Play game
Dragon Curve [PICO8 1k Jam]'s itch.io pageCompressed Bytes used
643
Source Code (OPTIONAL)
-- 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
Leave a comment
Log in with itch.io to leave a comment.
Comments
No one has posted a comment yet