We are about to switch to a new forum software. Until then we have removed the registration on this forum.
original code given:
int[] x = {50,61,83,69,71,50,29,31,17,39};
int[] y = {18,37,43,60,82,73,82,60,43,37};
beginShape();
for(int i=0;i < x.length; i++)
vertex(x[i],y[i]);
endShape(CLOSE);`
Add the appropriate methods so the star will appear at a random location. This method does NOT allow the user to select the location of a star.
Use a "for" loop in the setup method to call the star() method 100 times to produce 100 stars on the screen.
This is what I have so far...something obviously isn't right
void setup()
{
size(800,600);
background(#0F4D7C);
for (int i = 0; i < 100; i++)
{
randomStar();
}
}
void randomStar()
{
pushMatrix();
translate(0,0);
int[] x = {50,61,83,69,71,50,29,31,17,39};
int[] y = {18,37,43,60,82,73,82,60,43,37};
beginShape();
for(int i=0;i < x.length; i++)
vertex(x[i],y[i]);
endShape(CLOSE);
popMatrix();
}
Answers
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
Oh, it's supposed to stamp 100 stars! I guess this is how:
Hello GoToLoop !
for (int i = 0; i != LEN; vertex(X[i], Y[i++]));
^:)^ :)
Why are you using "static final" at the beginning ?
Funny you've only noticed it now since I do that almost in all of my sketches! :-$
final
guarantees that those fields X & Y gonna be forever bound to their initial arrays.static
avoids redundant re-instantiation of those 2 arrays in case the same sketch is instantiated more than once. Since those arrays' contents aren't supposed to change. They're immutable!"static avoids redundant re-instantiation of those 2 arrays in case the same sketch is instantiated more than once"
I see ! It was unnecessary here but it's smart :) Thanks !