Code Sketch


Shravani
By: Mhalsakant School
Category: Art
// An updated version of the earlier republic day drawing 
// using pic.thatsXX transforms
// works with Kojo 2.9.18 and later

size(775, 527)
cleari()
setAnimationDelay(0)
originBottomLeft()

initRandomGenerator(-4566063618077315813L)

val bgc1 = cm.linearGradient(0, 0, Color(255, 222, 149), 0, cheight / 2, Color(173, 41, 0), false) //> val bgc1: java.awt.GradientPaint = java.awt.GradientPaint@18726d1a
val bg1 = fillColor(bgc1) * penColor(noColor) -> Picture.rectangle(cwidth, cheight / 2) //> val bg1: net.kogics.kojo.core.Picture = PostDrawTransform (Id: 374995042 -> PostDrawTransform (Id: 1070534804 -> Picture with Id: 1184766315))
val bgc2 = cm.linearGradient(0, 0, Color(0, 102, 45), 0, cheight / 2, Color(204, 204, 204), false) //> val bgc2: java.awt.GradientPaint = java.awt.GradientPaint@4ff26f99
val bg2 = fillColor(bgc2) * penColor(noColor) -> Picture.rectangle(cwidth, cheight / 2) //> val bg2: net.kogics.kojo.core.Picture = PostDrawTransform (Id: 401508276 -> PostDrawTransform (Id: 1255474829 -> Picture with Id: 2053251731))

val bg = picColCentered(bg2, bg1) //> val bg: net.kogics.kojo.picture.VPics2 = Picture Column2 (Id: 1002288985)

def building(n: Int) {
    repeat(2) {
        forward(n)
        right(90)
        forward(30)
        right(90)
    }
    right(90)
    hop(30)
    left(90)
} //> def building(n: Int): Unit

def buildings = Picture {
    repeat(26) {
        building(random(40, 150))
    }
} //> def buildings: net.kogics.kojo.picture.Pic0

def chakra = penColor(ColorMaker.hsl(219, 0.93, 0.60)) -> Picture {
    left(-90)
    hop(25)
    left(90)
    circle(25)
    right(-90)
    forward(50)
    hop(-25)
    left(90)
    hop(25)
    right(180)
    forward(50)
    hop(-25)
    right(45)
    hop(25)
    right(180)
    forward(50)
    hop(-25)
    right(90)
    hop(25)
    right(180)
    forward(50)

} //> def chakra: net.kogics.kojo.core.Picture

def city = picStack(
    buildings.withFillColor(white)
        .withPenColor(ColorMaker.hsl(0, 0.00, 0.93))
        .thatsTranslated(0, cheight / 2 - 43),
    chakra
        .thatsTranslated(cwidth * 0.5 + 2.5, cheight * 0.5)
) //> def city: net.kogics.kojo.picture.GPics

def f = Picture {
    setFillColor(ColorMaker.hsl(0, 0.17, 0.21))
    setPenColor(noColor)
    forward(60)
    left(90)
    forward(5)
    left(90)
    forward(60)
    left(90)
    forward(5)
    left(90)
    hop(60)
    right(90)
    setFillColor(cm.darkOrange)
    forward(40)
    right(90)
    forward(10)
    right(90)
    forward(40)
    right(180)
    setFillColor(white)
    forward(40)
    right(90)
    forward(10)
    right(90)
    forward(40)
    right(180)
    setFillColor(cm.green)
    forward(40)
    right(90)
    forward(10)
    right(90)
    forward(40)
    right(180)
} //> def f: net.kogics.kojo.picture.Pic0

val flag = picStack(
    f,
    chakra.thatsScaled(0.18).thatsTranslated(20, 45)
) //> val flag: net.kogics.kojo.picture.GPics = Picture Stack (Id: 394573028)

def text = Picture {
    setPenColor(white)
    write("Happy Independence Day!")
} //> def text: net.kogics.kojo.picture.Pic0

val pic = picStack(
    bg,
    city,
    flag.thatsScaled(0.5).thatsTranslated(197, 367),
    text.thatsScaled(2).thatsTranslated(cwidth / 2 - 183, 120)
) //> val pic: net.kogics.kojo.picture.GPics = Picture Stack (Id: 564308691)

draw(pic)