Last active
March 15, 2016 04:17
-
-
Save dododas/11724b7cf8033907c077 to your computer and use it in GitHub Desktop.
Particles performing Brownian random walk - processing
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
// 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