How do we create graphics in Python?
You use the turtle module to create graphics in Python. I’ll add some of the simple scripts I wrote when I was learning Python.
- This script creates a simple never stopping concentric polygon.
- import turtle
- def draw(t, length, n):
- if n == 0:
- return
- angle = 60
- t.fd(length*n)
- t.lt(angle)
- draw(t, length, n-1)
- t.rt(2*angle)
- draw(t, length, n-1)
- t.lt(angle)
- t.bk(length*n)
- bob= turtle.Turtle()
- print (draw(bob, 1, 1/3))
- turtle.mainloop()
- This script creates a three coloured cirlce. :p
- import turtle
- def shape():
- window = turtle.Screen()
- window.bgcolor("white")
- asdf = turtle.Turtle()
- asdf.shape("turtle")
- asdf.speed(500)
- for j in range(120):
- asdf.color("blue")
- for i in range(4):
- asdf.forward(100)
- asdf.right(90)
- asdf.right(1)
- for j in range(120):
- asdf.color("green")
- for i in range(4):
- asdf.forward(100)
- asdf.right(90)
- asdf.right(1)
- for j in range(120):
- asdf.color("yellow")
- for i in range(4):
- asdf.forward(100)
- asdf.right(90)
- asdf.right(1)
- window.exitonclick()
- shape()
You can run these scripts using python3 and if it increases your curiosity, you can learn about it more from various resources.