Created
March 7, 2018 19:07
-
-
Save hidex7777/f02991d42527510ef654109ee3f29dc4 to your computer and use it in GitHub Desktop.
Haze 07C for Processing
This file contains hidden or 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
//Haze07C | |
//date | |
int _y = year(); | |
int _mo = month(); | |
int _d = day(); | |
int _h = hour(); | |
int _mi = minute(); | |
int _s = second(); | |
PImage _img; | |
int _NUM = 4000; | |
PVector[] location = new PVector[_NUM]; | |
PVector[] velocity = new PVector[_NUM]; | |
PVector[] acceleration = new PVector[_NUM]; | |
PVector[] force = new PVector[_NUM]; | |
color[] colors = new color[_NUM]; | |
float _radius = 1.0; | |
float _friction = 0.1; | |
PVector _minloc; | |
PVector _maxloc; | |
float _noiseScale = 0.02;//0.01 | |
float _noiseStrength = 0.1;//0.1 | |
void setup(){ | |
size(800, 800, P3D); | |
smooth(); | |
_img = loadImage("source.jpg"); | |
_img.resize(width, height); | |
_img.loadPixels(); | |
_minloc = new PVector(0, 0, height * -0.4); | |
_maxloc = new PVector(width, height, height * 0.4); | |
frameRate(60); | |
for(int i = 0; i < _NUM; i++){ | |
location[i] = new PVector(random(width), random(height), random(height * -0.4, height * 0.4)); | |
velocity[i] = new PVector(0, 0, 0); | |
acceleration[i] = new PVector(0, 0, 0); | |
force[i] = new PVector(0, 0, 0); | |
setColor(location[i], i); | |
} | |
background(255); | |
} | |
void draw(){ | |
noStroke(); | |
for(int i = 0; i < _NUM; i++){ | |
fill(colors[i], 6);//a = 3 | |
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); | |
pushMatrix(); | |
translate(location[i].x, location[i].y, location[i].z); | |
ellipse(0, 0, _radius * 2, _radius * 2); | |
popMatrix(); | |
if(location[i].x < _minloc.x){ | |
location[i].x = _maxloc.x; | |
} | |
if(location[i].y < _minloc.y){ | |
location[i].y = _maxloc.y; | |
} | |
if(location[i].z < _minloc.z){ | |
location[i].z = _maxloc.z; | |
} | |
if(location[i].x > _maxloc.x){ | |
location[i].x = _minloc.x; | |
} | |
if(location[i].y > _maxloc.y){ | |
location[i].y = _minloc.y; | |
} | |
if(location[i].z > _maxloc.z){ | |
location[i].z = _minloc.z; | |
} | |
} | |
} | |
void mousePressed(){ | |
if (mouseButton == RIGHT){ | |
noiseSeed(round(random(1000))); | |
for(int i = 0; i < _NUM; i++){ | |
location[i].set(random(width), random(height), random(height * -0.4, height * 0.4)); | |
velocity[i].set(0, 0, 0); | |
force[i].set(0, 0); | |
acceleration[i].set(0, 0, 0); | |
} | |
//background(255); | |
}else if(mouseButton == LEFT){ | |
saveFrame("output/haze07C" + _y + _mo + _d + _h + _mi + _s + "#######.jpg"); | |
}else{ | |
background(0); | |
} | |
} | |
void setColor(PVector loc, int i){ | |
int x = (int)loc.x; | |
int y = (int)loc.y; | |
int pickup = x + (y * _img.height); | |
color c = _img.pixels[pickup]; | |
colors[i] = c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment