help with star array needed
in
Programming Questions
•
9 months ago
I am currently attempting to create an array of stars across the screen, in no particular order. I thought I was getting close with my script but I've just realised all I have done is replicate the script, which isn't going to work!
I guess I just want to create multiple objects, but I don't know where to start on that, as I've only been doing this for a week or so!
Any pointers would be awesome - many thanks in advance.
THE SCRIPT:
// VARIABLES
int step;
float angle, rad1, rad2;
int division=4;
int xsize=600;
int ysize=600;
float xdivider=float(xsize)/float(division);
float ydivider=float(ysize)/float(division);
float xcoord=xdivider;
float ycoord=ydivider;
Star star01;
Star star02;
// SETUP
void setup() {
size(xsize, ysize);
star01=new Star();
star02=new Star();
step = 10;
rad1 = 25.0;
rad2 = 50.0;
smooth();
xdivider = width / division;
ydivider = height / division;
}
//ANIMATION LOOP
void draw() {
background(55);
star01.display();
star02.display();
translate(xcoord, ycoord);
beginShape();
for (int i = 0; i < step; i++) {
float whichRad = (i%2 == 0)?rad1:rad2;
angle += TWO_PI/step;
float x = cos(angle)*whichRad;
float y = sin(angle)*whichRad;
stroke (0);
strokeWeight (2);
vertex(x, y);}
endShape(CLOSE);
angle += TWO_PI/360;
for (int x=0; x<division; x++) {
for (int y=0; y<division; y++) {
float xcoord = xdivider * (x+0.5);
float ycoord = ydivider * (y+0.5);
}
}
}
class Star{
//VARIABLES
float centreX;
float centreY;
void display()
{
beginShape();
for (int i = 0; i < step; i++) {
float whichRad = (i%2 == 0)?rad1:rad2;
angle += TWO_PI/step;
float x = cos(angle)*whichRad;
float y = sin(angle)*whichRad;
stroke (0);
strokeWeight (2);
vertex(x, y);
}
endShape(CLOSE);
angle += TWO_PI/360;
}
}
1