narenarya

Beautiful carpet with turtle and python

May 6th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. __author__ = 'Naren'
  2. import turtle
  3. import random
  4. window=turtle.Screen()
  5. window.bgcolor('black')
  6. def draw_square(n,color,path):
  7.     point=turtle.Turtle()
  8.     point.color(color)
  9.     point.shape('turtle')
  10.     point.speed(8)
  11.     for i in range(1,5):
  12.         if path=='rt':
  13.             point.rt(90)
  14.             point.fd(n)
  15.         elif path=='lt':
  16.             point.lt(90)
  17.             point.fd(n)
  18.         elif path=='fd_lt':
  19.             point.fd(n)
  20.             point.lt(90)
  21.         elif path=='fd_rt':
  22.             point.fd(n)
  23.             point.rt(90)
  24. def draw_beautiful_carpet():
  25.     paths=['rt','lt','fd_lt','fd_rt']
  26.     colors=['darkViolet','darkGreen','darkBlue','darkCyan','maroon','white','grey','khaki']
  27.     for s in paths:
  28.         for i in range(1,400,10):
  29.             if i == 400:
  30.                 draw_square(i,'black',s)
  31.             else:
  32.                 draw_square(i,random.choice(colors),s)
  33.  
  34. draw_beautiful_carpet()
  35. window.exitonclick()
Advertisement
Add Comment
Please, Sign In to add comment