188 lines
5.5 KiB
Lua
188 lines
5.5 KiB
Lua
pico-8 cartridge // http://www.pico-8.com
|
|
version 41
|
|
__lua__
|
|
-- bitplane-thingie
|
|
-- by kistaro
|
|
-- mastodon: @kistaro@dragon.style
|
|
-- matrix: @kistaro:chromaticdragon.net
|
|
--
|
|
-- dev tool for experimenting
|
|
-- with bitplanes and palettes
|
|
|
|
function _init()
|
|
cls()
|
|
-- reset bitplanes
|
|
poke(0x5f5e, 0xff)
|
|
-- enable mouse
|
|
poke(0x5f2d, 0x1)
|
|
|
|
-- lock bottom 16 rows to default palette
|
|
pal({[0]=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, 2)
|
|
poke(0x5f5f, 0x10)
|
|
poke(0x5f7e, 0xff)
|
|
poke(0x5f7f, 0xff)
|
|
|
|
-- reset mouse position
|
|
last_segment = nil
|
|
segment = nil
|
|
was_click = false
|
|
cx, cy = 0, 0
|
|
|
|
-- reset color
|
|
plane_mask = 0xff
|
|
|
|
-- experimental additive palette 1
|
|
pal({[0]=0,136,3,4,1,141,13,5,6,8,139,10,140,14,12,7}, 1)
|
|
end
|
|
|
|
function _update60()
|
|
restore_under_cursor()
|
|
if stat(34) & 0x1 == 0 then
|
|
-- mouse up
|
|
was_click = false
|
|
segment = nil
|
|
return
|
|
end
|
|
|
|
-- ignore drag off ui
|
|
if was_click and segment == nil then
|
|
return
|
|
end
|
|
|
|
-- mouse down
|
|
local mouse_x = stat(32)
|
|
local mouse_y = stat(33)
|
|
|
|
if mouse_y >= 112 then
|
|
if segment then
|
|
mouse_y = 111
|
|
elseif not was_click then
|
|
handle_ui_click(mouse_x, mouse_y)
|
|
end
|
|
end
|
|
|
|
if mouse_y < 112 then
|
|
local r = 1
|
|
if segment then
|
|
local dx = mouse_x - segment[1]
|
|
local dy = mouse_y - segment[2]
|
|
r = sqrt(dx*dx+dy*dy)
|
|
end
|
|
segment = {mouse_x, mouse_y, r}
|
|
end
|
|
|
|
was_click = true
|
|
end
|
|
|
|
function _draw()
|
|
draw_ui()
|
|
draw_segment()
|
|
draw_cursor()
|
|
end
|
|
|
|
-->8
|
|
-- draw_segment
|
|
|
|
function draw_segment()
|
|
if (not segment) return
|
|
|
|
color(0xff)
|
|
poke(0x5f5e, plane_mask)
|
|
circfill(unpack(segment))
|
|
end
|
|
|
|
-->8
|
|
-- ui (and click)
|
|
|
|
function draw_ui()
|
|
poke(0x5f5e, 0xff)
|
|
rectfill(1, 113, 126, 126, 6)
|
|
rect(0,112,0,127,7)
|
|
rect(0,112,127,112,7)
|
|
rect(127,112,127,127,5)
|
|
rect(0,127,127,127,5)
|
|
|
|
-- draw "nuke" button
|
|
spr(21,0,112,2,2)
|
|
|
|
print("clr", 19, 118, 1)
|
|
print("clr", 18, 117, 7)
|
|
-- draw "color" bits
|
|
for i=0,3 do
|
|
draw_ui_checkbox(32 + 9*i, plane_mask & 1<<i ~= 0,i)
|
|
end
|
|
|
|
print("mask", 73, 118, 1)
|
|
print("mask", 72, 117, 7)
|
|
-- draw "mask" bits
|
|
for i=0,3 do
|
|
draw_ui_checkbox(90 + 9*i, plane_mask & 1<<(i+4) ~= 0, i)
|
|
end
|
|
end
|
|
|
|
function draw_ui_checkbox(x, checked, n)
|
|
spr(checked and 18 or 17,
|
|
x,
|
|
113)
|
|
spr(33+n, x, 121)
|
|
end
|
|
|
|
function handle_ui_click(x, y)
|
|
-- out of range
|
|
if (x < 3 or x > 125) return
|
|
|
|
-- nuke button
|
|
if x <= 12 and y > 114 and y < 125 then
|
|
cls()
|
|
return
|
|
end
|
|
|
|
end
|
|
-->8
|
|
-- draw_cursor
|
|
|
|
function draw_cursor()
|
|
cx, cy = stat(32), stat(33)
|
|
|
|
-- save blob under cursor to
|
|
-- corner of sprite sheet
|
|
-- to restore on next frame
|
|
poke(0x5f54, 0x60)
|
|
poke(0x5f55, 0x00)
|
|
palt(0, false)
|
|
sspr(cx, cy, 8, 8, 120, 24)
|
|
palt(0, true)
|
|
poke(0x5f54, 0x00)
|
|
poke(0x5f55, 0x60)
|
|
spr(stat(34)+1, cx, cy)
|
|
end
|
|
|
|
function restore_under_cursor()
|
|
palt(0, false)
|
|
sspr(120, 24, 8, 8, cx, cy)
|
|
palt(0, true)
|
|
end
|
|
__gfx__
|
|
00000000500000005000000050000000500000005000000050000000500000005000000000000000000000000000000000000000000000000000000000000000
|
|
00000000550000005500000055000000550000005500000055000000550000005500000000000000000000000000000000000000000000000000000000000000
|
|
0070070057500000595000005a5000005a5000005b500000595000005a5000005950000000000000000000000000000000000000000000000000000000000000
|
|
0007700057750000599500005aa50000599500005bb5000059b500005bb5000059b5000000000000000000000000000000000000000000000000000000000000
|
|
0007700057775000599950005aaa50005aaa50005bbb500059b950005aaa50005aaa500000000000000000000000000000000000000000000000000000000000
|
|
00700700557550005595500055a550005595500055b5500055b5500055b5500055b5500000000000000000000000000000000000000000000000000000000000
|
|
000000000057500000595000005a5000005a5000005b5000005b5000005a50000059500000000000000000000000000000000000000000000000000000000000
|
|
00000000005500000055000000550000005500000055000000550000005500000055000000000000000000000000000000000000000000000000000000000000
|
|
00000000555555565555555600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000511111165111111600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000511111165117711600000000000000000066666666666600000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000511111165177771600000000000000000062228222282500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000511111165177771600000000000000000068898898882500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000511111165117711600000000000000000062889999822500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000051111116511111160000000000000000006229aaaa888500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
000000006666666666666666000000000000000000688a7779888500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
000000000007000000077000007070000007700000688977aa892500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000007710000070170000717100007017000062899aa9888500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000710000001701000777700000770100062999aa9888500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000710000007010000017110007017000062889998288500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000007770000077770000007100000770100068822998888500000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000111000001111000000100000011000065555555555500000000000000000000000000000000000000000000000000000000000000000000000000
|