Skip to content

Commit

Permalink
Voronoi Germs
Browse files Browse the repository at this point in the history
Playing with voronoi regions rendering at a per pixel level. When
scaling up I forgot to scale up the region rendering map, and the
regions stayed small. Kind of like how they clustered, looks like germs.

Also last commit of Grain Waterfall did not include the final source.
  • Loading branch information
James Lawrence Turner committed Feb 2, 2015
1 parent b01c199 commit 77dba51
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#### Copyright James Lawrence Turner, 2015, All Rights Reserved

## Voronoi Germs [Sun Feb 1, 2015]
![Voronoi Germs](/voronoi_germs/output.png?raw=true)

## Grain Waterfalls [Fri Jan 30, 2015]
![Grain Waterfalls](/grain_waterfalls/output.png?raw=true)

Expand Down
20 changes: 14 additions & 6 deletions grain_waterfalls/grain_waterfalls.pde
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PShape logo;
PGraphics logoMask;

void setup() {
size(5000,5000,OPENGL);
size(5000,5000);

logo = loadShape("urx-logo.svg");
logo.disableStyle();
Expand All @@ -39,8 +39,10 @@ void setup() {
}

void draw() {
for(int x = 0; x < width; x++) {
for(int y = 0; y < height; y++) {
PGraphics output = createGraphics(width,height);
output.loadPixels();
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
color c;
float distanceToClosestRegion = width;
for(Region r : regions) {
Expand All @@ -49,9 +51,15 @@ void draw() {
distanceToClosestRegion = distance;
}
}
c = color(map(distanceToClosestRegion, 0, 100, 0, 255));
set(x, y, c);
c = color(map(distanceToClosestRegion, 0, 50, 150, 0));
if(logoMask.pixels[y * width + x] == color(255)) {
int variance = round(map(distanceToClosestRegion, 0, 50, 0, 150));
c = color(variance, 120 + variance, 200 + variance);
}
output.pixels[y * width + x] = c;
}
println(y);
}
save("output.png");
output.updatePixels();
output.save("output.png");
}
Binary file modified grain_waterfalls/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grain_waterfalls/output2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added voronoi_germs/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions voronoi_germs/sketch.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mode.id=processing.mode.java.JavaMode
mode=Java
20 changes: 20 additions & 0 deletions voronoi_germs/urx-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions voronoi_germs/voronoi_germs.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class Region {
float x, y;
Region(float x, float y) {
this.x = x;
this.y = y;
}
float distanceTo(float x, float y){
// Use cheaper manhattan distance calculation
return sqrt(sq(this.x - x) + sq(this.y - y));
//return abs(this.x - x) + abs(this.y - y);
//return sqrt(pow((this.x - x) + (this.y - y),2));
}
}

ArrayList<Region> regions;
PShape logo;
PGraphics logoMask;

void setup() {
size(5000,5000);

logo = loadShape("urx-logo.svg");
logo.disableStyle();
logo.scale(width / logo.width);

logoMask = createGraphics(width, height);
logoMask.beginDraw();
logoMask.background(0);
logoMask.translate(width / 8, height/4 + height / 16);
logoMask.scale(0.75);
logoMask.fill(255);
logoMask.shape(logo);
logoMask.endDraw();

smooth();
background(color(255));
regions = new ArrayList<Region>();
for(int i = 0; i < 500; i++) {
regions.add(new Region(random(width), random(height)));
}
noLoop();
}

void draw() {
PGraphics output = createGraphics(width,height);
output.loadPixels();
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
color c;
float distanceToClosestRegion = width;
for(Region r : regions) {
float distance = r.distanceTo(x,y);
if(distance < distanceToClosestRegion) {
distanceToClosestRegion = distance;
}
}
c = color(map(distanceToClosestRegion, 0, 120, 150, 0));
if(logoMask.pixels[y * width + x] == color(255)) {
int variance = round(map(distanceToClosestRegion, 0, 120, 150, -50));
c = color(variance, 120 + variance, 200 + variance);
}
output.pixels[y * width + x] = c;
}
println(y);
}
output.updatePixels();
output.save("output.png");
}

0 comments on commit 77dba51

Please sign in to comment.