Skip to content

Instantly share code, notes, and snippets.

@dododas
Last active March 15, 2016 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dododas/11724b7cf8033907c077 to your computer and use it in GitHub Desktop.
Save dododas/11724b7cf8033907c077 to your computer and use it in GitHub Desktop.
Particles performing Brownian random walk - processing
// processing script to simulate Brownian random motion
int n_particles = 200; // number of particles
// prepare arrays to store particle coordinates
float[] x = new float[n_particles];
float[] y = new float[n_particles];
void setup() {
size(512, 512);
background(0);
// draw particles at random positions
stroke(0, 200, 0, 200);
fill(0, 200, 0, 200);
for (int i=0; i<n_particles; i++){
x[i] = random(0, 512);
y[i] = random(0, 512);
ellipse(x[i], y[i], 2, 2);
}
}
void draw() {
// update particle positions
background(0);
for (int i=0; i<n_particles; i++){
x[i] += randomGaussian();
y[i] += randomGaussian();
ellipse(x[i], y[i], 2, 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment