Created
March 3, 2018 17:35
-
-
Save hidex7777/b1f16d9dc2cbd22131ec5ee22a5fd56e to your computer and use it in GitHub Desktop.
Haze 03C 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
//Haze03C | |
//date | |
int _y = year(); | |
int _mo = month(); | |
int _d = day(); | |
int _h = hour(); | |
int _mi = minute(); | |
int _s = second(); | |
PImage _img; | |
int _NUM = 3000; | |
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.01;//0.01 | |
float _noiseStrength = 0.1;//0.1 | |
void setup(){ | |
size(1000, 1000, 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], 3);//a = 3 | |
force[i].x = cos(noise(location[i].x * _noiseScale, location[i].y * _noiseScale, location[i].z * _noiseScale) * TWO_PI * 2.0); | |
force[i].y = sin(noise(location[i].x * _noiseScale, location[i].y * _noiseScale, location[i].z * _noiseScale) * TWO_PI * 2.0); | |
force[i].z = cos(noise(location[i].x * _noiseScale, location[i].y * _noiseScale, location[i].z * _noiseScale) * TWO_PI * 2.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/haze03C" + _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; | |
} | |
void setColorlp(int i){ | |
//Light+ | |
int c = round(random(11)); | |
switch(c){ | |
case 0: | |
colors[i] = color(241, 152, 150); | |
break; | |
case 1: | |
colors[i] = color(255, 167, 135); | |
break; | |
case 2: | |
colors[i] = color(255, 190, 113); | |
break; | |
case 3: | |
colors[i] = color(242, 217, 110); | |
break; | |
case 4: | |
colors[i] = color(199, 211, 109); | |
break; | |
case 5: | |
colors[i] = color(133, 206, 158); | |
break; | |
case 6: | |
colors[i] = color(98, 192, 181); | |
break; | |
case 7: | |
colors[i] = color(91, 175, 196); | |
break; | |
case 8: | |
colors[i] = color(108, 154, 197); | |
break; | |
case 9: | |
colors[i] = color(144, 145, 195); | |
break; | |
case 10: | |
colors[i] = color(176, 136, 181); | |
break; | |
case 11: | |
colors[i] = color(217, 142, 165); | |
break; | |
} | |
} | |
void setColorv(int i){ | |
//Vivid | |
int c = round(random(23)); | |
switch(c){ | |
case 0: | |
colors[i] = color(173 ,46 ,108); | |
break; | |
case 1: | |
colors[i] = color(185 ,31 ,87); | |
break; | |
case 2: | |
colors[i] = color(208 ,47 ,72); | |
break; | |
case 3: | |
colors[i] = color(221 ,68 ,59); | |
break; | |
case 4: | |
colors[i] = color(233 ,91 ,35); | |
break; | |
case 5: | |
colors[i] = color(230 ,120 ,0); | |
break; | |
case 6: | |
colors[i] = color(244 ,157 ,0); | |
break; | |
case 7: | |
colors[i] = color(241 ,181 ,0); | |
break; | |
case 8: | |
colors[i] = color(238 ,201 ,0); | |
break; | |
case 9: | |
colors[i] = color(210 ,193 ,0); | |
break; | |
case 10: | |
colors[i] = color(168 ,187 ,0); | |
break; | |
case 11: | |
colors[i] = color(88 ,169 ,29); | |
break; | |
case 12: | |
colors[i] = color(0 ,161 ,90); | |
break; | |
case 13: | |
colors[i] = color(0 ,146 ,110); | |
break; | |
case 14: | |
colors[i] = color(0 ,133 ,127); | |
break; | |
case 15: | |
colors[i] = color(0 ,116 ,136); | |
break; | |
case 16: | |
colors[i] = color(0 ,112 ,155); | |
break; | |
case 17: | |
colors[i] = color(0 ,96 ,156); | |
break; | |
case 18: | |
colors[i] = color(0 ,91 ,165); | |
break; | |
case 19: | |
colors[i] = color(26 ,84 ,165); | |
break; | |
case 20: | |
colors[i] = color(83 ,74 ,160); | |
break; | |
case 21: | |
colors[i] = color(112 ,63 ,150); | |
break; | |
case 22: | |
colors[i] = color(129 ,55 ,138); | |
break; | |
case 23: | |
colors[i] = color(143 ,46 ,124); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment