Code Sketch


Republic Day Art
By: Ayush Manu Aggarwal
Category: Art
cleari()
setSpeed(superFast)
val cb = canvasBounds

//showAxes()
val bgColor = cm.linearGradient(cb.x, cb.y, Color(40, 96, 5), cb.x, cb.y + cb.height, ColorMaker.hsl(20, 0.50, 0.50), false)
val bg = fillColor(bgColor) * penColor(noColor) * trans(0, cheight / 2) -> Picture.rectangle(cwidth, cheight / 2)

setBackground(bgColor)

def mountain(n: Double) = Picture.fromVertexShape { s =>
    import s._
    beginShape()
    curveVertexRt(n, 0)
    curveVertexRt(n, 0)
    curveVertexRt(n, random(100, 20))
    curveVertexRt(n, 180)
    curveVertexRt(n, 180)
    endShape()
}

def hills(n: Int, size: Double): Picture = {
    if (n == 1) {
        mountain(size)
    }

    else {
        fillColor(ColorMaker.hsla(0, 0.33, 0.24, 0.87)) * penColor(noColor) -> picStack(
            mountain(size),
            trans(size * 1.5, 0) -> hills(n - 1, size)
        )
    }
}

val mountains = hills(3, 150)

def bird(n: Double) = penColor(black) * scale(1) -> Picture {
    right(54)
    right(60, n)
    left(96)
    right(60, n)
}

def birds(n: Int, Size: Double): Picture = {
    if (n == 1) {
        bird(Size)

    }
    else {
        picStack(
            bird(Size),
            trans(Size * 1.8, Size * 1.4) -> birds(n - 1, Size * 0.6)
        )
    }
}

def chakra = Picture {
    setPenColor(blue)
    right(360, 20)
    right(90)
    hop(20)
    left(90)
    repeat(8) {
        forward(20)
        hop(-20)
        forward(-20)
        hop(20)
        right(45)
    }
}

val flag = picStack(
    Picture.rectangle(150, 100)
        .withFillColor(cm.linearGradient(0, 0, cm.green, 0, 100, cm.darkOrange, false))
        .withPenColor(darkGray),
    trans(55, 50) -> chakra
)

val bird2 = picStack(
    birds(6, 50),
    birds(6, 50).withFlippedX
)

val text = Picture {
    setPenColor(black)
    setPenFontSize(50)
    write("Happy Republic Day!")
}

val look = picStack(
    trans(-200, -16) -> mountains,
    trans(-1, 140) -> bird2,
    trans(-75, 175) -> flag,
    trans(-248, -95) -> text
)

draw(look)