Code Sketch


Grow Shrink Animation
By: Nitin Mishra
Category: Art
cleari()
setBackground(black)
toggleFullScreenCanvas()
def shape() {
    repeat(8) {
        savePosHe()
        setFillColor(clr)
        right(45, 40)
        restorePosHe()
        savePosHe()
        left(45, 40)
        restorePosHe()
        forward(20)
    }
}

var clr = red

val pic1 = Picture {
    repeat(20) {
        savePosHe()
        clr = clr.spin(18)
        setPenColor(clr)
        shape()
        restorePosHe()
        right(18)
    }
}

var n = 1.0

draw(pic1)

def grow {
    animate {
        pic1.scale(1.005)
        pic1.rotate(1)
        n += 0.5
        //        println(n)
        if (n >= 130) {
            stopAnimation()
        }
    }
}

def shrink {
    animate {
        pic1.scale(0.99)
        pic1.rotate(-1)
        n -= 1
        //        println(n)
        if (n <= 1) {
            stopAnimation()
        }
    }

}

def growAndShrink {
    grow
    while (n < 130) { pause(0.01) }
    shrink
    while (n > 1) { pause(0.01) }
    growAndShrink
}

growAndShrink