Bombolles

Programador 

Pau Tutó

Instruccions

Clica sobre la pantalla per a fer aparèixer més bombolles. Reinicialitza l’scketch clicant qualsevol tecla.

 


Codi:
/* 
Aquí presento totes les variables, on apareixerean les rodones, cap a on es mouran, de quin colors seran…*/
float[] coorX = new float[10];
float[] velX = new float[10];
float[] coorY = new float[10];
float[] velY = new float[10];
float[] g = new float[255];
float[] b = new float[255];
float[] r = new float[255];
float[] size = new float[10];
float [] movimentX = new float[10];
float [] movimentY = new float[10];
int k, l, R, G, B, S;void setup() {
int i, j;
stroke(1);
size(800, 400);
background(255);
/* Aquí dibuixo totes les rodones, dibuixo un total de 10, totes les rodones són diferents */
for (i=0; i<10; i++) {
coorX[i] = 400;
}
for (i=0; i<10; i++) {
size[i] = random(5, 40);
}
for (j=0; j<10; j++) {
velX[j] = random(-2, 2);
}
for (k=0; k<10; k++) {
coorY[k] = 200;
}
for (R=0; R<10; R++) {
r[R] = random(0, 255);
}
for (G=0; G<10; G++) {
g[G] = random(0, 255);
}
for (B=0; B<10; B++) {
b[B] = random(0, 255);
}
for (l=0; l<10; l++) {
velY[l] = random(-2, 2);
}
}
void draw() {
/* Aquí faig que si apretes qualsevol tecla la pantalla es reinicia */
if (keyPressed ==true) {
background(255);
}
float a=random(0, 1);
int i;
for (i=0; i<10; i++) {
fill(r[i], g[i], b[i]);
ellipse(coorX[i], coorY[i], size[i], size[i]);
size[i]= size[i]-0.2;
if (size[i]<=0) {
size[i]=0;
}
/* Aquí sumo les coordenades random creades abans per moure les rodones cap a direccions diferents */
coorX[i]=coorX[i]+velX[i];
coorY[i]=coorY[i]+velY[i];
}
for (i=0; i<10; i++) { if (a>0.7) {
velY[i]=random(-5, 5);
}
if (a>0.5) {
velY[i]=random(-5, 5);velX[i]=random(-5, 5);
}
}
}void mousePressed() {
/* Aquí torno a dibuixar totes les bombolles quan clico el ratolí, repeteixo el codi amb totes les variables */
int i, j;
i=0;
j=0;
for (i=0; i<10; i++) {
coorX[i] = mouseX;
}
for (j=0; j<10; j++) {
velX[j] = random(-2, 2);
}
for (k=0; k<10; k++) {
coorY[k] =mouseY;
}
for (l=0; l<10; l++) {
velY[l] = random(-2, 2);
}
for (R=0; R<10; R++) {
r[R] = random(0, 255);
}
for (G=0; G<10; G++) {
g[G] = random(0, 255);
}
for (B=0; B<10; B++) {
b[B] = random(0, 255);
}
for (i=0; i<10; i++) {
size[i] = random(5, 40);
}
}

 

Deja un comentario