Code Sketch


yoi
By: Mhalsakant School
Category: Programming

cleari()
disablePanAndZoom()
setBackground(gray)

val cb = canvasBounds

val tileSize = 3.0
val gap = 3.0
val step = tileSize + gap

val cols = (cb.width / step).toInt + 4
val rows = (cb.height / step).toInt + 3

for (row <- -1 until rows) {

    val offset =
        if (row % 2 == 0) 0.0
        else step / 2.0

    for (col <- -2 until cols) {

        val x = cb.x + col * step + offset
        val y = cb.y + row * step

        val box = Picture.rectangle(
            tileSize,
            tileSize
        )

        if ((row + col) % 2 == 0) {
            box.setFillColor(black)
            box.setPenColor(black)
        } else {
            box.setFillColor(white)
            box.setPenColor(white)
        }

        box.setPosition(
            x + tileSize / 2,
            y + tileSize / 2
        )

        draw(box)
    }
}