Created
May 8, 2019 15:41
-
-
Save hidex7777/21de46e9022cf98d4b30090bf44b8937 to your computer and use it in GitHub Desktop.
let go for 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
//let go | |
//init settings | |
int _minx = -300; | |
int _maxx = 1300; | |
int _miny = -300; | |
int _maxy = 1300; | |
int _minz = -800; | |
int _maxz = 500; | |
int _particlenum = 500; | |
float _friction = 0.01; | |
float _noiseScale = 0.02; | |
float _noiseStrength = 0.5; | |
//date | |
int _y = year(); | |
int _mo = month(); | |
int _d = day(); | |
int _h = hour(); | |
int _mi = minute(); | |
int _s = second(); | |
PVector[] location = new PVector[_particlenum]; | |
PVector[] velocity = new PVector[_particlenum]; | |
PVector[] acceleration = new PVector[_particlenum]; | |
PVector[] force = new PVector[_particlenum]; | |
void setup(){ | |
size(1000, 1000, P3D); | |
smooth(); | |
frameRate(60); | |
for(int i = 0; i < _particlenum; i++){ | |
location[i] = new PVector(random(width), random(height), random(_minz, _maxz)); | |
velocity[i] = new PVector(0, 0, 0); | |
acceleration[i] = new PVector(0, 0, 0); | |
force[i] = new PVector(0, 0, 0); | |
} | |
background(255); | |
} | |
void draw(){ | |
background(255); | |
stroke(0); | |
strokeWeight(1); | |
for(int i = 0; i < _particlenum; i++){ | |
force[i].x = cos(noise(location[i].x * _noiseScale, location[i].y * _noiseScale, location[i].z * _noiseScale) * TWO_PI * 2.5); | |
force[i].y = sin(noise(location[i].x * _noiseScale, location[i].y * _noiseScale, location[i].z * _noiseScale) * TWO_PI * 2.5); | |
force[i].z = cos(noise(location[i].x * _noiseScale, location[i].y * _noiseScale, location[i].z * _noiseScale) * TWO_PI * 1.0); | |
force[i].mult(_noiseStrength); | |
acceleration[i].add(force[i]); | |
velocity[i].add(acceleration[i]); | |
velocity[i].mult(1.0 - _friction); | |
location[i].add(velocity[i]); | |
acceleration[i].set(0, 0, 0); | |
if(location[i].x > _maxx){ | |
location[i].x = _maxx; | |
velocity[i].x *= -1; | |
} | |
if(location[i].x < _minx){ | |
location[i].x = _minx; | |
velocity[i].x *= -1; | |
} | |
if(location[i].y > _maxy){ | |
location[i].y = _maxy; | |
velocity[i].y *= -1; | |
} | |
if(location[i].y < _miny){ | |
location[i].y = _miny; | |
velocity[i].y *= -1; | |
} | |
if(location[i].z > _maxz){ | |
location[i].z = _maxz; | |
velocity[i].z *= -1; | |
} | |
if(location[i].z < _minz){ | |
location[i].z = _minz; | |
velocity[i].z *= -1; | |
} | |
} | |
noFill(); | |
beginShape(); | |
for(int i = 0; i < _particlenum; i++){ | |
curveVertex(location[i].x, location[i].y, location[i].z); | |
if(i % 19 == 0){ | |
endShape(); | |
beginShape(); | |
} | |
} | |
endShape(); | |
} | |
void mousePressed(){ | |
saveFrame("output/letgo" + _y + _mo + _d + _h + _mi + _s + "##########.jpg"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment