Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import "./style.css";
// --- Configuration -----------------------------------------------------------

const MAX_OPTIONS = 30;

const params = new URLSearchParams(window.location.search);
let items: string[] =
params.getAll("option").length > 0
? params.getAll("option").slice(0, MAX_OPTIONS)
: ["Aiko", "Björn", "Chioma", "Diego", "Elif", "Femi", "Guadalupe"];
const DEFAULT_OPTIONS = [
"Aiko",
"Björn",
"Chioma",
"Diego",
"Elif",
"Femi",
"Guadalupe",
];

const COLORS = [
"#e63946",
Expand All @@ -29,6 +32,12 @@ const FRICTION = 0.987;
// Speed below which we consider the wheel stopped.
const STOP_THRESHOLD = 0.0005;

const params = new URLSearchParams(window.location.search);
let items: string[] =
params.getAll("option").length > 0
? params.getAll("option").slice(0, MAX_OPTIONS)
: DEFAULT_OPTIONS;

// --- Canvas & button setup ---------------------------------------------------

const canvas = document.querySelector<HTMLCanvasElement>("#wheel")!;
Expand Down Expand Up @@ -171,7 +180,10 @@ function drawWheel(angleOffset: number): void {
for (let i = 0; i < items.length; i++) {
const startAngle = angleOffset + i * sliceAngle;
const endAngle = startAngle + sliceAngle;
const color = COLORS[i % COLORS.length];

const modifier =
Math.floor(i / COLORS.length) * Math.round(COLORS.length / 2);
const color = COLORS[(i + modifier) % COLORS.length];

// --- Wedge fill ---
ctx.beginPath();
Expand Down