Skip to content

Instantly share code, notes, and snippets.

@thacuber2a03
Created April 11, 2024 13:47
Show Gist options
  • Save thacuber2a03/e53a0e79f085f09f48ee09f3d57b767c to your computer and use it in GitHub Desktop.
Save thacuber2a03/e53a0e79f085f09f48ee09f3d57b767c to your computer and use it in GitHub Desktop.
picotron cartridge // www.picotron.net
version 2
:: gfx/0.gfx
b64$LS1bW3BvZCxjcmVhdGVkPSIyMDI0LTA0LTA3IDE0OjU5OjUxIixtb2RpZmllZD0iMjAyNC0w
NC0xMSAwMTo0NDoxMyIscmV2aXNpb249MzUxN11dbHo0AG0AAAAFMQAA8xR7WzBdPXtibXA9cHh1
AEMgEBAE8PAsZmxhZ3M9MCxwYW5feAgAz3k9MCx6b29tPTh9LDEA------------------------
----------------------------------------51BtPTh9fQ==
:: gfx/.info.pod
b64$LS1bW3BvZCxjcmVhdGVkPSIyMDI0LTA0LTA3IDE0OjU5OjQwIixzdG9yZWQ9IjIwMjQtMDQt
MDcgMTQ6NTk6NDAiXV1sejQABAAAAAMAAAAwbmls
:: main.lua
--[[pod_format="raw",created="2024-04-07 14:59:45",modified="2024-04-11 01:44:13",revision=4010]]
local grid_size <const> = 16
local circle_rad <const> = 8
local padding <const> = 20
local window_size <const> = grid_size * circle_rad + padding * 2
local t = 0 -- custom var to be able to reset time after input
local f = "sin(y/4+t*2)"
local lf -- loaded func; the thing that will actually be called
local err -- an error was thrown while loading the function?
local editing = false
local edity, targetey = -1, -1 -- editor's y and target y positions
local ecursor = 1
local blinkt = 0
local non_word_chars = " \t\n/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-"
local function rectwh(x, y, w, h, c)
rect(x, y, x+w, y+h, c)
end
local function rectfillwh(x, y, w, h, c)
rectfill(x, y, x+w, y+h, c)
end
local tixy_env = {
tonumber = tonumber,
tostring = tostring,
}
for k,v in pairs(math) do tixy_env[k] = v end
for k,v in pairs(string) do tixy_env[k] = v end
local function reload()
local luaf = "return function(t,i,x,y) return "..f.." end"
local res, l, val
err = true
res = load(luaf, "tixy-func", "t", tixy_env)
if (not res) return
l = res()
res, val = pcall(l,1,2,3,4)
if (not res) return
if (type(val) == "nil") return
lf = l
t = 0
err = false
end
function _init()
window {
x = (480-window_size)/2,
y = (270-window_size)/2+11,
width = window_size,
height = window_size,
fullscreen = false,
resizeable = false,
title = "tixy"
}
reload()
end
function _update()
t += 1/60
if targetey != edity then
edity += (targetey-edity) * 0.2
if abs(targetey-edity) <= 1e-2 then
targetey = edity
end
end
local t = readtext()
if not editing and (t or keyp "enter" or keyp "space") then
editing = true
targetey = padding
elseif editing then
if keyp "enter" then
editing = false
targetey = -1
end
local prev = ecursor
if (keyp "right") ecursor += 1
if (keyp "left") ecursor -= 1
if (keyp "home") ecursor = 1
if (keyp "end") ecursor = #f+1
if keyp "backspace" then
f = f:sub(1, max(ecursor-2, 0)) .. f:sub(ecursor, -1)
ecursor -= 1
reload()
end
if keyp "delete" then
f = f:sub(1, ecursor-1) .. f:sub(ecursor+1, -1)
blinkt = time() -- doesn't move cursor, so manually set
reload()
end
ecursor = mid(1, ecursor, #f+1)
if t then
f = f:sub(1, ecursor-1) .. t .. f:sub(ecursor, -1)
ecursor += 1
reload()
end
if (ecursor != prev) blinkt = time()
end
end
local function center_print(t, x, y, c)
local w = print(t, 1000, 1000)-1000
print(t, x-w/2, y-6, c)
end
local function draw_editor()
clip(padding, window_size-padding, window_size-padding*2, padding)
center_print("press enter or a letter", window_size/2, window_size-padding/2-edity, 5)
if edity <= 1e-1 then
clip()
return
end
local textc = 5
local curc = 7
local rw = (print(f, 1000, 1000, 7)) - 1000
if err then
textc = 7
curc = 0
rectfillwh(
padding,
window_size-edity/2-1,
rw+2, 9,
8
)
end
if (time() - blinkt) % 1 <= 0.5 then
local twidth = (print(sub(f, 1, ecursor-1), 1000, 1000))-1000
rectfillwh(
window_size/2-padding/2+twidth+1,
window_size-edity/2,
0, 7,
curc
)
end
center_print(f, window_size/2, window_size-edity/4+1, textc)
clip()
end
function _draw()
cls()
camera(0, edity/2)
for i=0, (grid_size * grid_size) - 1 do
local x = i % grid_size
local y = math.floor(i / grid_size)
local res, r = pcall(lf, t, i, x, y)
err = err or (not res)
if (type(r) != "number") r = r and 1 or 0
r = mid(-1, r, 1)
local c = r < 0 and 8 or 7
local offset = (window_size-((grid_size-1) * circle_rad))/2
circfill(
offset + x * circle_rad,
offset + y * circle_rad,
math.abs(r)*(circle_rad/2)-1,
c
)
end
draw_editor()
end
:: map/0.map
b64$LS1bW3BvZCxjcmVhdGVkPSIyMDI0LTA0LTA3IDE0OjU5OjQ0Iixtb2RpZmllZD0iMjAyNC0w
NC0xMSAwMTo0NDoxMyIscmV2aXNpb249MzUxNV1dbHo0AGgAAABYEAAA8Ah7e2JtcD11c2VyZGF0
YSgiaTE2IiwzMgMALyIwAQD--------------------78QgiKSxoaWRkZW49ZmFsc2UscGFuX3g9
MAgA0nk9MCx0aWxlX2g9MTYKABB3CgCAem9vbT0xfX0=
:: map/.info.pod
b64$LS1bW3BvZCxjcmVhdGVkPSIyMDI0LTA0LTA3IDE0OjU5OjQwIixzdG9yZWQ9IjIwMjQtMDQt
MDcgMTQ6NTk6NDAiXV1sejQABAAAAAMAAAAwbmls
:: sfx/0.sfx
b64$LS1bW3BvZCxjcmVhdGVkPSIyMDI0LTA0LTA3IDE1OjAwOjA1Iixtb2RpZmllZD0iMjAyNC0w
NC0xMSAwMTo0NDoxMyIscmV2aXNpb249MzUwN11dbHo0ABEBAADBCAAA8CdweHUAAygAAAMABA9A
EAIOAAGgASACoA4ADxAADfDKAQIDBAUGBwAP-5AICQoLDwwPDQ8ODw8QAPAADQ8RDxIPEw8UDxUP
Fg8XEwDxAQ8YDxkPGg8bDxwPHQ8eDx8UAPEAIA8hDyIPIw8kDyUPJg8nFADxACgPKQ8qDysPLA8t
Dy4PLxQA8QAwDzEPMg8zDzQPNQ82DzcUAP8FOA85DzoPOw88Dz0PPg8-AA--8P8BAOv-J1oBEAYP
IBABIAEgAfAAAhACDBABIA8hIAEwD0Dwww8oD--wxg-4Cg--D4AP9w8NAfAJARAGDDAA--_6H-8B
AMy-6A9AAA1A--_w8HAKAP--ZB--AQCXUP----8f
:: sfx/.info.pod
b64$LS1bW3BvZCxjcmVhdGVkPSIyMDI0LTA0LTA3IDE0OjU5OjQwIixzdG9yZWQ9IjIwMjQtMDQt
MDcgMTQ6NTk6NDAiXV1sejQABAAAAAMAAAAwbmls
:: .info.pod
b64$LS1bW3BvZCxydW50aW1lPTUsc3RvcmVkPSIyMDI0LTA0LTExIDAxOjQ0OjEzIix3b3Jrc3Bh
Y2VzPXt7bG9jYXRpb249Im1haW4ubHVhIzE0NSIsd29ya3NwYWNlX2luZGV4PTF9LHtsb2NhdGlv
bj0iZ2Z4LzAuZ2Z4Iix3b3Jrc3BhY2VfaW5kZXg9Mn0se2xvY2F0aW9uPSJtYXAvMC5tYXAiLHdv
cmtzcGFjZV9pbmRleD0zfSx7bG9jYXRpb249InNmeC8wLnNmeCIsd29ya3NwYWNlX2luZGV4PTR9
fV1dbHo0AAQAAAADAAAAMG5pbA==
:: gfx/
:: map/
:: sfx/
:: [eoc]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment