/** Draw the shape into an arbitrary PGraphics. */ void draw(PGraphics pg) { if (iFrame.isEyeFrame()) return; if (shift != null) if (pg.is3D()) pg.translate(shift.x(), shift.y(), shift.z()); else pg.translate(shift.x(), shift.y()); // The shape part took verbatim from Processing, see: // https://github.com/processing/processing/blob/master/core/src/processing/core/PGraphics.java if (shp != null) { // don't do expensive matrix ops if invisible if (shp.isVisible() && !iFrame.isEyeFrame()) { pg.flush(); if (pg.shapeMode == PApplet.CENTER) { pg.pushMatrix(); pg.translate(-shp.getWidth() / 2, -shp.getHeight() / 2); } shp.draw(pg); // needs to handle recorder too if (pg.shapeMode == PApplet.CENTER) { pg.popMatrix(); } } } else if (mth != null && obj != null) { try { mth.invoke(obj, new Object[] {pg}); } catch (Exception e1) { try { mth.invoke(obj, new Object[] {iFrame, pg}); } catch (Exception e2) { PApplet.println("Something went wrong when invoking your " + mth.getName() + " method"); } } } }