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) -- reset mouse position last_segment = nil segment = nil was_click = false cx, cy = 0, 0 -- reset color plane_mask = 0xff 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(x, 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) end function handle_ui_click(x, y) 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