Hello to you all . I am trying to develop a pizza-like graph. Each “slice” of the full circle represents an element that will have some data attached to it. I am having trouble to acess each slice “individualy”. I’ve used a for loop to check if the distance of the mouse pointer is equal to the sum of the distance of the mouse pointer to the two edges of the “slice”, so i can keep track if the mouse pointer is inside the “slice”. It works but it is looking kind of glitchy, since the for loop keeps running an retrieves a false value more often than a true. Can somebody please help me by looking at the code or recommending any good resources can help me with the pizza-graph approach in P5 or Processing.
Thank you very much. I can make the issue more clear please tell me. And sorry for the bad english, it is not my native language.
here is the code. Basically I am just using one object of this class and using both functions I wrote.
class globalGraph {
constructor() {
this.angleinc = 2 * PI / 120;
this.radius = 300;
this.check = false;
this.toggle = true;
this.alpha = 0;
this.smoothedReceiving = 0;
}
display() {
fill(30, 50);
stroke(255);
for (var i = 1; i <= 120; i++) {
arc(width / 2, height / 2, this.radius * 2, this.radius * 2, (i - 1) * this.angleinc, i * this.angleinc, PIE);
}
}
highlight() {
var angleinit = PI / 60;
var angleend = 2 * (PI / 60);
var hover;
var hover2;
var hoverdist;
var v;
var teste;
var v2;
var distance = [];
var vec2 = [];
var vec1 = [];
for (var i = 0; i <= this.radius; i++) {
v = createVector(cos(angleinit) * i + width / 2, sin(angleinit) * i + height / 2);
vec1.push(v);
v2 = createVector(cos(angleend) * i + width / 2, sin(angleend) * i + height / 2);
vec2.push(v2);
}
for (var j = 0; j < vec1.length; j++) {
hoverdist = dist(vec1[j].x, vec1[j].y, vec2[j].x, vec2[j].y);
distance.push(hoverdist);
}
for (var w = 0; w < distance.length; w++) {
hover = floor(dist(mouseX, mouseY, vec1[w].x, vec1[w].y));
hover2 = floor(dist(mouseX, mouseY, vec2[w].x, vec2[w].y));
if (floor(distance[w]) == hover + hover2) {
this.check = true;
this.alpha = 100;
}
}
if (this.check == true) {
noStroke();
fill(255,0,0,this.alpha);
arc(width / 2, height / 2, this.radius * 2, this.radius * 2, angleinit, angleend);
this.check = false;
}
print(this.check);
}
}