Playing with Python library Turtle

Turtle is a fun tool to play simple graphics on python language. Imagine a robotic turtle starting at 0:0 and moves accordingly to your code.
After doing little tweaks, I came up with the simple code that shows some art).



Here is the code:
import turtle
from turtle import *
import random
from random import *
#get cursor to default - center position
turtle.home()
#colors
colors = ['red', 'purple', 'blue', 'green', 'yellow', 'orange']
#background
turtle.bgcolor('black')
#loop for 100 iterations
for x in range(100):
#random color
turtle.color(colors[randint(0, 5)])
#randomly go in any direction X, Y - randomly, within 600 pixels
turtle.goto(randint(-300, 300), randint(-300, 300))
#draw a circle with random radius 0-50pxls
turtle.circle(randint(0, 50))
print('Horray!')
turtle.done()
More about the Turtle, can be read over here: https://docs.python.org/2/library/turtle.html

This is the cool tool to introduce programming to children.

Nik

I am passionate about creating stuff and want to change the world.

No comments:

Post a Comment