Using arrays to create and change circles?
in
Programming Questions
•
11 months ago
So I need a little bit of help with arrays. I have created an array that will create ellipses when I click the screen. Though once they are placed I can't seem to do anything else with them. I have created a tracker that moves across the screen and I want it to change the colour of each individual ellipse separately as it passes it. I was wondering if this is possible and how would I do it? Any help would be appreciated thanks
int count = 1;
float [] xp = new float [count];
float [] yp = new float [count];
float [] s = new float [count];
float [] c = new float [count];
int range = 25;
int v = 255;
int b = 0;
int lx = 0;
void setup ()
{
size (500, 500);
background (0);
}
void draw ()
{
gfx();
tracker();
}
void mousePressed ()
{
xp = expand(xp, count + 1);
yp = expand(yp, count + 1);
s = expand(s, count + 1);
c = expand(c, count + 1);
xp[count]= mouseX;
yp[count]= mouseY;
s[count]=random(5);
count = count + 1;
}
void gfx ()
{
smooth ();
noStroke();
fill (v, v, v);
int i = 0;
while ( i < count){
ellipse (xp[i], yp[i], s[i], s[i]);
// yp[i] = yp[i]+1; //moving up
i = i + 1;}
}
void tracker ()
{
smooth ();
stroke (0);
// noStroke ();
line (lx, 0, lx, 500);
lx = lx+1;
if (lx > 500){
lx = 0;}
}
int count = 1;
float [] xp = new float [count];
float [] yp = new float [count];
float [] s = new float [count];
float [] c = new float [count];
int range = 25;
int v = 255;
int b = 0;
int lx = 0;
void setup ()
{
size (500, 500);
background (0);
}
void draw ()
{
gfx();
tracker();
}
void mousePressed ()
{
xp = expand(xp, count + 1);
yp = expand(yp, count + 1);
s = expand(s, count + 1);
c = expand(c, count + 1);
xp[count]= mouseX;
yp[count]= mouseY;
s[count]=random(5);
count = count + 1;
}
void gfx ()
{
smooth ();
noStroke();
fill (v, v, v);
int i = 0;
while ( i < count){
ellipse (xp[i], yp[i], s[i], s[i]);
// yp[i] = yp[i]+1; //moving up
i = i + 1;}
}
void tracker ()
{
smooth ();
stroke (0);
// noStroke ();
line (lx, 0, lx, 500);
lx = lx+1;
if (lx > 500){
lx = 0;}
}
1