Skip to content

Instantly share code, notes, and snippets.

@hidex7777
Created February 26, 2018 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidex7777/bf50a0d75796f8fb21dcfdc1171e5e48 to your computer and use it in GitHub Desktop.
Save hidex7777/bf50a0d75796f8fb21dcfdc1171e5e48 to your computer and use it in GitHub Desktop.
Haze 26B for Processing
//Haze26B
//date
PImage _img;
int _y = year();
int _mo = month();
int _d = day();
int _h = hour();
int _mi = minute();
int _s = second();
int _gap = 5;
int _maxr = 50;
int _minr = 40;
color[] colors = {};
float[] rs = {};
ArrayList<Bubble> bubbles = new ArrayList<Bubble>();
void setup(){
size(850, 850);
_img = loadImage("source.jpg");
_img.resize(width, height);
_img.loadPixels();
frameRate(240);
background(0);
getColor();
}
void draw(){
int i = round(random(bubbles.size() - 1));
Bubble bs = bubbles.get(i);
bs.updateMe();
bs.drawMe();
}
void mousePressed(){
saveFrame("output/haze26B" + _y + "_" + _mo + "_" + _d + "_" + _h + "_" + _mi + "_" + _s + "_" + "#######.jpg");
}
void getColor(){
for(int y = 0; y < _img.height; y += _gap){
for(int x = 0; x < _img.width; x += _gap){
int loc = x + (y * _img.height);
color c = _img.pixels[loc];
//float r = map(brightness(_img.pixels[loc]), 0.0, 255.0, _minr, _maxr);
bubbles.add(new Bubble(x, y, c));
}
}
}
class Bubble{
PVector location;
float myr;
color myc;
boolean wasBorn;
boolean hasStopped;
float acceleration;
Bubble(float x, float y, color c){
location = new PVector(x, y);
myr = 0;
myc = c;
wasBorn = false;
hasStopped = false;
acceleration = random(4, 40);
}
void updateMe(){
acceleration *= 0.5;
if(!hasStopped){
myr += acceleration;
for(Bubble bs: bubbles){
if(bs.wasBorn == true){
float d = dist(this.location.x, this.location.y, bs.location.x, bs.location.y) - this.myr - bs.myr;
if((d < 2) && (bs != this)){
hasStopped = true;
}
}
}
}
}
void drawMe(){
if(!hasStopped){
wasBorn = true;
pushMatrix();
translate(this.location.x, this.location.y);
noStroke();
fill(myc);
ellipse(0, 0, myr * 2, myr * 2);
popMatrix();
}
if(!wasBorn){
acceleration = random(4, 30);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment