PShape createFrame(PImage photo) { PShape face = createShape(); face.beginShape(QUAD); face.noStroke(); //face.stroke(0); face.textureMode(NORMAL); face.texture(photo); face.vertex(-1, -1, 0, 0, 0); face.vertex(1, -1, 0, 1, 0); face.vertex(1, 1, 0, 1, 1); face.vertex(-1, 1, 0, 0, 1); face.endShape(); return face; }
static protected void copyGroup(PApplet parent, PShape src, PShape dest) { copyMatrix(src, dest); copyStyles(src, dest); copyImage(src, dest); for (int i = 0; i < src.childCount; i++) { PShape c = PShape.createShape(parent, src.children[i]); dest.addChild(c); } }
static protected void copyMatrix(PShape src, PShape dest) { if (src.matrix != null) { dest.applyMatrix(src.matrix); } }
static protected void copyGeometry(PShape src, PShape dest) { dest.beginShape(src.getKind()); copyMatrix(src, dest); copyStyles(src, dest); copyImage(src, dest); dest.fill((int)(vert[PGraphics.A] * 255) << 24 | (int)(vert[PGraphics.R] * 255) << 16 | (int)(vert[PGraphics.G] * 255) << 8 | vert[PGraphics.NY], vert[PGraphics.NZ], 0, 0, 0)) { dest.normal(vert[PGraphics.NX], vert[PGraphics.NY], vert[PGraphics.NZ]); dest.vertex(vert[X], vert[Y], vert[Z], vert[PGraphics.U], vert[PGraphics.V]); float[] vert = src.vertices[i]; if (vert[Z] == 0) { dest.vertex(vert[X], vert[Y]); } else { dest.vertex(vert[X], vert[Y], vert[Z]); dest.endShape();
tess.set3D(is3D); // if this is a 3D shape, make the new shape 3D as well tess.beginShape(TRIANGLES); tess.noStroke(); tess.fill(argb0); tess.normal(nx0, ny0, nz0); tess.vertex(x0, y0, z0, uv[2 * i0 + 0], uv[2 * i0 + 1]); tess.fill(argb1); tess.normal(nx1, ny1, nz1); tess.vertex(x1, y1, z1, uv[2 * i1 + 0], uv[2 * i1 + 1]); tess.fill(argb2); tess.normal(nx2, ny2, nz2); tess.vertex(x2, y2, z2, uv[2 * i2 + 0], uv[2 * i2 + 1]); } else if (is2D()) { float x0 = vertices[4 * i0 + 0], y0 = vertices[4 * i0 + 1]; tess.fill(argb0); tess.vertex(x0, y0, uv[2 * i0 + 0], uv[2 * i0 + 1]); tess.fill(argb1); tess.vertex(x1, y1, uv[2 * i1 + 0], uv[2 * i1 + 1]); tess.fill(argb2); tess.vertex(x2, y2, uv[2 * i2 + 0], uv[2 * i2 + 1]); tess.endShape();
public static PShapeOpenGL createShape(PGraphicsOpenGL pg, PShape src) { PShapeOpenGL dest = null; if (src.getFamily() == GROUP) { //dest = PGraphics3D.createShapeImpl(pg, GROUP); dest = (PShapeOpenGL) pg.createShapeFamily(GROUP); copyGroup(pg, src, dest); } else if (src.getFamily() == PRIMITIVE) { //dest = PGraphics3D.createShapeImpl(pg, src.getKind(), src.getParams()); dest = (PShapeOpenGL) pg.createShapePrimitive(src.getKind(), src.getParams()); PShape.copyPrimitive(src, dest); } else if (src.getFamily() == GEOMETRY) { //dest = PGraphics3D.createShapeImpl(pg, PShape.GEOMETRY); dest = (PShapeOpenGL) pg.createShapeFamily(PShape.GEOMETRY); PShape.copyGeometry(src, dest); } else if (src.getFamily() == PATH) { dest = (PShapeOpenGL) pg.createShapeFamily(PShape.PATH); //dest = PGraphics3D.createShapeImpl(pg, PATH); PShape.copyPath(src, dest); } dest.setName(src.getName()); dest.width = src.width; dest.height = src.height; dest.depth = src.depth; return dest; }
static public void copyGroup(PGraphicsOpenGL pg, PShape src, PShape dest) { copyMatrix(src, dest); copyStyles(src, dest); copyImage(src, dest); for (int i = 0; i < src.getChildCount(); i++) { PShape c = createShape(pg, src.getChild(i)); dest.addChild(c); } }
PShape s = new PShape(PShape.PATH); s.beginShape(); } else { s.beginContour(); s.vertex(iterPoints[0], iterPoints[1]); break; s.vertex(iterPoints[0], iterPoints[1]); break; s.quadraticVertex(iterPoints[0], iterPoints[1], iterPoints[2], iterPoints[3]); break; s.quadraticVertex(iterPoints[0], iterPoints[1], iterPoints[2], iterPoints[3], iterPoints[4], iterPoints[5]); s.endContour(); s.endShape(CLOSE); return s;
float x = inGeo.vertices[index++]; float y = inGeo.vertices[index ]; super.vertex(x, y); x = inGeo.vertices[v++]; y = inGeo.vertices[v ]; super.vertex(x, y); y3 = inGeo.vertices[v]; super.quadraticVertex(cx, cy, x3, y3); y4 = inGeo.vertices[v ]; super.bezierVertex(x2, y2, x3, y3, x4, y4); y = inGeo.vertices[v ]; super.curveVertex(x, y); super.endContourImpl(); super.beginContourImpl(); insideContour = true; super.endContourImpl();
Table data; PShape dataPlot; size(1620, 1080,P2D); //create a group to store the lines from each row dataPlot = createShape(); //load the data, specifying it has a header and it's tab separated data = loadTable("data.tsv", "header, tsv"); //traverse each row dataPlot.beginShape(LINES); for(TableRow row : data.rows()){ //extract each value int x1 = row.getInt("x1"); int y1 = row.getInt("y1"); int x2 = row.getInt("x2"); int y2 = row.getInt("y2"); //add the coordinates as lines to the group dataPlot.stroke(160); dataPlot.vertex(x1,y1); dataPlot.stroke(0); dataPlot.vertex(x2,y2); } dataPlot.endShape(); //render the plot shape(dataPlot);
Table data; PShape dataPlot; size(1620, 1080, P2D); //create a group to store the lines from each row dataPlot = createShape(GROUP); //load the data, specifying it has a header and it's tab separated data = loadTable("data.tsv", "header, tsv"); //traverse each row for (TableRow row : data.rows ()) { //extract each value int x1 = row.getInt("x1"); int y1 = row.getInt("y1"); int x2 = row.getInt("x2"); int y2 = row.getInt("y2"); //add the coordinates as lines to the group PShape line = createShape(LINE, x1, y1, x2, y2); float dist = dist(x1, y1, x2, y2); line.setStroke(color(map(dist, 0, height, 160, 0))); line.setStrokeWeight(map(dist, 0, height, 10.0, 1.0)); dataPlot.addChild(line); } //render the plot shape(dataPlot);
size(1200, 480,OPENGL);//the catch is, even though we use PMatrix2D, PShape's applyMatrix() only seems to work with the P3D or OpenGL renderer PShape usa = loadShape("usa-wikipedia.svg"); ohio = (PShape)usa.getChild("OH"); ohio.applyMatrix(transform); //apply this transformation matrix to the SVG boolean isOver = ohio.contains(mouseInSVG.x,mouseInSVG.y); ohio.disableStyle(); fill(isOver ? color(0,192,0) : color(255,127,0)); shape(ohio);
/** * @webref pshape:method * @brief Adds a new child * @param who any variable of type PShape * @see PShape#getChild(int) */ public void addChild(PShape who) { if (children == null) { children = new PShape[1]; } if (childCount == children.length) { children = (PShape[]) PApplet.expand(children); } children[childCount++] = who; who.parent = this; if (who.getName() != null) { addName(who.getName(), who); } }
/** * * @param x double * @param y double * @param z double */ @Override public void vertex(double x, double y, double z) { shape.vertex((float) x, (float) y, (float) z); }
/** * Detect faces using {@link HaarCascadeDetector}, return an {@link ArrayList} of * {@link PShape} instances. Note the {@link PShape} instances have no fill and * a colour: 255,0,0 * @return detected faces */ public ArrayList<PShape> faces(){ ArrayList<PShape> faces = new ArrayList<PShape>(); List<DetectedFace> detected = faceDetector.detectFaces(oiImage.flatten()); for (DetectedFace detectedFace : detected) { Rectangle bounds = detectedFace.getBounds(); PShape detectedPShape = this.parent.createShape(RECT,bounds.x,bounds.y,bounds.width,bounds.height); detectedPShape.setFill(false); detectedPShape.setStroke(this.parent.color(255f, 0, 0)); faces.add(detectedPShape); } return faces; } }
/** * ( begin auto-generated from PShape_disableStyle.xml ) * * Disables the shape's style data and uses Processing's current styles. * Styles include attributes such as colors, stroke weight, and stroke * joints. * * ( end auto-generated ) * <h3>Advanced</h3> * Overrides this shape's style information and uses PGraphics styles and * colors. Identical to ignoreStyles(true). Also disables styles for all * child shapes. * @webref pshape:method * @usage web_application * @brief Disables the shape's style data and uses Processing styles * @see PShape#enableStyle() */ public void disableStyle() { style = false; for (int i = 0; i < childCount; i++) { children[i].disableStyle(); } }
hangman.addChild(createShape(LINE,20,100,20,30)); hangman.addChild(createShape(LINE,20,30,50,30)); hangman.addChild(createShape(LINE,50,30,50,35)); hangmanMembers = new PShape[]{createShape(ELLIPSE,50,35,10,10),//head createShape(LINE ,55,45,55,50),//neck int livesDiff = maxLives-lives;//work out the number of lives lost (maximum value - current) if(livesDiff < maxLives) {//if there still is a shape to display hangman.addChild(hangmanMembers[livesDiff]);
/** * @webref pshape:method * @brief Finishes the creation of a new PShape * @see PApplet#beginShape() */ public void endShape() { endShape(OPEN); }
/** * Get a particular element based on its SVG ID. When editing SVG by hand, * this is the id="" tag on any SVG element. When editing from Illustrator, * these IDs can be edited by expanding the layers palette. The names used * in the layers palette, both for the layers or the shapes and groups * beneath them can be used here. * <PRE> * // This code grabs "Layer 3" and the shapes beneath it. * PShape layer3 = svg.getChild("Layer 3"); * </PRE> */ @Override public PShape getChild(String name) { PShape found = super.getChild(name); if (found == null) { // Otherwise try with underscores instead of spaces // (this is how Illustrator handles spaces in the layer names). found = super.getChild(name.replace(' ', '_')); } // Set bounding box based on the parent bounding box if (found != null) { // found.x = this.x; // found.y = this.y; found.width = this.width; found.height = this.height; } return found; }