pico-8 cartridge // http://www.pico-8.com version 41 __lua__ -- bitplane-thingie 1.0 -- 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 -- see tab 5 for palettes pal_idx = 1 pal(palettes[palette_cycle[pal_idx]],1) end function _update60() restore_under_cursor() if (btnp(❎)) next_pal() 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+4) ~= 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< 125) return -- nuke button if x <= 12 and y > 114 and y < 125 then cls() return end -- checkboxes: qualify if (y < 113 or y > 120 or x < 32) return if x <= 67 then x -= 32 if (x % 9 == 8) return local box = x \ 9 --check range if (box < 0 or box > 3) return toggle_mask_bit(box+4) return end x -= 90 if (x % 9 == 8) return local box = x \ 9 --check range if (box < 0 or box > 3) return toggle_mask_bit(box) return end function toggle_mask_bit(n) local sel = 1 << n local b = plane_mask & sel plane_mask = plane_mask & ~sel if (b > 0) return plane_mask = plane_mask | sel end -->8 -- draw_cursor function draw_cursor() poke(0x5f5e,0xff) 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) poke(0x5f5e,0xff) sspr(120, 24, 8, 8, cx, cy) palt(0, true) end -->8 -- future ambitions -- palette selection ui -- [x] ...from a preset list -- [ ] ...freely -->8 -- palettes palettes = { classic = {[0] = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, alt = {[0] = 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143}, additive = {[0]=0,136,3,4,1,141,13,5,6,8,139,10,140,14,12,7}, subtractive = {[0]=7,12,14,1,10,11,136,5,6,140,130,129,132,131,2,0}, } palette_cycle = {"additive", "subtractive", "classic", "alt"} function draw_color_blocks() for i=0,15 do local x0 = 8*i rectfill(x0, 0, x0+7, 7, i) end end function next_pal() pal_idx += 1 if (pal_idx > #palette_cycle) pal_idx = 1 pal(palettes[palette_cycle[pal_idx]], 1) draw_color_blocks() end __gfx__ 00000000500000005000000050000000500000005000000050000000500000005000000000000000000000000000000000000000000000000000000000000000 00000000550000005500000055000000550000005500000055000000550000005500000000000000000000000000000000000000000000000000000000000000 0070070057500000595000005a5000005a5000005b500000595000005a5000005950000000000000000000000000000000000000000000000000000000000000 0007700057750000599500005aa50000599500005bb5000059b500005bb5000059b5000000000000000000000000000000000000000000000000000000000000 0007700057775000599950005aaa50005aaa50005bbb500059b950005aaa50005aaa500000000000000000000000000000000000000000000000000000000000 00700700557550005595500055a550005595500055b5500055b5500055b5500055b5500000000000000000000000000000000000000000000000000000000000 000000000057500000595000005a5000005a5000005b5000005b5000005a50000059500000000000000000000000000000000000000000000000000000000000 00000000005500000055000000550000005500000055000000550000005500000055000000000000000000000000000000000000000000000000000000000000 00000000555555565555555600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000511111165111111600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000511111165117711600000000000000000066666666666600000000000000000000000000000000000000000000000000000000000000000000000000 00000000511111165177771600000000000000000062228222282500000000000000000000000000000000000000000000000000000000000000000000000000 00000000511111165177771600000000000000000068898898882500000000000000000000000000000000000000000000000000000000000000000000000000 00000000511111165117711600000000000000000062889999822500000000000000000000000000000000000000000000000000000000000000000000000000 0000000051111116511111160000000000000000006229aaaa888500000000000000000000000000000000000000000000000000000000000000000000000000 000000006666666666666666000000000000000000688a7779888500000000000000000000000000000000000000000000000000000000000000000000000000 000000000007000000077000007070000007700000688977aa892500000000000000000000000000000000000000000000000000000000000000000000000000 00000000007710000070170000717100007017000062899aa9888500000000000000000000000000000000000000000000000000000000000000000000000000 00000000000710000001701000777700000770100062999aa9888500000000000000000000000000000000000000000000000000000000000000000000000000 00000000000710000007010000017110007017000062889998288500000000000000000000000000000000000000000000000000000000000000000000000000 00000000007770000077770000007100000770100068822998888500000000000000000000000000000000000000000000000000000000000000000000000000 00000000000111000001111000000100000011000065555555555500000000000000000000000000000000000000000000000000000000000000000000000000 __label__ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000ooooo00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000oooooooooo0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000ooooooooooooooo000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000ooooooooooooooooooo00000000003330000033300000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000ooooooooooooooooooooo000033333333003333333000000000000000000000000000000000000000000000000000000000000000000000 000000000000000ooooooooooooooooooooooooo0333333333333333333000030000000000000000000000000000000000000000000000000000000000000000 00000000000000oooooooooooooooooooooooooo4443333333333333333300333000000000000000000000000000000000000000000000000000000000000000 00000000000000oooooooooooooooooooooooooo4444433333333333333330333000000000000000000000000000000000000000000000000000000000000000 0000000000000oooooooooooooooooooooooooo44444443333333333333333333300000000000000000000000000000000000000000000000000000000000000 0000000000000ooooooooooooooooooooooooo44444444333333333333333333330000000000000000000000000000000000000t000000000000000000000000 0000000000000ooooooooooooooooooooooooo44444444333333333333333333333000000000000000000000000000000000000tt00000000000000000000000 0000000000000oooooooooooooooooooooooo444444444333333333333333333333000000000000000000000000000000000000t5t0000000000000000000000 000000000000ooooooooooooooooooooooooo444444444433333333333333333333000000000000000000000000000000000000t55t000000000000000000000 00000000000oooooooooooooooooooooooooo444444444433333333333333333330000000000000000000000000000000000000t555t00000000000000000000 00000000000oooooooooooooooooooooooooo444444444433333333333333333333000000000000000000000000000000000000tt5tt00000000000000000000 00000000000ooooooooooooooooooooooooo444444444433333333333333333333300000000000000000000000000000000000000t5t00000000000000000000 000000000000oooooooooooooooooooooooo444444444433333333333333333333300000000000000000000000000000000000000tt000000000000000000000 000000000000oooooooooooooooooooooooo44444444443333333333333333333330000000000000000000000000000000000000000000000000000000000000 000000000000oooooooooooooooooooooooo44444444443333333333333333333330000000000000000000000000000000000000000000000000000000000000 000000000000ooooooooooooooooooooooo444444444443333333333333333333330000000000000000000000000000000000000000000000000000000000000 000000000000oooooooooooooooooooooo4455544444433333333333333333333300000000000000000000000000000000000000000000000000000000000000 000000000000ooooooooooooooootttttt5555554444433333333333333333333300000000000000000000000000000000000000000000000000000000000000 0000000000000oooooooooooootttttttt5555555554433333333333333333333000000000000000000000000000000000000000000000000000000000000000 0000000000000ooooooooooootttttttttt555555555333333333333333333333000000000000000000000000000000000000000000000000000000000000000 00000000000000ooooooooootttttttttt555555555ddd3333333333333333330000000000000000000000000000000000000000000000000000000000000000 000000000000000oooooooottttttttttt555555555dddd333333333333333330000000000000000000000000000000000000000000000000000000000000000 0000000000000000ooooooottttttttttt55555555dddddd33333333333333330000000000000000000000000000000000000000000000000000000000000000 0000000000000000000ootttttttttttttt555555ddddddd33333333333333330000000000000000000000000000000000000000000000000000000000000000 00000000000000000000tttttttttttttttt55ddddddddddd3333333333333300000000000000000000000000000000000000000000000000000000000000000 000000000000000000001ttttttttttttttt1dddddddddddd3333333333333300000000000000000000000000000000000000000000000000000000000000000 0000000000000000000111ttt1tttttttt111dddddddddddd3333333333333300000000000000000000000000000000000000000000000000000000000000000 00000000000000000011111111111ttt111111ddddddddddd3333333333333000000000000000000000000000000000000000000000000000000000000000000 000000000000000000111111111111111111111dddddddddd3333333333330000000000000000000000000000000000000000000000000000000000000000000 000000000000000000111111111111111111111111ddddddd3333333333300000000000000000000000000066666000000000000000000000000000000000000 0000000000000000001111111111111111111111111dddddd3333333333000000000000000000000000000666666600000000000000000000000000000000000 00000000000000000011111111111111111111111111ddd1dd333333300000000000000000000000000006666666660000000000000000000000000000000000 00000000000000000011111111111111111111111111111111100333000000000000000000000000000066666666666000000000000000000000000000000000 00000000000000000011111111111111111111111111111111100000000000000000000000000000000666666666666000000000000000000000000000000000 00000000000000000011111111111111111111111111111111100000000000000000000000000000006666666666666000666660600000000000000000000000 00000000000000000011111111111111111111111111111111100000000000000000000000000000066666666666666066666666660066600000000000000000 00000000000000000011111111111111111111111111111111100000000000000000000000000000666666666666666666666666666666666660000000000000 00000000000000000011111111111111111111111111111111000000000000000000000000000006666666666666666666666666666666666666000000000000 00000000000000000001111111111111111111111111111110000000000000000000000000000000666666666666666666666666666666666660000000000000 00000000000000000001111111111111111111111111111100000000000000000000000000000000666666668886666666666666666666666660000666000000 00000000000000000001111111111111111111111111111100000000000000000000000000000000666666688888888666666666666666666666006666600000 00000000000000000000111111111111111111111111111000000000000000000000000000000006666666888888888888886666666666666666666666600000 00000000000000000000000011111111111111111111110000000000000000000000000000000006666666888888888888888666666666666666666666600000 00000000000000000000000001111111111111111111100000000000000000000000000000000006666668888888888888888866666666666666666666600000 00000000000000000000000000011111111111111111100000000000000000000000000000000006666688888888888888888866666666666666666666600000 00000000000000000000000000001111111111111111000000000000000000000000000000000066666888888888888888888886666666rrr666666666000000 0000000000000000000000000000000000111111000000000000000000000000000000000000006666888888888888888888888666rrrrrrrr66666666000000 000000000000000000000000000000000000000000000000000000000000000000000000000000666688888888888888888888arrrrrrrrrrrr6666666600000 0000000000000000000000000000000000000000000000000000000000000000000000000000006666888888888888888aaaaarrrrrrrrrrrr66666666600000 000000000000000000000000000000000000000000000000000000000000000000000000000006666688888888888888aaaaaarrrrrrrrrrrr66666666600000 00000000000000000000000000000000000000000000000000000000000000000000000000000666688888888888888aaaaaaarrrrrrrrrrrrr6666666660000 00000000000000000000000000000000000000000000000000000000000000000000000000006666688888888888888aaaaaaarrrrrrrrrrrrr6666666660000 0000000000000000000000000000000000000000000000000000000000000000000000000000666688888888888888aaaaaaarrrrrrrrrrrrrr6666666660000 000000000000000000000000000000000000000000000000000000000000000000000000000066668888888888888aaaaaaaarrrrrrrrrrrrrr6666666600000 000000000000000000000000000000000000000000000000000000000000000000000000000066668888888888888aaaaaaaarrrrrrrrrrrrr66666666600000 00000000000000000000000000000000000000000000000000000000000000000000000000006668888888888888aaaaaaaaarrrrrrrrrrrrr66666666660000 0000000000000000000000000000000000000000000000000000000000000000000000000000666888888888888aaaaaaaaarrrrrrrrrrrrrr66666666666000 0000000000000000000000000000000000000000000000000000000000000000000000000000666888888888888aaaaaaaarrrrrrrrrrrrrrr66666666666000 000000000000000000000000000000000000000000000000000000000000000000000000000066688888888888e77aaaaaarrrrrrrrrrrrrr666666666666000 00000000000000000000000000000000000000000000000000000000000000000000000000066668888888888ee7777aaarrrrrrrrrrrrrrr666666666666000 0000000000000000000000000000000000000000000000000000000000000000000000000066666888888888eee777777rrrrrrrrrrrrrrr6666666666666000 000000000000000000000000000000000000000000000000000000000000000000000000006666688888888eeee77777cccrrrrrrrrrrrr66666666666660000 000000000000000000000000000000000000000000000000000000000000000000000000006666668888888eeee7777ccccccrrrrrrrrr666666666666600000 00000000000000000000000000000000000000000000000000000000000000000000000000666666666888eeeeee77ccccccccrrrrrrr6666666666666000000 00000000000000000000000000000000000000000000000000000000000000000000000000666666666688eeeeeesccccccccccrrrrr66666666666666000000 00000000000000000000000000000000000000000000000000000000000000000000000000066666666666sseeessscccccccccrrrr666666666666666600000 00000000000000000000000000000000000000000000000000000000000000000000000000006666666666ssssssssssccccccccrr6666666666666666600000 0000000000000000000000000000000000000000000000000000000000000000000000000000066666666sssssssssssscccccccs66666666666666666600000 0000000000000000000000000000000000000000000000000000000000000000000000000000666666666ssssssssssssssssssss66666666666666666000000 0000000000000000000000000000000000000000000000000000000000000000000000000006666666666ssssssssssssssssssss66666666666666666000000 0000000000000000000000000000000000000000000000000000000000000000000000000006666666666sssssssssssssssssss666666666666666660000000 0000000000000000000000000000000000000000000000000000000000000000000000000006666666666sssssssssssssssssss666666666666666660000000 0000000000000000000000000000000000000000000000000000000000000000000000000006666666666sssssssssssssssssss666666666666666660000000 0000000000000000000000000000000000000000000000000000000000000000000000000006666666666sssssssssssssssssss666666666666666666000000 0000000000000000000000000000000000000000000000000000000000000000000000000066666666666ssssssssssssssssss6666666666666666666000000 00000000000000000000000000000000000000000000000000000000000000000000000000666666666666sssssssssssssssss6666666666666666666000000 000000000000000000000000000000000000000000000000000000000000000000000000006666666666666sssssssssssssss66666666666666666660000000 000000000000000000000000000000000000000000000000000000000000000000000000000666666666666ssssssssssssss666666666666666666600000000 0000000000000000000000000000000000000000000000000000000000000000000000000006666666666666sssssssssssss666666666666666666600000000 0000000000000000000000000000000000000000000000000000000000000000000000000006666666666666ssssssssssss6666666666666666666000000000 00000000000000000000000000000000000000000000000000000000000000000000000000066666666666666sssssssssss6666666666666666666600000000 000000000000000000000000000000000000000000000000000000000000000000000000000666666666666666ssssssssss6666666666666666666660000000 000000000000000000000000000000000000000000000000000000000000000000000000000066666666666666sssssssss66666666666666666666600000000 0000000000000000000000000000000000000000000000000000000000000000000000000000066666666666666ssssssss66666666666666666666000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000666666666666666sssss666666666666666666660000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000006666666666666666666666666666666666666660000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000006666666666666666666666666666666666666000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000666666666666666666666666666666660000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000006666666666666666666666666666600000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000066666666666666666660000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006666666666666666000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000666666660000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006660000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777775 76666666666666666666666666666666555555566555555566555555566555555566666666666666666666666655555556655555556655555556655555556665 76666666666666666666666666666666511111166511111166511111166511111166666666666666666666666651111116651111116651111116651111116665 76622282222825666666666666666666511771166511771166511771166511771166666666666666666666666651111116651111116651111116651177116665 76688988988825666666666666666666517777166517777166517777166517777166666666666666666666666651111116651111116651111116651777716665 76628899998225666667767666777666517777166517777166517777166517777166666677767776677676766651111116651111116651111116651777716665 766229aaaa8885666676117166717166511771166511771166511771166511771166666677717171761171716651111116651111116651111116651177116665 76688a77798885666671667166776166511111166511111166511111166511111166666671717771777677616651111116651111116651111116651111116665 76688977aa8925666671667166717666666666666666666666666666666666666666666671717171617171766666666666666666666666666666666666666665 7662899aa98885666667767776717166666766666666776666667676666666776666666671717171776171716666676666666677666666767666666677666665 7662999aa98885666666116111616166667716666667617666667171666667617666666661616161611661616666771666666761766666717166666761766665 76628899982885666666666666666666666716666666176166667777666666776166666666666666666666666666671666666617616666777766666677616665 76688229988885666666666666666666666716666666761666666171166667617666666666666666666666666666671666666676166666617116666761766665 76655555555555666666666666666666667776666667777666666671666666776166666666666666666666666666777666666777766666667166666677616665 76666666666666666666666666666666666111666666111166666661666666611666666666666666666666666666611166666611116666666166666661166665 55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555