This commit is contained in:
2026-05-05 20:32:40 -04:00
parent 5c6a02b850
commit 76ee7306bb

View File

@@ -241,20 +241,82 @@ end
local ballX, ballY = 0, 0 local ballX, ballY = 0, 0
local function bgAt(bx, by) -- Repair the wheel pixels inside a circle of radius r centred on (cx,cy).
local d = math.sqrt((bx - CX)^2 + (by - CY)^2) -- Re-rasterises all wedges clipped to that bounding box, then chrome on top.
if d > R_POCKET_OUT then return COL_TRACK end -- This replaces the old flat-colour eraseBall which left coloured smears.
if d > R_POCKET_IN then local function repairWheelPatch(cx, cy, r)
-- approximate — use average of red/black (dark grey) cx = math.floor(cx); cy = math.floor(cy)
return 0x181818 -- Bounding box for the patch
local px0 = cx - r; local px1 = cx + r
local py0 = cy - r; local py1 = cy + r
-- For each wedge, re-rasterise only within this bounding box
for slotIdx = 1, NUM_POCKETS do
local halfArc = math.pi / NUM_POCKETS
local midAngle = FIXED_ROTOR + (slotIdx - 1) * TWO_PI / NUM_POCKETS
local a0 = midAngle - halfArc
local a1 = midAngle + halfArc
local arc = (a1 - a0) % TWO_PI
local num = WHEEL_ORDER[slotIdx]
local col = pocketColor(num)
local ri, ro = R_POCKET_IN, R_POCKET_OUT
for sy = py0, py1 do
local runStart = nil
for sx = px0, px1 do
local dx = sx - CX; local dy = sy - CY
local dist = math.sqrt(dx*dx + dy*dy)
local inRing = dist >= ri and dist <= ro
local rel = (math.atan2(dy, dx) - a0) % TWO_PI
local inWedge = rel <= arc
if inRing and inWedge then
if not runStart then runStart = sx end
else
if runStart then
px_rect(runStart, sy, sx - runStart, 1, col)
runStart = nil
end
end
end
if runStart then
px_rect(runStart, sy, px1 - runStart + 1, 1, col)
end
end
end
-- Repaint chrome rings and background that overlap the patch,
-- in inside-out priority order using elseif so each pixel is set once.
for sy = py0, py1 do
for sx = px0, px1 do
local dx = sx - CX; local dy = sy - CY
local d = math.sqrt(dx*dx + dy*dy)
if d <= R_HUB - 4 then
px_rect(sx, sy, 1, 1, COL_HUB)
elseif d <= R_HUB then
px_rect(sx, sy, 1, 1, COL_HUB_RING)
elseif d <= R_POCKET_IN then
-- gap between hub ring and inner rim — plain hub bg
px_rect(sx, sy, 1, 1, COL_HUB)
elseif d <= R_POCKET_IN + 2 then
px_rect(sx, sy, 1, 1, COL_RIM)
elseif d <= R_POCKET_OUT then
-- inside pocket ring — wedge already painted above
elseif d <= R_POCKET_OUT + 2 then
px_rect(sx, sy, 1, 1, COL_RIM)
elseif d <= R_OUTER - 6 then
px_rect(sx, sy, 1, 1, COL_TRACK)
elseif d <= R_OUTER then
px_rect(sx, sy, 1, 1, COL_RIM)
end
end
end end
return COL_HUB
end end
local function eraseBall() local function eraseBall()
-- Shadow is drawn at +2,+2 with full BALL_RADIUS, so the total footprint local r = BALL_RADIUS + 5
-- extends BALL_RADIUS+2 from centre in x/y. Add 3px margin to be safe. repairWheelPatch(ballX, ballY, r)
px_circle(ballX, ballY, BALL_RADIUS + 5, bgAt(ballX, ballY))
end end
local function drawBall(bx, by) local function drawBall(bx, by)