mirror of
https://github.com/processing/processing4.git
synced 2026-06-08 16:40:46 +02:00
changes to simulate examples
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user