Created
October 18, 2012 19:44
-
-
Save resophonic/3914364 to your computer and use it in GitHub Desktop.
cluster_v1
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.*; | |
// ranges for x/y positions of points | |
FloatRange xpos, ypos; | |
// helper class for rendering | |
ToxiclibsSupport gfx; | |
// empty voronoi mesh container | |
Voronoi voronoi = new Voronoi(); | |
// optional polygon clipper | |
PolygonClipper2D clip; | |
// switches | |
boolean doShowPoints = true; | |
boolean doShowDelaunay; | |
boolean doShowHelp=true; | |
boolean doClip; | |
boolean doSave; | |
void setup() { | |
size(800, 800); | |
smooth(); | |
xpos=new BiasedFloatRange(0, width, width/2, 0.1f); | |
ypos=new BiasedFloatRange(0, height, height/2, 0.1f); | |
} | |
void draw() { | |
background(255); | |
stroke(0); | |
noFill(); | |
if (doShowPoints) { | |
fill(0); | |
noStroke(); | |
for (Vec2D c : voronoi.getSites()) { | |
ellipse(c.x, c.y, 5, 5); | |
} | |
} | |
} | |
void keyPressed() { | |
switch(key) { | |
case 'r': | |
for (int i = 0; i < 10; i++) { | |
voronoi.addPoint(new Vec2D(xpos.pickRandom(), ypos.pickRandom())); | |
} | |
break; | |
} | |
} | |
void mousePressed() { | |
voronoi.addPoint(new Vec2D(mouseX, mouseY)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment