xxxxxxxxxx
112
let isStartPage = true;
document.body.oncontextmenu = () => { return false };
let a = 0, rotated = false, frm, nm, val, hidden = true, stoppedColor;
let colors = ['#FF0000', '#64AF00', '#0EDBFA', '#FDFD4A']; // Add your desired colors
function setup() {
createCanvas(windowWidth, windowHeight);
frm = floor(random(1000, 1100));
nm = [];
for (let i = 1; i <= 16; i++) { // Fixed to 16 sections
nm.push(i);
}
// shuffle(nm, true);
}
function draw() {
if (isStartPage) {
drawStartPage();
} else {
drawWheelScreen();
}
}
function mousePressed() {
if (isStartPage && mouseX > width / 2 - 50 && mouseX < width / 2 + 50 && mouseY > height / 2 - 25 && mouseY < height / 2 + 25) {
isStartPage = false;
setupWheelScreen();
}
}
function drawStartPage() {
background(220);
textSize(32);
textAlign(CENTER, CENTER);
fill(0);
text("Click PLAY to start", width / 2, height / 2 - 50);
// Draw play button
fill(0,0,255);
rect(width / 2 - 50, height / 2 - 25, 100, 50);
fill(0);
textSize(24);
text("PLAY", width / 2, height / 2);
}
function setupWheelScreen() {
document.body.oncontextmenu = () => { return false };
frm = floor(random(1000, 1100));
nm = [];
for (let i = 1; i <= 16; i++) { // Fixed to 16 sections
nm.push(i);
}
// shuffle(nm, true);
}
function drawWheelScreen() {
clear();
strokeWeight(1);
createWheel();
rotate(a);
push();
rotate(-a);
fill(0);
circle(0, 0, 150);
fill(stoppedColor || colors[3 % colors.length]); // Use the stoppedColor or default color
circle(0, 0, 100);
pop();
if (rotated) {
a += 0.5;
a %= 2 * PI;
}
}
function keyPressed() {
if (key == " ") {
rotated = !rotated;
frameCount = 0;
frm = floor(random(1000, 1100));
}
}
function createWheel() {
let beg = 0;
let angle = 2 * PI / nm.length;
translate(width / 2, height / 2);
ellipseMode(CENTER);
let wh = min(width, height);
stroke(0);
fill(0);
circle(0, 0, wh - 10);
for (var i = 0; i < nm.length; i++) {
fill(colors[i % colors.length]); // Use modulo to cycle through colors
stroke(0);
if (a >= beg && a <= beg + angle) {
stoppedColor = colors[i % colors.length]; // Set stoppedColor when the wheel stops
fill(0);
stroke(stoppedColor);
strokeWeight(2);
val = nm[i];
}
arc(0, 0, wh - 50, wh - 50, beg, beg + angle, PIE);
let x = (wh - 150) * cos((beg + beg + angle) / 2) / 2;
let y = (wh - 150) * sin((beg + beg + angle) / 2) / 2;
beg += angle;
}
noFill();
}