I'm doing a project for my class where I have to draw 'blinking' Christmas lights (ellipses) in the form/shape of an image (for e.g. butterfly). My objective is to draw the blinking ellipses for 3 other images, every time the mouse is clicked. The view should change from butterfly to for e.g. blinking Christmas tree when the mouse is clicked.
Here's the code I have so far:
float x = 3;
float y = 3;
int xs[] = new int[0];
int ys[] = new int[0];
float alphas[] = new float[0];
float alphaDirs[] = new float[0];
float r = random(256);
float g = random(256);
float b = random(256);
PImage [] imageArray = new PImage[4];
void setup() {
size(635, 600);
smooth();
noStroke();
imageMode (CENTER);
for (int m=0; m < imageArray.length; m++) {
imageArray [0] = loadImage( "butterfly.png");
// imageArray [1] = loadImage( "three.jpg");
// imageArray [2] = loadImage( "four.jpg");
// imageArray [3] = loadImage( "five.jpg");
}
for (int x = 0; x < imageArray [0].width; x+=6) {
for (int y = 0; y< imageArray [0].height; y+=6) {
color c = imageArray [0].get(x, y);
if (red(c) < 255) {
if (random(0, 100) > 80) {
xs= append(xs, x);
ys=append(ys, y);
alphas=append(alphas, random(0, 255));
alphaDirs = append(alphaDirs, random(-5,5));
}
}
}
}
}
//int curI=0;
void draw() {
background(0);
for (int i = 0; i < xs.length; i+=1) {
// int i =curI;
fill(r, g, b, alphas[i]);
translate(xs[i], ys[i]);
// translate(pmouseX, pmouseY);
ellipse(0, 0, 10, 10);
// ellipse(15, 20, 10, 10);
translate(-xs[i], -ys[i]);
// translate(-pmouseX, -pmouseY);
// point(xs[i],ys[i]);
if(alphas[i] < 0) {
}
alphas[i]+=alphaDirs[i];
if((alphaDirs[i] > 0) && (alphas[i]>255)) {
alphas[i]=255;
alphaDirs[i] *=-1;
} else if ((alphaDirs[i] < 0) && (alphas[i]<0)){
alphas[i]=0;
alphaDirs[i] *=-1;
// curI = int(random(0, xs.length));
// }
}
}
}
void mouseClicked() {
I'm stuck at mouseClicked! Please please please help me! Thank you!