Last active
December 1, 2018 19:53
-
-
Save RyosukeCla/e33db770ace53552a7602ad9be7e2abe to your computer and use it in GitHub Desktop.
simple diffusion limited aggregation simulation with 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
int N = 2000; | |
float size = 5.0; | |
float r2 = size * size / 4.0; | |
PVector[] particles = new PVector[N]; | |
boolean[] statuses = new boolean[N]; | |
void setup() { | |
float theta; | |
float r; | |
particles[0] = new PVector(0, 0); | |
statuses[0] = true; | |
for (int i = 1; i < N; i++) { | |
theta = random(0, 2 * PI); | |
r = random(40, 150); | |
particles[i] = new PVector(r * cos(theta), r * sin(theta)); | |
statuses[i] = false; | |
} | |
size(500, 500); | |
background(40, 90); | |
translate(250, 250); | |
noStroke(); | |
} | |
void draw() { | |
noStroke(); | |
fill(40, 90); | |
rect(0, 0, 500, 500); | |
translate(250, 250); | |
for (int i = 0; i < N; i++) { | |
PVector pos = particles[i]; | |
boolean isCluster = statuses[i]; | |
if (isCluster) { | |
fill(40, 100, 200); | |
} else { | |
fill(255); | |
} | |
ellipse(pos.x, pos.y, size, size); | |
if (isCluster) continue; | |
float theta = random(0, 2 * PI); | |
float r = size / 2; | |
pos.add(new PVector(r * cos(theta), r * sin(theta))); | |
for (int j = 0; j < N; j++) { | |
if (j == i) continue; | |
isCluster = statuses[j]; | |
if (!isCluster) continue; | |
PVector otherPos = particles[j]; | |
float dist = (new PVector(pos.x - otherPos.x, pos.y - otherPos.y)).magSq(); | |
if (dist < r2 * 2.0 + 1) { | |
statuses[i] = true; | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
class は面倒だったので使わなかったです。