/** * Translate in X and Y. */ public void translate(float tx, float ty) { g.translate(tx, ty); }
/** * Translate in X, Y, and Z. */ public void translate(float tx, float ty, float tz) { g.translate(tx, ty, tz); }
/** * @param z z-coordinate of text */ public void text(char c, float x, float y, float z) { // if ((z != 0) && (textMode == SCREEN)) { // String msg = "textMode(SCREEN) cannot have a z coordinate"; // throw new RuntimeException(msg); // } if (z != 0) translate(0, 0, z); // slowness, badness text(c, x, y); // textZ = z; if (z != 0) translate(0, 0, -z); }
/** * Draw a single character on screen (with a z coordinate) */ public void text(char c, float x, float y, float z) { // if ((z != 0) && (textMode == SCREEN)) { // String msg = "textMode(SCREEN) cannot have a z coordinate"; // throw new RuntimeException(msg); // } if (z != 0) translate(0, 0, z); // slowness, badness text(c, x, y); // textZ = z; if (z != 0) translate(0, 0, -z); }
/** * Same as above but with a z coordinate. */ public void text(String str, float x, float y, float z) { // if ((z != 0) && (textMode == SCREEN)) { // String msg = "textMode(SCREEN) cannot have a z coordinate"; // throw new RuntimeException(msg); // } if (z != 0) translate(0, 0, z); // slow! text(str, x, y); // textZ = z; if (z != 0) translate(0, 0, -z); }
public void drawString(PGraphics g, String str, float x, float y, float size) { // 1) scale by the 1.0/unitsPerEm // 2) scale up by a font size g.pushMatrix(); float s = size / face.unitsPerEm; //System.out.println("scale is " + s); // swap y coord at the same time, since fonts have y=0 at baseline g.translate(x, y); g.scale(s, -s); char[] c = str.toCharArray(); for (int i = 0; i < c.length; i++) { // call draw on each char (pulling it w/ the unicode table) FontGlyph fg = unicodeGlyphs.get(Character.valueOf(c[i])); if (fg != null) { fg.draw(g); // add horizAdvX/unitsPerEm to the x coordinate along the way g.translate(fg.horizAdvX, 0); } else { System.err.println("'" + c[i] + "' not available."); } } g.popMatrix(); }
public void drawString(PGraphics g, String str, float x, float y, float size) { // 1) scale by the 1.0/unitsPerEm // 2) scale up by a font size g.pushMatrix(); float s = size / (float) face.unitsPerEm; //System.out.println("scale is " + s); // swap y coord at the same time, since fonts have y=0 at baseline g.translate(x, y); g.scale(s, -s); char[] c = str.toCharArray(); for (int i = 0; i < c.length; i++) { // call draw on each char (pulling it w/ the unicode table) FontGlyph fg = (FontGlyph) unicodeGlyphs.get(new Character(c[i])); if (fg != null) { fg.draw(g); // add horizAdvX/unitsPerEm to the x coordinate along the way g.translate(fg.horizAdvX, 0); } else { System.err.println("'" + c[i] + "' not available."); } } g.popMatrix(); }
public void drawChar(PGraphics g, char c, float x, float y, float size) { g.pushMatrix(); float s = size / (float) face.unitsPerEm; g.translate(x, y); g.scale(s, -s); FontGlyph fg = (FontGlyph) unicodeGlyphs.get(new Character(c)); if (fg != null) g.shape(fg); g.popMatrix(); }
public void drawChar(PGraphics g, char c, float x, float y, float size) { g.pushMatrix(); float s = size / face.unitsPerEm; g.translate(x, y); g.scale(s, -s); FontGlyph fg = unicodeGlyphs.get(Character.valueOf(c)); if (fg != null) g.shape(fg); g.popMatrix(); }
/** * Convenience method to draw at a particular location. */ public void shape(PShape shape, float x, float y) { if (shape.isVisible()) { // don't do expensive matrix ops if invisible pushMatrix(); if (shapeMode == CENTER) { translate(x - shape.getWidth()/2, y - shape.getHeight()/2); } else if ((shapeMode == CORNER) || (shapeMode == CORNERS)) { translate(x, y); } shape.draw(this); popMatrix(); } }
public void shape(PShape shape, float x, float y, float c, float d) { if (shape.isVisible()) { // don't do expensive matrix ops if invisible pushMatrix(); if (shapeMode == CENTER) { // x and y are center, c and d refer to a diameter translate(x - c/2f, y - d/2f); scale(c / shape.getWidth(), d / shape.getHeight()); } else if (shapeMode == CORNER) { translate(x, y); scale(c / shape.getWidth(), d / shape.getHeight()); } else if (shapeMode == CORNERS) { // c and d are x2/y2, make them into width/height c -= x; d -= y; // then same as above translate(x, y); scale(c / shape.getWidth(), d / shape.getHeight()); } shape.draw(this); popMatrix(); } }
public void shape(PShape shape) { if (shape.isVisible()) { // don't do expensive matrix ops if invisible if (shapeMode == CENTER) { pushMatrix(); translate(-shape.getWidth()/2, -shape.getHeight()/2); } shape.draw(this); // needs to handle recorder too if (shapeMode == CENTER) { popMatrix(); } } }
PGraphics pg; void setup() { size(200, 200, P2D); pg = createGraphics(100, 100, P3D); } void draw() { pg.beginDraw(); pg.background(0); pg.noStroke(); pg.translate(pg.width*0.5, pg.height*0.5); pg.lights(); pg.sphere(25); pg.endDraw(); background(0, 0, 255); image(pg, 50, 50); }
/** * @param a x-coordinate of the shape * @param b y-coordinate of the shape * @param c width to display the shape * @param d height to display the shape */ public void shape(PShape shape, float a, float b, float c, float d) { if (shape.isVisible()) { // don't do expensive matrix ops if invisible flush(); pushMatrix(); if (shapeMode == CENTER) { // x and y are center, c and d refer to a diameter translate(a - c/2f, b - d/2f); scale(c / shape.getWidth(), d / shape.getHeight()); } else if (shapeMode == CORNER) { translate(a, b); scale(c / shape.getWidth(), d / shape.getHeight()); } else if (shapeMode == CORNERS) { // c and d are x2/y2, make them into width/height c -= a; d -= b; // then same as above translate(a, b); scale(c / shape.getWidth(), d / shape.getHeight()); } shape.draw(this); popMatrix(); } }
public void shape(PShape shape) { if (shape.isVisible()) { // don't do expensive matrix ops if invisible // Flushing any remaining geometry generated in the immediate mode // to avoid depth-sorting issues. flush(); if (shapeMode == CENTER) { pushMatrix(); translate(-shape.getWidth()/2, -shape.getHeight()/2); } shape.draw(this); // needs to handle recorder too if (shapeMode == CENTER) { popMatrix(); } } }
PGraphics p; void setup(){ size(400,400,P3D); p = createGraphics(400,400,P3D); smooth(); stroke(180,90,210); } void draw(){ background(180,90,210); p.beginDraw(); p.background(220, 180, 40,0); p.noFill(); p.stroke(220, 180, 40); p.translate(width/2 - (width/2 - mouseX), height/2, 400-mouseY*5); p.sphere(100); p.endDraw(); pushMatrix(); translate(width/2, height/2, -200); rotateY(radians(frameCount)); rotateX(radians(frameCount/2)); box(100); popMatrix(); image(p,0,0); }
pg.noSmooth(); pg.clear(); pg.translate (width/2+100, height/2); pg.rotate (PI/6); pg.stroke(255);