Skip to content

Commit

Permalink
Voronoi
Browse files Browse the repository at this point in the history
Just played around with a basic voronoi regions (flat colors instead of
calculating color based on distance to center of region). I love the
shapes created by voronoi regions.
  • Loading branch information
James Lawrence Turner committed Feb 3, 2015
1 parent c2e916b commit 301c8ff
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 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 [Mon Feb 2, 2015]
![Voronoi](/voronoi/output.png?raw=true)

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

Expand Down
Binary file added voronoi/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/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/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/voronoi.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class Region {
float x, y, colorNumber;
Region(float x, float y) {
this.x = x;
this.y = y;
this.colorNumber = noise(x, y);
}
float distanceTo(float x, float y){
return sqrt(sq(this.x - x) + sq(this.y - y));
}
}

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 = Float.MAX_VALUE;
Region closestRegion = null;
for(Region r : regions) {
float distance = r.distanceTo(x,y);
if(distance < distanceToClosestRegion) {
closestRegion = r;
distanceToClosestRegion = distance;
}
}
c = color(map(closestRegion.colorNumber, 0.0, 1.0, 150, 0));
if(logoMask.pixels[y * width + x] == color(255)) {
int variance = round(map(closestRegion.colorNumber, 0.0, 1.0, 0, 150));
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 301c8ff

Please sign in to comment.