Skip to content

Instantly share code, notes, and snippets.

@m0ppers
Last active April 23, 2025 13:47
Show Gist options
  • Save m0ppers/d660e56a2640d6d895b80a35a64b8010 to your computer and use it in GitHub Desktop.
Save m0ppers/d660e56a2640d6d895b80a35a64b8010 to your computer and use it in GitHub Desktop.
coppershowdown seminar code
copper_showdown_version = "0.0.1"
copper_showdown_api_version = "0.1.0"
code = '''
local num_frames = 48
local bg_color = 0x222
local bar_size = 0xf
local vpos_start = 0x1f
local vpos_end = 0x126
local cx = 320/2
local cy = 256/2
local bars = {
{
o=0,
c=0xf00,
},
{
o=0.2,
c=0xff0,
},
{
o=0.4,
c=0xf0f,
},
{
o=0.6,
c=0x0f0,
},
}
newlist("start")
nextlist("setup")
newlist("setup")
color(1, 0xfff)
push({
DDFSTRT, 0x38,
DDFSTOP, 0xd0,
DIWSTRT, 0x2c81,
DIWSTOP, 0x2cc1,
BPL1MOD, 0,
BPL2MOD, 0,
BPLCON0, 1 << 12,
})
nextlist("frame0")
function insert(t, vpos, c)
local o = {vpos=vpos, c=c}
for k,v in ipairs(t) do
if v.vpos > vpos then
table.insert(t, k, o)
return
end
end
table.insert(t, o)
end
function calc_bars(f)
local result = {}
for k,b in ipairs(bars) do
local v = (math.sin(f/num_frames * math.pi * 2 + b.o) + 1) /2
local vpos = math.floor(vpos_start + (vpos_end-vpos_start) * v)
insert(result, vpos, b.c)
end
return result
end
local amiga_suxx = false
function wait(vpos)
if vpos > 0xff and not amiga_suxx then
amiga_suxx = true
push(0xffe1, 0xfffe)
end
vpos = vpos & 0xff
push(vpos << 8 | 0x11, 0xfffe)
end
function frame(f)
amiga_suxx = false
local b = calc_bars(f)
push({
BPL1PTH, "screen" .. f .. "#h",
BPL1PTL, "screen" .. f .. "#l",
})
--color(0, bg_color)
local reset = nil
for k,b2 in ipairs(b) do
if reset ~= nil and reset < b2.vpos then
wait(reset)
color(0, bg_color)
end
--print(b2.vpos)
reset = b2.vpos + bar_size
wait(b2.vpos)
color(0, b2.c)
end
wait(reset)
color(0, bg_color)
end
for f=0,num_frames-1 do
newlist("frame"..f)
frame(f)
nextlist("frame" .. (f+1) % num_frames)
end
function fract(x)
return x - math.floor(x)
end
function is_hit(x,y,f)
if x % 4 == 0 and y % 4 == 0 then
return true
end
local TAU = math.pi *2
local dx = cx - x
local dy = cy - y
local d = math.sqrt(dx * dx + dy * dy)
local id = math.floor(d * 0.09)
local angle = math.atan(dx, dy)
angle = fract((angle / TAU + 0.5) + f / num_frames) * TAU - math.pi;
if(id == 1) then
return true
elseif (id == 2) then
if(angle < -0.32 and angle > -1.45) then
return true
end
elseif(id == 3) then
if(angle < 0.35 and angle > 0.1) then
return true
end
if(angle < 2.3 and angle > 1.7) then
return true
end
if(angle < -1.9 and angle > -2.6) then
return true
end
elseif(id == 4) then
if(angle < 0.8 and angle > -0.2) then
return true
end
if(angle < 2.75 and angle > 1.0) then
return true
end
if(angle < -1.65 or angle > 2.95) then
return true
end
elseif(id == 5) then
return true
elseif(id == 7) then
if(angle < -2.6 and angle > -2.77) then
return true
elseif(angle > 2.75) then
return true
elseif(angle > -1.55 and angle < -1.25) then
return true
elseif(angle > -0.95 and angle < -0.75) then
return true
elseif(angle > -0.23 and angle < 0.23) then
return true
elseif(angle > 0.7 and angle < 1.7) then
return true
end
elseif(id == 8) then
return true
elseif(id == 9) then
if(angle > -2.55 and angle < -1.6) then
return true
elseif(angle > 0.7 and angle < 0.85) then
return true
end
end
return false
end
function screen_mem(x, y, f)
local m = 0
for i=0,15 do
local h = is_hit(x+i, y, f)
if h then
m = m | 1 << (15-i)
end
end
return m
end
for f=0, num_frames do
label("screen"..f)
for y=1,256 do
for x=1,320/16 do
push(screen_mem((x-1) * 16, y-1, f))
end
end
end
return resolve(), DMAF_RASTER'''
[[images]]
name = "akronymeanalogiker.png"
data = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMAAAAA3CAMAAABtlbWUAAAAAXNSR0IArs4c6QAAABhQTFRFAAAARCIz3Xci//8zme5VM2aId0SIiJlEvtb+BgAAAAh0Uk5TAP/////////VylQyAAABSElEQVRoge2YWQ7DIAxE46bL/W/cKqKJYVgMZAFif6TWMDY8UEXaaRo0qLXIBni4Qc4nz4oUTGJVCqAA7QIQepoGAEUBjgGYTWAyOwqBgh6fku7MlQMBSpW7AJTexLsvjgSeiLI3wLIrPQMkkCQA4s4nAfjXrQAXAXiUFAA+6wCebtQqlPDg0/IcCEACTzFA+S+yRgBWz30B0okCKIACXA9Q96cZmybDXjcn2TcDvdzIUDiApAq8BF5RHwVQgG4Afl+4vQDYQIMnIJlreABMsKmbKEDh+VsAbxOYvMNDJuEA4apNAW+8yty76PECeFoQKAKA2EZkAgSVcwE870KBxQX2+3KArWqHE8CXuc4AFkUBVgAWwT4tA4iU2wI4Z8usNsDHDYIs5kkrrN8foKQPGxgUABNcgseTpYQB0p0VQAEUIADQY0xjxBdRnYk/KFw/CwAAAABJRU5ErkJggg=="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment