changes to simulate examples

This commit is contained in:
shiffman
2011-12-15 17:27:25 +00:00
parent 2072bceb6e
commit 65f795f70d
12 changed files with 205 additions and 307 deletions
@@ -8,48 +8,42 @@
// @pjs preload must be used to preload media if the program is
// running with Processing.js
/* @pjs preload="texture.gif"; */
/* @pjs preload="texture.png"; */
ParticleSystem ps;
Random generator;
void setup() {
size(640, 360);
colorMode(RGB, 255, 255, 255, 100);
// Using a Java random number generator for Gaussian random numbers
size(640,360);
generator = new Random();
// Create an alpha masked image to be applied as the particle's texture
PImage msk = loadImage("texture.gif");
PImage img = createImage(msk.width, msk.height, RGB);
for (int i = 0; i < img.pixels.length; i++) {
img.pixels[i] = color(255);
}
img.mask(msk);
ps = new ParticleSystem(0, new PVector(width/2, height-20), img);
PImage img = loadImage("texture.png");
ps = new ParticleSystem(0,new PVector(width/2,height-60),img);
smooth();
}
void draw() {
background(75);
background(0);
// Calculate a "wind" force based on mouse horizontal position
float dx = (mouseX - width/2) / 1000.0;
PVector wind = new PVector(dx,0,0);
displayVector(wind,width/2,50,500);
ps.add_force(wind);
float dx = map(mouseX,0,width,-0.2,0.2);
PVector wind = new PVector(dx,0);
ps.applyForce(wind);
ps.run();
for (int i = 0; i < 2; i++) {
ps.addParticle();
}
// Draw an arrow representing the wind force
drawVector(wind, new PVector(width/2,50,0),500);
}
void displayVector(PVector v, float x, float y, float scayl) {
// Renders a vector object 'v' as an arrow and a location 'loc'
void drawVector(PVector v, PVector loc, float scayl) {
pushMatrix();
float arrowsize = 4;
// Translate to location to render vector
translate(x,y);
translate(loc.x,loc.y);
stroke(255);
// Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
rotate(v.heading2D());