Code<\/strong>, as below: <\/p>\n\/\/references:\r\n\/\/http:\/\/www.processing.org\/tutorials\/pixels\/\r\n\/\/http:\/\/robbietilton.com\/blog\/?p=607\r\n\/\/http:\/\/vormplus.be\/blog\/article\/voronoi-paintings-with-toxiclibs\r\n\r\nimport toxi.geom.*;\r\nimport toxi.geom.mesh2d.*; \r\nimport toxi.util.*;\r\nimport toxi.util.datatypes.*; \r\nimport toxi.processing.*;\r\nimport processing.video.*;\r\n\r\nCapture video;\r\nfloat size = 10000;\r\nVoronoi voronoi;\r\nPImage source;\r\n\r\nint pointDensity = 70;\r\nint cols, rows;\r\nint x, y;\r\nint numPixels;\r\nfloat colorThreshold = 30;\r\n\r\nvoid setup() {\r\n size(640,480);\r\n \/\/size(source.width, source.height);\r\n video = new Capture(this, width, height);\r\n video.start();\r\n\r\n \/\/source = loadImage("test.png");\r\n source = createImage(640,480,RGB);\r\n smooth();\r\n\r\n cols = width\/pointDensity;\r\n rows = height\/pointDensity;\r\n numPixels = source.width * source.height;\r\n\r\n voronoi = new Voronoi(size);\r\n\r\n}\r\n\r\nvoid addPoint() {\r\n source.copy(video,0,0,640,480,0,0,640,480);\r\n source.updatePixels();\r\n\r\n for (x=1; x<source.width; x+=cols) {\r\n for (y=1; y<source.height; y+=rows) { int loc = x + y*source.width; color pix = source.pixels[loc]; int leftLoc = (x-1) + (y-1)*source.width; color leftPix = source.pixels[leftLoc]; \/\/ compare ver: color float r1 = red(pix); float g1 = green(pix); float b1 = blue(pix); float r2 = red(leftPix); float g2 = green(leftPix); float b2 = blue(leftPix); float diff = dist(r1,g1,b1,r2,g2,b2); \/\/ compare ver: brightness \/\/ float diff = abs(brightness(pix)-brightness(leftPix)); if (diff > colorThreshold) {\r\n\/\/ voronoi.addPoint(new Vec2D(x+random(-2, 2), y+random(-2, 2)));\r\n voronoi.addPoint(new Vec2D(x, y));\r\n }\r\n }\r\n }\r\n} \r\n\r\nvoid drawTriangle(){\r\n\r\n for (Triangle2D t : voronoi.getTriangles()) {\r\n color pix;\r\n\r\n \/\/ use Centroid's color\r\n Vec2D locVec = t.computeCentroid();\r\n int loc = (int)((locVec.x) + (locVec.y)*source.width);\r\n\r\n pix = source.pixels[constrain(loc,0,numPixels-1)];\r\n\/\/ stroke(pix,100);\r\n fill(pix);\r\n\/\/ noFill();\r\n noStroke();\r\n\r\n beginShape(TRIANGLES);\r\n stroke(pix);\r\n\/\/ strokeWeight(.1);\r\n vertex(t.a.x, t.a.y);\r\n vertex(t.b.x, t.b.y);\r\n vertex(t.c.x, t.c.y);\r\n endShape(); \r\n }\r\n}\r\n\r\nvoid draw() {\r\n background(255);\r\n video.read();\r\n \/\/image(video,0,0);\r\n\r\n if(showImg) {\r\n image(source, 0, 0);\r\n } else {\r\n addPoint(); \r\n drawTriangle();\r\n }\r\n\r\n fill(0); \r\n rect(15,5,30,20);\r\n\r\n \/\/ show frame rate\r\n fill(255);\r\n text(int(frameRate), 20, 20);\r\n\r\n updatePixels();\r\n\r\n if (frameCount%10 == 0)\r\n voronoi = new Voronoi(size);\r\n\r\n}\r\n\r\nboolean showImg = false;\r\nboolean saveImg = false;\r\n\r\nvoid keyPressed() {\r\n if(key == 'i')\r\n showImg = !showImg;\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"Triangulation.. Finally! Want it so bad for a semester. Luckily having a winter break to do it. Have a lot of rooms for improvement but still, one step further! *UPDATE*(in… Read The Rest →<\/a><\/p>\n","protected":false},"author":1,"featured_media":712,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[127,2],"tags":[30,24,99,98,261],"_links":{"self":[{"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/posts\/677"}],"collection":[{"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/comments?post=677"}],"version-history":[{"count":10,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/posts\/677\/revisions"}],"predecessor-version":[{"id":919,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/posts\/677\/revisions\/919"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/media\/712"}],"wp:attachment":[{"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/media?parent=677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/categories?post=677"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/tags?post=677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}