Skip to content

Instantly share code, notes, and snippets.

@Blizzardo1
Created January 10, 2017 09:06
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 Blizzardo1/620cb96f39a8db1d2a04a1b017a47bb9 to your computer and use it in GitHub Desktop.
Save Blizzardo1/620cb96f39a8db1d2a04a1b017a47bb9 to your computer and use it in GitHub Desktop.
// Daniel Shiffman
// http://codingrainbow.com
// http://patreon.com/codingrainbow
// Code for: https://youtu.be/QHEQuoIKgNE
// Adonis Deliannis (Blizzardo1)
// Added modification to create colour scheme.
class Circle {
float x;
float y;
float r;
boolean growing = true;
int _r,_g,_b,rr;
Circle (float x_, float y_) {
this(x_, y_, 255,255,255);
}
Circle(float x_, float y_, int red, int green, int blue) {
x = x_;
y = y_;
r = 1;
if(red > 255) _r = 255; else _r = red;
if(green > 255) _g = 255; else _g = green;
if(blue > 255) _b = 255; else _b = blue;
rr = int(random(0,16));
}
void grow() {
if (growing) {
r = r + 0.5;
}
}
boolean edges() {
return (x + r > width || x - r < 0 || y + r > height || y -r < 0);
}
void show() {
//stroke(_r, _g, _b);
stroke(colClamp(x), colClamp(y * 2), colClamp(r * 2));
strokeWeight(2);
noFill();
ellipse(x, y, r*2, r*2);
}
int colClamp(float val) {
return clamp(0,255,int(val));
}
int clamp(int min, int max, int val) {
return ((val < min) ? min : ((val > max) ? max : val));
}
}
// Daniel Shiffman
// http://codingrainbow.com
// http://patreon.com/codingrainbow
// Code for: https://youtu.be/QHEQuoIKgNE
// Adonis Deliannis (Blizzardo1)
// Added modification to create colour scheme.
ArrayList<Circle> circles;
ArrayList<PVector> spots;
PImage img;
int _r = 0;
int _g = 0;
int _b = 0;
void setup() {
size(900, 400);
spots = new ArrayList<PVector>();
img = loadImage("2017.png");
img.loadPixels();
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++) {
int index = x + y * img.width;
color c = img.pixels[index];
float b = brightness(c);
if (b > 1) {
spots.add(new PVector(x,y));
}
}
}
circles = new ArrayList<Circle>();
}
void draw() {
background(0);
int total = 10;
int count = 0;
int attempts = 0;
while (count < total) {
Circle newC = newCircle();
if (newC != null) {
circles.add(newC);
count++;
}
attempts++;
if (attempts > 1000) {
noLoop();
println("FINISHED");
break;
}
}
for (Circle c : circles) {
if (c.growing) {
if (c.edges()) {
c.growing = false;
} else {
for (Circle other : circles) {
if (c != other) {
float d = dist(c.x, c.y, other.x, other.y);
if (d - 2 < c.r + other.r) {
c.growing = false;
break;
}
}
}
}
}
c.show();
c.grow();
}
}
Circle newCircle() {
int r = int(random(0,spots.size()));
_r = int(random(0,255));
_g = int(random(0,255));
_b = int(random(0,255));
PVector spot = spots.get(r);
float x = spot.x;
float y = spot.y;
boolean valid = true;
for (Circle c : circles) {
float d = dist(x, y, c.x, c.y);
if (d < c.r) {
valid = false;
break;
}
}
if (valid) {
return new Circle(x, y, _r, _g, _b);
} else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment