Code Sketch


Pattern
By: Nitin Mishra
Category: Art
def shape(s: Int) {
    repeat(2) {
        forward(s)
        left(45)
        forward(s)
        right(90)
        forward(s)
        left(45)
        forward(s)
        right()
    }
    repeat(2) {
        forward(s)
        right(45)
        forward(s)
        left(90)
        forward(s)
        right(45)
        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(15)
}

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