Hello, I was refactoring some old code and I noticed a problem with this sketch. It starts getting weird when there are 7 or 11, 13 (ad so on…) values in the array. I’m sure that’s because there are floating variables but I tried to round them, converting to int etc… but wasn’t able to solve the issues. Any help would be much appreciated.
int lineLength = 300;
int[] values = new int[0];
int[] val = new int[0];
void setup() {
size(800, 800);
pixelDensity(2);
values = append(values, int(random(100)));
val = append(val, int(random(100)));
}
void draw() {
background(50);
pushMatrix();
translate(width/2, height/2);
rotate(radians(180)); // rotate everything to put the first value at the top - center.
// DRAW GUI
float intraLineAngle = 360/values.length;
float angleInRadians = radians(intraLineAngle);
noFill();
stroke(150, 50);
for (int i = 10; i <= 100; i += 10) {
float diam = map(i, 0, 100, 0, lineLength*2);
ellipse(0, 0, diam, diam);
}
stroke(150);
for (int i = 0; i < values.length; i++) {
float posx = lineLength * sin(i*angleInRadians);
float posy = lineLength * cos(i*angleInRadians);
line(0, 0, posx, posy);
fill(255);
}
// DRAW FIRST CHART
beginShape();
for (int i=0; i < values.length; i++) {
float posx = map(values[i], 0, 100, 0, lineLength) * sin(i*angleInRadians);
float posy = map(values[i], 0, 100, 0, lineLength) * cos(i*angleInRadians);
fill(255, 0, 0, 50);
stroke(255, 0, 0);
vertex(-posx, posy); // -pos to rotate correctly clockwise
}
endShape(CLOSE);
popMatrix();
}
void mouseClicked() {
values = append(values, int(random(100)));
val = append(val, int(random(100)));
}