Code Sketch


Color Spectrum Flower
By: Anusha Pant
size(900, 900)
cleari()
initRandomGenerator(-4907162015393102707L)
originTopLeft()

val tileCount = 25
val tileSize = cwidth / tileCount

def shape =  Picture.rectangle(tileSize, tileSize)

def block(posX: Double, posY: Double, col: Color) {
    val pic = shape
    pic.setPosition(posX, posY)
    pic.setPenColor(col)
    pic.setFillColor(col)
    draw(pic)
}

var col = cm.hsb(360, 1, 1)
val huefac = 360/tileCount
var satfac = 1.00

repeatFor(rangeTill(0, cheight, tileSize)) { posY =>
    var i = 1
    repeatFor(rangeTill(0, cwidth, tileSize)) { posX =>
        block(posX, posY, col)
        col = cm.hsb(360 - huefac*i, satfac, 1)
        i += 1
    }
    satfac = satfac - 1.00/tileCount
}

def line(){
    setPenThickness(random(1, 6))
    repeat(randomDouble(cwidth/4, cwidth/2).toInt) {
        forward(1)
        right(random(0, 5))
        forward(1)
        left(random(0, 5))
    }
}

def circshape() = Picture{
    repeat(90) {
        savePosHe()
        line()
        restorePosHe()
        right(4)
    }
   
}
val p1 = trans(cwidth/2, cheight/2) * fillColor(Color(51, 51, 51)) * penColor(Color(51, 51, 51)) -> Picture.circle(10)
val p2 = trans(cwidth/2, cheight/2) * penColor(ColorMaker.hsla(51, 0.94, 0.07, 0.70)) -> circshape()
val pic = picStack(p1, p2)

draw(pic)