Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Redraw PGraphics object

$
0
0

I got this simple voronoi sketch below. I can draw this Voronoi into an graphics object with the getGraphics() method in the ToxiclibsSupport class. But when i press the mouse and are updating the voronoi only the background updates. Not the PGraphics object.

How do I get the PGraphics-object to redraw?

import toxi.geom.*;
import toxi.geom.mesh2d.*;
import toxi.processing.*;

ToxiclibsSupport gfx;
Voronoi v;
PGraphics pg;

void setup() {
  size( 500, 500 );
  gfx = new ToxiclibsSupport( this );
  pg = createGraphics(width, height);

  drawVoronoi();
}

void drawVoronoi() {
  v = new Voronoi();
  for ( int i = 0; i < 150; i++ ) {
    v.addPoint( new Vec2D( random(width), random(height) ) );
  }

  for (int i = 0; i < v.getRegions().size(); i++) {
    Polygon2D p = v.getRegions().get(i);
    fill(random(255));
    gfx.polygon2D(p);
  }
}

void draw() {
  pg = gfx.getGraphics();
  image(pg, mouseX, mouseY, 200, 200);
}

void mousePressed() {
  drawVoronoi();
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles