Code Sketch


Pattern
By: Nitin Mishra
Category: Art
def shape(s: Int) {
    repeat(2) {
        forward(s)
        left()
        right(180, s / 2)
        left()
        forward(s)
        right()
    }
    repeat(2) {
        forward(s)
        right()
        left(180, s / 2)
        right()
        forward(s)
        right()
    }

}
clear()
setBackground(white)
setSpeed(superFast)
setPenColor(darkGray.fadeOut(0.2))
setPenThickness(1)

val nx = 13
val ny = 9
val cb = canvasBounds
val dx = cb.width / nx
val dy = cb.height / ny



def posx(gx: Int) = cb.x + gx * dx
def posy(gy: Int) = cb.y + gy * dy

def block(gx: Int, gy: Int) {
    setPosition(posx(gx), posy(gy))
    setFillColor(randomColor.fadeOut(0.7))
    shape(20)
}

repeatFor(0 until nx) { x =>
    repeatFor(0 until ny) { y =>
        block(x, y)
    }
}
invisible()