Code Sketch
Random-Shape-Grid
clear()
setBackground(white)
setSpeed(superFast)
setPenColor(gray.fadeOut(0.5))
setPenThickness(1)
def polygon(n: Int) {
var len = 30
if (n <= 4) {
len = len + 20
}
repeat(n) {
forward(len)
right(360.0 / n)
}
}
val nx = 15
val ny = 15
val cb = canvasBounds
val dx = cb.width / nx
val dy = cb.height / ny
def shape() {
savePosHe()
val a = random(-10,10)
val r = random(3, 9)
right(a)
polygon(r)
restorePosHe()
}
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.8))
shape()
}
repeatFor(0 until nx) { x =>
repeatFor(0 until ny) { y =>
block(x, y)
}
}