Creating Graphics with Python

In Python, Turtle graphics is a popular way for introducing programming. Imagine a robotic turtle starting at (0, 0) in the x-y plane. After anĀ importĀ turtle, give it the commandĀ turtle.forward(15), and it moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the commandĀ turtle.right(25), and it rotates in-place 25 degrees clockwise.

By combining together these and similar commands, intricate shapes and pictures can easily be drawn.

Now lets make a graphic using python turtle module:

import turtle
colors=['red','purple','blue','green','orange','yellow']
t=turtle.Pen()
turtle.bgcolor('black')
for x in range(360):
    t.pencolor(colors[x%6])
    t.width(x/100+1)
    t.forward(x)
    t.left(59)
Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of datašŸ“ˆ.

Articles: 1534

Leave a Reply