xxxxxxxxxx
83
const circlesize = 200;
let anglePad1 = 0;
let anglePad2 = 0;
let angleBall = 0;
let padWidth;
const colorBall = [255,0,0];
const colorPad1 = [0,255,0];
const colorPad2 = [0,0,255];
function setup() {
createCanvas(400, 400);
padWidth = PI/8;
textSize(80);
textAlign(CENTER,CENTER);
strokeCap(SQUARE);
}
function draw() {
background(220);
noFill();
stroke(0);
strokeWeight(16);
push();
translate(200,150);
circle(0,0,circlesize);
angleBall = mouseY / 50;
anglePad1 = mouseX / 50;
anglePad2 = anglePad1 + PI;
noFill();
stroke(colorPad1);
arc(0,0,circlesize,circlesize,anglePad1 - padWidth,anglePad1 + padWidth);
stroke(colorPad2);
arc(0,0,circlesize,circlesize,anglePad2 - padWidth,anglePad2 + padWidth);
noStroke();
fill(colorBall);
circle(cos(angleBall) * circlesize/2, sin(angleBall) * circlesize/2, 20);
pop();
if(intersectingDisplay()) {
noStroke();
fill(colorBall);
text("!",200,160);
}
}
function intersectingDisplay(){
noFill();
stroke(128);
line(A2L(0), 270,A2L(TWO_PI), 270);
fill(colorBall);
noStroke();
circle(A2L(angleBall), 300,16);
const p1a1 = normalizeSingleAngle(anglePad1 - padWidth);
const p1a2 = normalizeSingleAngle(anglePad1 + padWidth);
stroke(colorPad1);
line(A2L(p1a1), 335,A2L(p1a2), 325);
const p2a1 = normalizeSingleAngle(anglePad2 - padWidth);
const p2a2 = normalizeSingleAngle(anglePad2 + padWidth);
stroke(colorPad2);
line(A2L(p2a1), 365,A2L(p2a2), 355);
return intersecting(angleBall,p1a1,p1a2,p2a1,p2a2)
}
function intersecting(ab,p1a1,p1a2,p2a1,p2a2){
return (ab >= p1a1 && ab <= p1a2) ||
(ab >= p2a1 && ab <= p2a2);
}
function A2L(a) {
return 100 + (a * 32);
}
function normalizeSingleAngle(a){
while(a < 0) a += TWO_PI;
return a % TWO_PI;
}