# Graphics/Ccurve.py # C-curve page 52 # Try: ccurve(100,100,50,0,12) from graphics import * from math import * import math ANGLE = math.pi/4 # angle=45 in radians startx,starty = 100,100 length = 200 def initGraphics(): win = GraphWin( "Fractal C Curve", 400, 400 ) return win def ccurve (x,y,len,alpha,n): print " x= ",x," y= ",y," len= ",len," alpha= ",alpha," n= ", n if n == 0 : x1= x y1= y x2= x + len * cos(alpha) y2= y + len * sin(alpha) print " x1= ",x," y1= ",y1," x2= ",x2," y2= ",y2 linea = Line(Point(x1,y1),Point(x2,y2)) linea.draw(win) else: len = len / sqrt(2) ccurve(x,y,len,alpha + ANGLE,n-1) x = x + len * cos(alpha + ANGLE) y = y + len * sin(alpha + ANGLE) ccurve(x,y,len,alpha-ANGLE,n-1) def main(): global win win = initGraphics() n=3 # n=12 ccurve(startx,starty,length,0,n) message = Text( Point(150,375), "Click anywhere to stop!" ) message.draw( win ) win.getMouse() win.close() main()