About arrays.. Specific question
in
Programming Questions
•
14 days ago
Hey everyone..
I have begun learning about arrays. I sort of get it, but I have one problem understanding something..
I would like this effect (a circle follows the mouse position with interaction history):
int num = 50;
int[] x = new int[num];
int[] y = new int[num];
void setup() {
size(100, 100);
noStroke();
smooth();
fill(255, 102);
}
void draw() {
background(0);
// Shift the values to the right
for (int i = num - 1; i > 0; i--) {
x[i] = x[i-1];
y[i] = y[i-1];
}
// Add the new values to the beginning of the array
x[0] = mouseX;
y[0] = mouseY;
// Draw the circles
for (int i = 0; i < num; i++) {
ellipse(x[i], y[i], i / 2.0, i / 2.0);
}
}
But if I want the ellipse to instead be a star? A star is defined by a lot of points and not (x,y) like a circle.. How can I do this, I just cant seem to figure it out..
Here is a star, moveable, but missing the effect from the program at the top:
int[][] points = { {50, 18}, {61, 37}, {83, 43}, {69, 60},
{71, 82}, {50, 73}, {29, 82}, {31, 60},
{17, 43}, {39, 37} };
void setup() {
size(100, 100);
fill(0);
smooth();
}
void draw() {
background(204);
translate(mouseX - 50, mouseY - 50);
beginShape();
for (int i = 0; i < points.length; i++) {
vertex(points[i][0], points[i][1]);
}
endShape();
}
Please help me ):
1