10PRINT Banner

10PRINT is a one-liner from the Commodore 64 era that randomly prints / or \ to fill the screen, creating a maze-like pattern. Here's my take on it for the Playdate.

Setup

Import the graphics library, define the grid spacing, and initialize the drawing position.

import "CoreLibs/graphics"

local gfx<const> = playdate.graphics
local dsp<const> = playdate.display

local spacing<const> = 10

local xCount
local yCount

local x = 0
local y = 0
local invert = false

function setup()
    dsp.setScale(2)
    xCount = dsp.getWidth() / spacing
    yCount = dsp.getHeight() / spacing
end

setup()

Draw loop

Each frame draws one diagonal line — either / or \ — chosen at random. Once the screen fills up, it clears and inverts the colors.

function playdate.update()
    if math.random() < 0.5 then
        gfx.drawLine(x, y, x + spacing, y + spacing)
    else
        gfx.drawLine(x, y + spacing, x + spacing, y)
    end

    x = x + spacing

    if x > dsp.getWidth() then
        x = 0
        y = y + spacing

        if y >= dsp.getHeight() then
            y = 0
            invert = not invert

            dsp.setInverted(invert)
            gfx.clear()
        end
    end
end

Preview