Skip to content

Instantly share code, notes, and snippets.

@hidex7777
Created February 18, 2018 20:56
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/47398e200303989d4477325ec513fd6a to your computer and use it in GitHub Desktop.
Save hidex7777/47398e200303989d4477325ec513fd6a to your computer and use it in GitHub Desktop.
Haze 18B for Processing
//Haze18B
//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(120);
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/haze18B" + _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, r, c));
}
}
}
class Bubble{
PVector location;
float myr;
float tempr;
color myc;
boolean wasBorn;
boolean hasStopped;
boolean expanding;
float acceleration;
Bubble(float x, float y, float r, color c){
location = new PVector(x, y);
myr = r;
tempr = 0;
myc = c;
wasBorn = false;
hasStopped = false;
acceleration = random(2, 14);
}
void updateMe(){
acceleration *= 0.8;
if(!hasStopped){
tempr += acceleration;
if(tempr >= myr){
tempr = myr;
}
for(Bubble bs: bubbles){
if(bs.wasBorn == true){
float d = dist(this.location.x, this.location.y, bs.location.x, bs.location.y) - this.tempr - bs.tempr;
if((d < -1) && (bs != this)){
hasStopped = true;
}
}
}
}
}
void drawMe(){
if(!hasStopped){
wasBorn = true;
pushMatrix();
translate(this.location.x, this.location.y);
noStroke();
fill(myc);
ellipse(0, 0, tempr * 2, tempr * 2);
popMatrix();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment