Code Sketch


Illusion - II
By: Soham Dabral
Category: Art
// this is an updated version of "another illusion" from earlier 
// that uses pic.thatsXX transforms
// works with Kojo 2.9.18 and later

cleari()
clearOutput()
setBackground(ColorMaker.hsl(22, 0.44, 0.51))
def nothing(n: Int) = Picture {

}

def pattern1(size: Double) = Picture {
    setPenColor(noColor)
    setFillColor(ColorMaker.hsl(255, 1.00, 0.43))
    forward(80)
    right(180, size)
    forward(80)
}

def pattern2(size: Double) = Picture {
    setPenColor(noColor)
    setFillColor(white)
    forward(80)
    right(180, size)
    forward(80)
}

def drawing(n: Int, size: Double): Picture = {
    if (n == 1) {
        nothing(0)
    }
    else {
        picStack(
            pic,
            trans(0, -size) * rot(10) -> drawing(n - 1, size)
        )
    }
}

val pic = picStack(
    scale(0.25) -> pattern1(100),
    scale(0.25) * trans(0, -120) * rot(6) -> pattern2(100),
    scale(0.25) * trans(0, -240) * rot(6) -> pattern1(100),
)

val pic1 = picStack(
    scale(0.75) -> drawing(45, 60),
    trans(50, -5) * scale(0.6) -> drawing(45, 60),
    trans(100, -10) * scale(0.45) -> drawing(45, 60),
    trans(135, -15) * scale(0.35) -> drawing(45, 60),
    trans(170, -20) * scale(0.25) -> drawing(45, 60)
)

val pic2 = picStack(
    pic1,
    pic1
        .thatsTranslated(40, 0)
        .withFlippedX,
    pic1
        .thatsTranslated(550, 0)
)

val pic3 = picStack(
    pic2,
    trans(0, -550) -> pic2,
    trans(0, 550) -> pic2
)

val pic4 = picStack(
    pic3,
    pic1
        .thatsScaled(0.45)
        .thatsTranslated(-130, -285),
    pic1
        .thatsScaled(0.45)
        .thatsTranslated(-130, 260),
    pic1
        .thatsScaled(0.45)
        .thatsTranslated(415, -285),
    pic1
        .thatsScaled(0.45)
        .thatsTranslated(415, 260)
)
drawCentered(pic4)