A continuacion les muestro como pueden hacer efecto de fuego aplicando la siguiente ecuacion, la cual consiste en el promedio de color basado en las posiciones del pixel.
(x,y)=((x,y)+(x-1,y+1)+(x,y+1)+(x+1,y+1))/4
El random de los colores van desde rojo, amarillo, negro y blanco, en el cual solamente se generan aletareamente en el ultimo renglon.
Codigo en processing:
Video
float y;
int r, g, b, i, j, n, np=20, cc=0;
int [][][] colores1=new int[101][101][3];
void setup() {
size(510, 510);
noStroke();
for (i=1; i<=100; i++) {
for (j=1; j<=100; j++) {
colores1[i][j][0]=0;
colores1[i][j][1]=0;
colores1[i][j][2]=0;
}
}
}
void draw() {
delay(10);
for (i=1; i<=100; i++) {
for (j=1; j<=100; j++) {
if (j==100 ) {
if ((int)random(0, 10)%3==0) {
//rojo
r=255;
g=0;
b=0;
} else if ((int)random(0, 10)%2==0) {
//amarillo
r=g=255;
b=0;
} else if ((int)random(0, 10)%2==0) {
r=g=b=255;
} else {
r=g=255;
b=0;
}
colores1[i][j][0]=r;
colores1[i][j][1]=g;
colores1[i][j][2]=b;
} else if (i<100 && j<100 &&i>1 &&j>1) {
if ((int)random(0, 10)%5==0) {
n=0;
} else {
n=(int)random(0, 5);
}
r=(colores1[i][j][0]+colores1[i-1][j+1][0]+colores1[i][j+1][0]+colores1[i+1][j+1][0])/4-n;
g=(colores1[i][j][1]+colores1[i-1][j+1][1]+colores1[i][j+1][1]+colores1[i+1][j+1][1])/4-n;
b=(colores1[i][j][2]+colores1[i-1][j+1][2]+colores1[i][j+1][2]+colores1[i+1][j+1][2])/4-n;
if (r<0)
r=0;
if (g<0)
g=0;
if (b<0)
b=0;
////////////
//////////
colores1[i][j][0]=r;
colores1[i][j][1]=g;
colores1[i][j][2]=b;
cuadro c=new cuadro(i, j, r, g, b);
if (j<96)
c.pinta();
}
}
}
}
class cuadro {
int x, y, r, g, b;
cuadro(int xx, int yy, int rr, int gg, int bb) {
x=xx;
y=yy;
r=rr;
g=gg;
b=bb;
}
void pinta() {
fill(r, g, b);
rect(x*5, y*5, 5, 5);
}
}

1 comentario:
Increible
Muy util Gracias
Publicar un comentario