Created
July 22, 2013 14:23
-
-
Save gwygonik/6054197 to your computer and use it in GitHub Desktop.
Voronoi Tread Image - Processing script that drives across the middle of an image, sampling colors and displaying data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import toxi.geom.*; | |
import toxi.geom.mesh2d.*; | |
import toxi.util.*; | |
import toxi.util.datatypes.*; | |
import toxi.processing.*; | |
Voronoi vo = new Voronoi(); | |
ToxiclibsSupport gfx; | |
PImage cm = new PImage(1280,720); | |
PImage pic; | |
void setup() { | |
size(1280, 720); | |
gfx = new ToxiclibsSupport(this); | |
// load pic here | |
// pic = loadImage("IMG_6319.jpg"); | |
background(0); | |
for (int i=0;i<width;i+=width/14) { | |
vo.addPoint(new Vec2D(i,0)); | |
vo.addPoint(new Vec2D(i,height/2-50)); | |
vo.addPoint(new Vec2D(i,height/2-100)); | |
} | |
for (int i=0;i<width;i+=width/13) { | |
vo.addPoint(new Vec2D(i,height/2+100)); | |
vo.addPoint(new Vec2D(i,height/2+50)); | |
vo.addPoint(new Vec2D(i,height)); | |
} | |
cm.copy(pic,0,0,pic.width,pic.height,0,0,1280,720); | |
image(cm,0,0,1280,720); | |
stroke(200); | |
strokeWeight(2); | |
noFill(); | |
int c= 0; | |
for (Polygon2D poly : vo.getRegions()) { | |
Vec2D cn = poly.getCentroid(); | |
fill(cm.get((int)cn.x,(int)cn.y)); | |
gfx.polygon2D(poly); | |
fill(255); | |
text(""+c,cn.x-4,cn.y); | |
text("#"+hex(cm.get((int)cn.x,(int)cn.y),6),cn.x-28,cn.y+16); | |
c++; | |
} | |
noFill(); | |
stroke(255, 50); | |
beginShape(TRIANGLES); | |
for (Triangle2D t : vo.getTriangles()) { | |
Vec2D cn = t.computeCentroid(); | |
gfx.triangle(t, false); | |
} | |
endShape(); | |
save("render.png"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment