Exploding Pixels
in
Contributed Library Questions
•
1 years ago
Can someone help me to improve this code, add timer (dead particles) and maybe more realistically effect, not so square...
- import processing.opengl.*;
import codeanticode.glgraphics.*;
GLGraphicsOffScreen glg1;
GLTexture img;
boolean state = true;
ArrayList particles = new ArrayList();
color pix;
int xx = 0;
int yy = 0;
Particle[][] boom = new Particle[157][157];
void setup() {
size(1280, 720, GLConstants.GLGRAPHICS);
glg1 = new GLGraphicsOffScreen(this, 1280, 720);
img = new GLTexture(this, "bubble.png");
for (int i=0; i<157; i++) {
for (int j=0; j<157; j++) {
boom[i][j] = new Particle(i, j, random(-1, 1), random(1, 3), 1);
particles.add(boom[i][j]);
}
}
}
void draw() {
background(0);
for(int i=0; i<157; i++) {
for(int j=0; j<157; j++) {
pix = img.pixels[i + (j*157)];
if (0 < alpha(pix)) {
fill(pix);
boom[i][j].render();
}
if(state==false) {
boom[i][j].update();
}
}
}
/*for (int k = particles.size()-1; k >= 0; k--) {
Particle prt = (Particle) particles.get(k);
prt.run();
if (prt.dead()) {
particles.remove(k);
}
}*/
}
class Particle {
float x, y;
float xMove, yMove;
int w;
float timer;
Particle(float tempx, float tempy, float tempxMove, float tempyMove, int tempw) {
x = tempx;
y = tempy;
xMove = tempxMove;
yMove = tempyMove;
w = tempw;
timer = 40.0;
}
void run() {
update();
render();
}
void render() {
pushMatrix();
//translate(mouseX, mouseY);
translate(550, 150);
noStroke();
rectMode(CENTER);
rect(x, y, w, w);
popMatrix();
}
void update() {
x = x+2*xMove;
y = y+2*yMove;
}
boolean dead() {
if (timer <= 0.0) {
return true;
} else {
return false;
}
}
}
void mousePressed() {
if (state==false) {
state=true;
}
else {
state=false;
}
}
1