def setup(): size(768, 625, P2D) def draw(): initial = 30 # how many frames to sit with the first image morph = 120 # how many frames for the morphing final = 30 # how many frames to sit with the final image def iter(c): if c <= initial: return 0 elif c <= initial + morph: return (c-float(initial))/morph else: return 1 if frameCount <= initial + morph + final: sierpinski(iter(frameCount), 7000) else: noLoop() saveFrame("frames//####.tif") def sierpinski (p, n): from random import randint # different sets of points, so different colors can be used. pts0 = [] pts1 = [] pts2 = [] last = (0,0) for i in range(n): select = randint(0,2) (x,y) = last if select == 0: last = (0.5*x, 0.5*y) pts0.append(last) if select == 1: last = (0.5*x + 0.5, 0.5*y) pts1.append(last) if select == 2: last = (0.5*x, 0.5*y + 0.5) pts2.append(last) background(color(0,0,0)) # the color is changed for each set of points. stroke(color(255,0,0)) strokeWeight(3) [point(450 * x[0] + 250 - p*200, 500 - 450 * x[1]) for x in pts0[10:-1]] stroke(color(0,255,0)) strokeWeight(3) [point(450 * x[0] + 250 - p*200, 500 - 450 * x[1]) for x in pts1[10:-1]] stroke(color(0,0,255)) strokeWeight(3) [point(450 * x[0] + 250 - p*200, 500 - 450 * x[1]) for x in pts2[10:-1]]