/* To simulate smoke we're going to use a slightly modified ParticleSystem object, as well as an instance of our CustomRandom object. */ ParticleSystem ps; CustomRandom rand; void setup() { // setup the environment size(400, 400); colorMode(RGB, 255, 255, 255, 100); smooth(); // Instance our Random Number Generator rand = new CustomRandom(); /* It's fairly straight forward to just load an image, but we also want to apply an alpha mask to it, so the images can blend together */ // The masking image PImage maskImg = loadImage("smoke.gif"); // Create a blank image and fill it with white PImage smokeImg = new PImage(maskImg.width, maskImg.height); for (int i = 0; i < smokeImg.pixels.length; i++) { smokeImg.pixels[i] = color(255); } // apply the mask to the image smokeImg.mask(maskImg); // Create our particle system // 1 -> How many particles to start with // Vector -> Origin of the particles // smokeImg -> The image to use when rendering particles ps = new ParticleSystem(1, new Vector3D(width / 2, height - 20, 0), smokeImg); } void draw() { // clear the background background(0); // Figure out if our mouse is on the left or right of the screen // and scale the number down so we can use it in a vector float dx = (mouseX - width / 2) / 1000.0; // Create a vector force for a horizontal wind Vector3D wind = new Vector3D(dx, 0, 0); ps.wind(wind); // Let the particles run ps.simulate(); // Add a few new particles for (int i = 0; i < 2; i++) { ps.addParticle(); } }