Skip to content

Instantly share code, notes, and snippets.

@resophonic
Created October 18, 2012 19:44
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 resophonic/3914364 to your computer and use it in GitHub Desktop.
Save resophonic/3914364 to your computer and use it in GitHub Desktop.
cluster_v1
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