Code Sketch


yoi
By: Mhalsakant School
Category: Programming

cleari()
disablePanAndZoom()

setBackground(black)

val cb = canvasBounds

val boxSize = 5

val cols = math.ceil(cb.width / boxSize).toInt + 1
val rows = math.ceil(cb.height / boxSize).toInt + 1

for (row <- 0 until rows) {
    for (col <- 0 until cols) {

        val isWhite = (row + col) % 2 == 0

        val box = Picture.rectangle(boxSize + 1, boxSize + 1)

        if (isWhite) {
            box.setFillColor(white)
            box.setPenColor(white)
        } else {
            box.setFillColor(black)
            box.setPenColor(black)
        }

        box.setPosition(
            cb.x + col * boxSize + boxSize / 2,
            cb.y + row * boxSize + boxSize / 2
        )

        draw(box)
    }
}