def setup(): global pi, myvalues, boards, angles, W, H W = 1280 H = 720 pi = 4 * atan2(1, 1) size(720, 720, P2D) def draw(): global angles, anglenums, currstack, anglestack rr = 3.23607 mylength = 5 angles = [] anglenums = [] if frameCount <= 2: # 1: The string determining the L-system. # 2: The length of each segment. # 3: Tuple containing Angle 1 and Angle 2. # 4: Depth of recursion. # 5: Number of segments (all if 0). # 6: Translation along the x-axis. # 7: Translation along the y-axis. # 8: Color of lines. # 9: Rotation (0 if none). # Fractal 1: Angles of 80 and 220. # Fractal 2: Angles of 90 and 150. drawfractal("F1F2F1F", float(mylength), [60,240], 5, 0, 0, 0, color(1,0,0), 1, 90) else: noLoop() # you can save frames to make a movie # saveFrame("frames//####.tif") def colorL(rgbList): return color(rgbList[0], rgbList[1], rgbList[2]) def FwithAngles(Lsystem1,len1, anglelist, n, angles, anglenums): if n > 0: for L in range(len(Lsystem1)): character = Lsystem1[L] if character == "F": FwithAngles(Lsystem1, len1, anglelist, n - 1, angles, anglenums) if n == 1: anglenums.append(len1) elif character == "[": anglenums.append("[") elif character == "]": anglenums.append("]") else: angles.append(anglelist[int(character) - 1]) anglenums.append(int(character) - 1) def drawfractal(s1, len1, anglelist, depth, n, t_x, t_y, mycolor, mystroke, rotation): # stores the sequence of angles global angles, currstack, anglestack currstack = [[0,0]] anglestack = [rotation] angles = [] anglenums = [] FwithAngles(s1, len1, anglelist, depth, angles, anglenums) # keeps track of current position and orientation currentX = 0 currentY = 0 currentangle = rotation stroke(mycolor) strokeWeight(mystroke) # Checks how long the string needs to be to produce n "F"'s. if n == 0: Fscount = len(anglenums) else: numFs = 0 Fscount = 0 done = False lenang = len(anglenums) while not(done): if (Fscount == lenang) or (numFs == n): done = True else: if isinstance(anglenums[Fscount],float): numFs +=1 Fscount += 1 #print(numFs) #print(Fscount) # converts degress to radians convert = pi / 180. for i in anglenums[:Fscount - 1]: if isinstance(i, float): leng = i # next, update the location nextX = currentX + leng * cos(currentangle * convert) nextY = currentY + leng * sin(currentangle * convert) # now draw the line line(currentX + t_x, t_y - currentY, nextX + t_x, t_y - nextY) # now update the current point currentX = nextX currentY = nextY elif i == "[": currstack.append([currentX,currentY]) anglestack.append(currentangle) elif i == "]": currentX = currstack[-1][0] currentY = currstack[-1][1] currentangle = anglestack[-1] del currstack[-1] del anglestack[-1] else: currentangle += angles[i]