Dave's Creature



  • 0_1532504178269_davesCreature.gif
    after this tweet:
    https://twitter.com/beesandbombs/status/1021746882362728448
    and this processing code:
    https://gist.github.com/beesandbombs/6f3e6fb723f50b080916816ae8e561e3

    I made a DrawBot/Python translation:

    import math
    n = 720
    l = 350
    twm = math.pi/20
    
    def mapValue(value, start1, stop1, start2, stop2):
        p = 1.0*(value-start1) / (stop1 - start1)
        return start2 + p*(stop2 - start2)
    
    def spiral(q, R, nt):
        path = BezierPath()
        origin = width()*.5, height()*.5
        path.moveTo(origin)
        for i in range(n):
            qq = 1.0*i/(n-1)
            r = mapValue(math.cos(2*math.pi*qq), 1, -1, 0, R)*math.sqrt(qq)
            th = nt*2*math.pi*qq - 4*2*math.pi*t - q
            x = r*math.cos(th)
            y = -l*qq + r*math.sin(th)
    
            tw = twm*math.sin(2*math.pi*t - math.pi*qq)
    
            xx = x*math.cos(tw) + y*math.sin(tw)
            yy = y*math.cos(tw) - x*math.sin(tw)
    
            path.lineTo((origin[0]+xx, origin[1]+yy))
    
        path.endPath()
        drawPath(path)
    
    N = 9
    frames = 60
    
    for f in range(frames):
        newPage(1000, 1000)
        frameDuration(1/30)
        fill(1)
        rect(0, 0, width(), height())
        t = 1.0*f/frames
        for i in range(N):
            R = 42
            m = mapValue(math.sin(2*math.pi*t), -1, 1, 0, 1)
            nt = 6+6*m
            save()
            stroke(.5)
            fill(None)
            strokeWidth(1)
            rotate(360.0*i/N, (width()*.5, height()*.5))
            spiral(2*math.pi*i/N, R, nt);
            restore()
    saveImage('davesCreature.gif')
    

    One might find mapValue an interesting function featured natively in processing:
    https://processing.org/reference/map_.html


Log in to reply