Created
November 18, 2011 05:50
-
-
Save rohitnjan88/1375722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Tkinter import * | |
from math import * | |
from time import * | |
class TurtleClass(object): | |
"""a turtle class """ | |
def __init__(self,c): | |
self.x,self.y,self.d=100,300,0 | |
self.c = c | |
self.l1,self.l2,self.l3 = 0,0,0 | |
def rotate_left(self,a): | |
self.d=self.d+a | |
def rotate_right(self,a): | |
self.d=self.d-a | |
def move_forward(self,d): | |
x_new=self.x + d*cos(self.d*pi/180) | |
y_new=self.y - d*sin(self.d*pi/180) | |
self.l4 = self.c.create_line(self.x,self.y,x_new,y_new) | |
self.x,self.y=x_new,y_new | |
def flake(self,l): | |
if l <10: | |
self.move_forward(l) | |
self.c.update() | |
sleep(.001) | |
return | |
else: | |
self.flake(l/3) | |
self.rotate_left(60) | |
self.flake(l/3) | |
self.rotate_right(120) | |
self.flake(l/3) | |
self.rotate_left(60) | |
self.flake(l/3) | |
r=Tk() | |
c=Canvas(width=600,height=600) | |
c.pack() | |
b=TurtleClass(c) | |
b.rotate_left(60) | |
b.flake(300) | |
b.rotate_right(120) | |
b.flake(300) | |
b.rotate_right(120) | |
b.flake(300) | |
t=raw_input() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Koch SNow Flake pattern using Python and Python-TKInter