Images: http://imgur.com/a/RsTfZ
Last active
April 13, 2017 22:51
-
-
Save PatrickMurphy/a3fb4c376be805edf81dea6bc4555121 to your computer and use it in GitHub Desktop.
Smoke Processing Weekly Challenge 57
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Particle { | |
PVector position, velocity, accel, shapeSize; | |
int transparency, texture_id; | |
float size_scale, rotation; | |
ParticleSystem parent; | |
Particle(PVector origin, ParticleSystem parent) { | |
this(origin, parent, 0); | |
} | |
Particle(PVector origin, ParticleSystem parent, int texture_id) { | |
position = origin.copy(); | |
velocity = new PVector(); | |
accel = new PVector(); | |
shapeSize = new PVector(150, 150); | |
rotation = random(0, 2*PI); | |
size_scale = .01; | |
transparency = 150; | |
this.texture_id = texture_id; | |
this.parent = parent; | |
} | |
void applyForce(PVector force) { | |
// sudo-mass calc | |
force.x = force.x / (10-(size_scale*10)); | |
accel.add(force); | |
} | |
void update() { | |
accel.limit(1.75); | |
accel.sub(velocity); | |
velocity.add(accel); | |
position.add(velocity); | |
accel.set(0, 0); | |
size_scale = min(1, size_scale+random(.0001, .01)); | |
rotation -= PI/random(200,230); | |
if (transparency <= 0) | |
ps.removeParticle(this); | |
else if (frameCount % 2 == 0) | |
transparency--; | |
} | |
void draw() { | |
pushMatrix(); | |
translate(position.x, position.y); | |
rotate(rotation); | |
tint(255, transparency); | |
image(textures[texture_id], 0, 0, shapeSize.x*size_scale, shapeSize.y*size_scale); | |
popMatrix(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ParticleSystem { | |
ArrayList<Particle> P; | |
PriorityQueue<Particle> remove_queue; | |
PVector origin; | |
int particleCount = 0; | |
int maxParticles = 75; | |
float xoff = 0; | |
boolean move; | |
ParticleSystem(PVector origin) { | |
this(origin,true); | |
} | |
ParticleSystem(PVector origin, boolean movement) { | |
remove_queue = new PriorityQueue<Particle>(); | |
this.origin = origin.copy(); | |
P = new ArrayList<Particle>(); | |
move = movement; | |
} | |
void addParticle() { | |
if (particleCount <= maxParticles) { | |
P.add(new Particle(origin,this)); | |
particleCount++; | |
} | |
} | |
void removeParticle(Particle p) { | |
remove_queue.add(p); | |
} | |
void removeDead() { | |
P.removeAll(remove_queue); | |
particleCount -= remove_queue.size(); | |
remove_queue.clear(); | |
} | |
void update() { | |
for (Particle p : P) { | |
if(move) | |
p.applyForce(new PVector(random(-15,15), - random(15))); | |
p.update(); | |
} | |
} | |
void draw() { | |
for (Particle p : P) p.draw(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
ParticleSystem ps; | |
PImage[] textures; | |
void setup() { | |
size(960, 540); | |
textures = new PImage[2]; | |
textures[0] = loadImage("smoke.png"); | |
textures[1] = loadImage("bg.jpg"); | |
imageMode(CENTER); | |
ps = new ParticleSystem(new PVector(124,184)); | |
} | |
void mousePressed(){ | |
println(mouseX,mouseY); | |
} | |
void draw() { | |
ps.removeDead(); | |
ps.update(); | |
if (frameCount%5==0) | |
ps.addParticle(); | |
tint(255,255); | |
background(0); | |
//image(textures[1],width/2,height/2,width,height); | |
//fill(255); | |
//text("Particle Count: "+ps.particleCount, 10, 10); | |
ps.draw(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment