From 76ee7306bbd109339fa3f95ba334223d405921e8 Mon Sep 17 00:00:00 2001 From: itzmarkoni Date: Tue, 5 May 2026 20:32:40 -0400 Subject: [PATCH] updated --- programs/roulette.lua | 82 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 10 deletions(-) diff --git a/programs/roulette.lua b/programs/roulette.lua index 9e0e0fe..310a41c 100644 --- a/programs/roulette.lua +++ b/programs/roulette.lua @@ -241,20 +241,82 @@ end local ballX, ballY = 0, 0 -local function bgAt(bx, by) - local d = math.sqrt((bx - CX)^2 + (by - CY)^2) - if d > R_POCKET_OUT then return COL_TRACK end - if d > R_POCKET_IN then - -- approximate — use average of red/black (dark grey) - return 0x181818 +-- Repair the wheel pixels inside a circle of radius r centred on (cx,cy). +-- Re-rasterises all wedges clipped to that bounding box, then chrome on top. +-- This replaces the old flat-colour eraseBall which left coloured smears. +local function repairWheelPatch(cx, cy, r) + cx = math.floor(cx); cy = math.floor(cy) + -- 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 - return COL_HUB end local function eraseBall() - -- Shadow is drawn at +2,+2 with full BALL_RADIUS, so the total footprint - -- extends BALL_RADIUS+2 from centre in x/y. Add 3px margin to be safe. - px_circle(ballX, ballY, BALL_RADIUS + 5, bgAt(ballX, ballY)) + local r = BALL_RADIUS + 5 + repairWheelPatch(ballX, ballY, r) end local function drawBall(bx, by)