Log In  


Cart #hadubiguku-0 | 2025-09-08 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

A simple graphical demo for the PICO-1K Jam 2025 which creates an animated Dragon Curve.

A Dragon Curve can be generated physically from repeatedly folding a strip of paper in half and hence the lines in a Dragon Curve never cross each other.

The different colours represent the level of recursion that each segment was generated at by the algorithm.

You can use the cursor keys to move he viewport and ZX / NM / CV to zoom in and out to explore the curve in more detail as it renders or once it has finished.

The compressed byte size of the cartridge is 643. I've made very little effort to save bytes because the program is so simple in the first place.

-- dragon curve
-- by retroredge,v0.1,2025

dirs = {{ 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 }}

rec_dep = 10
line_len = 2
sx = 84
sy = 94
curve = {}
count = 1

function flp(tbl)
    new = {}
    for i = 1, #tbl do
        if tbl[i] == "l" then
            add(new, "r")
        else
            add(new, "l")
        end
    end
    return new
end

function rev(tbl)
    new = {}
    for i = #tbl, 1, -1 do
        add(new, tbl[i])
    end
    return new
end

function gen_curve(letters, lvl)
    new = flp(letters)
    add(curve, "l")
    new = rev(new)
    for i = 1, #new do
        add(curve, new[i])
    end

    if lvl < rec_dep then
        gen_curve(curve, lvl + 1)
    end
end

function wrap1to4(i)
 return ((i - 1) % 4) + 1
end

function _init()
    gen_curve(curve, 0)
end

function _draw()
    cls(0)
    dir_ind = 1
    x = sx
    y = sy
    col_max = 1
    col = 4

    for i = 1, count do
        if i > col_max then
            col_max = shl(col_max, 1)
            col += 1
        end
        dir = dirs[dir_ind]
        nx = x + dir[1] * line_len
        ny = y + dir[2] * line_len
        line(x, y, nx, ny, col)
        x = nx
        y = ny
        if curve[i] == "l" then
            dir_ind = wrap1to4(dir_ind - 1)
        else
            dir_ind = wrap1to4(dir_ind + 1)
        end
    end

    if count < #curve then
        count += 1
    end
end

function _update()
    if btn(4) then
        line_len += 1
    elseif btn(5) then
        line_len -= 1
    end

    line_len = min(max(line_len, 2), 16)

    if btn(1) then
        sx += 1
    elseif btn(0) then
        sx -= 1
    end

    if btn(2) then
        sy -= 1
    elseif btn(3) then
        sy += 1
    end
end
1



[Please log in to post a comment]