Java Code Examples for processing.core.PShape#addChild()
The following examples show how to use
processing.core.PShape#addChild() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DwSoftGrid3D.java From PixelFlow with MIT License | 6 votes |
private PShape createShape(PGraphics pg){ PShape shp = pg.createShape(PConstants.GROUP); PShape[] shp_grid = new PShape[6]; for(int i = 0; i < shp_grid.length; i++){ shp_grid[i] = pg.createShape(); shp.addChild(shp_grid[i]); } shp_grid[0].setName("gridXYp"); shp_grid[1].setName("gridXYn"); shp_grid[2].setName("gridYZp"); shp_grid[3].setName("gridYZn"); shp_grid[4].setName("gridXZp"); shp_grid[5].setName("gridXZn"); displayGridXY(shp_grid[0], normals[0], 0 , texture_XYp); if(nodes_z > 1) displayGridXY(shp_grid[1], normals[1], nodes_z-1, texture_XYn); displayGridYZ(shp_grid[2], normals[2], 0 , texture_YZp); if(nodes_x > 1) displayGridYZ(shp_grid[3], normals[3], nodes_x-1, texture_YZn); displayGridXZ(shp_grid[4], normals[4], 0 , texture_XZp); if(nodes_y > 1) displayGridXZ(shp_grid[5], normals[5], nodes_y-1, texture_XZn); return shp; }
Example 2
Source File: HaiBlobsSSAO.java From haxademic with MIT License | 5 votes |
protected PShapeSolid newSolidIcos(float size, PImage texture) { PShape group = createShape(GROUP); PShape icos = Icosahedron.createIcosahedron(p.g, icosaDetail, texture); PShapeUtil.scaleShapeToExtent(icos, size); group.addChild(icos); return new PShapeSolid(group); }
Example 3
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static PShape addShapesByColor(PShape shape, float searchR, float searchG, float searchB, PShape container, float closenessThreshold) { for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); if(colorMatchNormalized(searchR, searchG, searchB, subShape.getFill(0), closenessThreshold)) { container.addChild(subShape); } // getShapeFromColor(shape.getChild(j), searchR, searchG, searchB); } return container; }
Example 4
Source File: Icosahedron.java From haxademic with MIT License | 5 votes |
public static PShape createIcosahedronGrouped(PApplet p, int level, PImage img, int fillColor, int strokeColor, float strokeWeight) { // the icosahedron is created with positions, normals and texture coordinates in the above class Icosahedron ico = new Icosahedron(level); p.textureMode(P.NORMAL); // set textureMode to normalized (range 0 to 1); PShape mesh = p.createShape(P.GROUP); // create the initial PShape // put all the vertices, uv texture coordinates and normals into the PShape PShape triangle = null; for (int i=0; i<ico.positions.size(); i++) { if(i % 3 == 0) { triangle = p.createShape(); triangle.beginShape(P.TRIANGLE); // define the PShape type: TRIANGLES if(fillColor != -1) { triangle.strokeWeight(strokeWeight); triangle.stroke(strokeColor); triangle.fill(fillColor); } if(img != null) mesh.texture(img); } PVector pos = ico.positions.get(i); PVector t = ico.texCoords.get(i); PVector n = ico.normals.get(i); triangle.normal(n.x, n.y, n.z); triangle.vertex(pos.x, pos.y, pos.z, t.x, t.y); if(i % 3 == 2) { triangle.endShape(); mesh.addChild(triangle); } } return mesh; }
Example 5
Source File: TextToPShape.java From haxademic with MIT License | 5 votes |
public PShape stringToShape2d(String text, String fontFile) { // if letter is in the cache, just send it back if(textShape2d.get(text) != null) return textShape2d.get(text); // geomerative builds a mesh from text & cached font if(fontsCache.get(fontFile) == null) fontsCache.put(fontFile, new RFont(fontFile, 100, RFont.CENTER)); // RFont font = fontsCache.get(fontFile); RGroup grp = font.toGroup(text); RMesh rMesh = grp.toMesh(); // convert to triangle strips from geomerative strips PShape newShape = P.p.createShape(P.GROUP); newShape.setName(text); for ( int i = 0; i < rMesh.strips.length; i++ ) { RPoint[] meshPoints = rMesh.strips[i].getPoints(); PShape triangle = P.p.createShape(); triangle.beginShape(P.TRIANGLE_STRIP); triangle.fill(255); triangle.noStroke(); for ( int ii = 0; ii < meshPoints.length; ii++ ) { triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, 0); } triangle.endShape(); newShape.addChild(triangle); } // center it PShapeUtil.centerShape(newShape); // cache & return textShape2d.put(text, newShape); return newShape; }
Example 6
Source File: PShapeSolid.java From haxademic with MIT License | 5 votes |
public static PShapeSolid newSolidIcos(float size, PImage texture, int resolution) { PShape icos = Icosahedron.createIcosahedron(P.p.g, resolution, texture).getTessellation(); PShapeUtil.repairMissingSVGVertex(icos); PShapeUtil.scaleShapeToExtent(icos, size); PShapeUtil.addTextureUVSpherical(icos, texture); PShape group = P.p.createShape(P.GROUP); group.addChild(icos); return new PShapeSolid(group); }
Example 7
Source File: PShapeSolid.java From haxademic with MIT License | 5 votes |
public static PShapeSolid newSolidSphere(float size, PImage texture) { PShape sphere = P.p.createShape(P.SPHERE, size).getTessellation(); sphere.setTexture(texture); PShapeUtil.addTextureUVSpherical(sphere, texture); PShape group = P.p.createShape(P.GROUP); group.addChild(sphere); return new PShapeSolid(group); }
Example 8
Source File: HaiBlobs.java From haxademic with MIT License | 5 votes |
protected PShapeSolid newSolidIcos(float size, PImage texture) { PShape group = createShape(GROUP); PShape icos = Icosahedron.createIcosahedron(p.g, icosaDetail, texture); PShapeUtil.scaleShapeToExtent(icos, size); group.addChild(icos); return new PShapeSolid(group); }
Example 9
Source File: BlobsForFun.java From haxademic with MIT License | 5 votes |
protected PShapeSolid newSolidIcos(float size, PImage texture) { PShape group = createShape(GROUP); PShape icos = Icosahedron.createIcosahedron(p.g, icosaDetail, texture); PShapeUtil.scaleShapeToExtent(icos, size); group.addChild(icos); return new PShapeSolid(group); }
Example 10
Source File: GradientBlobs.java From haxademic with MIT License | 5 votes |
protected PShapeSolid newSolidIcos(float size, PImage texture) { PShape group = createShape(GROUP); PShape icos = Icosahedron.createIcosahedron(p.g, 5, texture); PShapeUtil.scaleShapeToExtent(icos, size); group.addChild(icos); return new PShapeSolid(group); }
Example 11
Source File: DwSoftBody2D.java From PixelFlow with MIT License | 5 votes |
@Override public void createShapeParticles(PApplet papplet, boolean icosahedron){ PShape shp = papplet.createShape(PShape.GROUP); for(int i = 0; i < particles.length; i++){ float radius = 1; // float radius = particles[i].rad; PShape shp_pa = createShape(papplet, radius); particles[i].setShape(shp_pa); shp.addChild(shp_pa); } setShapeParticles(papplet, shp); }
Example 12
Source File: DwSoftBody3D.java From PixelFlow with MIT License | 5 votes |
@Override public void createShapeParticles(PApplet papplet, boolean icosahedron){ PShape shp = papplet.createShape(PShape.GROUP); for(int i = 0; i < particles.length; i++){ float radius = 1; // float radius = particles[i].rad; PShape shp_pa = createShape(papplet, radius, icosahedron); particles[i].setShape(shp_pa); shp.addChild(shp_pa); } setShapeParticles(papplet, shp); }
Example 13
Source File: ParticleSystem.java From PixelFlow with MIT License | 4 votes |
public PShape createParticleShape(DwParticle2D particle, PImage sprite_img){ final float rad = particle.rad; PShape shp_particle = papplet.createShape(PShape.GROUP); if( PARTICLE_SHAPE_IDX >= 0 && PARTICLE_SHAPE_IDX < 4){ PShape sprite = papplet.createShape(PShape.GEOMETRY); sprite.beginShape(PConstants.QUAD); sprite.noStroke(); sprite.noFill(); sprite.textureMode(PConstants.NORMAL); sprite.texture(sprite_img); sprite.normal(0, 0, 1); sprite.vertex(-rad, -rad, 0, 0); sprite.vertex(+rad, -rad, 1, 0); sprite.vertex(+rad, +rad, 1, 1); sprite.vertex(-rad, +rad, 0, 1); sprite.endShape(); shp_particle.addChild(sprite); } else if( PARTICLE_SHAPE_IDX == 4){ float threshold1 = 1; // radius shortening for arc segments float threshold2 = 140; // arc between segments double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad); double arc2 = (180 - threshold2) * Math.PI / 180; double arc = Math.min(arc1, arc2); int num_vtx = (int)Math.ceil(2*Math.PI/arc); // System.out.println(num_vtx); PShape circle = papplet.createShape(PShape.GEOMETRY); circle.beginShape(); circle.noStroke(); circle.fill(200,100); for(int i = 0; i < num_vtx; i++){ float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * rad; float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * rad; circle.vertex(vx, vy); } circle.endShape(PConstants.CLOSE); PShape line = papplet.createShape(PShape.GEOMETRY); line.beginShape(PConstants.LINES); line.stroke(0, 100); line.strokeWeight(1); line.vertex(0, 0); line.vertex(-(rad-1), 0); line.endShape(); // PShape circle = papplet.createShape(PConstants.ELLIPSE, 0, 0, rad*2, rad*2); // circle.setStroke(false); // circle.setFill(papplet.color(200,100)); // // PShape line = papplet.createShape(PConstants.LINE, 0, 0, -(rad-1), 0); // line.setStroke(papplet.color(0,200)); // line.setStrokeWeight(1); shp_particle.addChild(circle); shp_particle.addChild(line); } return shp_particle; }
Example 14
Source File: GradientBlobs.java From haxademic with MIT License | 4 votes |
protected PShapeSolid newSolidSphere(float size, PImage texture) { PShape group = createShape(GROUP); group.addChild(newSphere(size, texture)); return new PShapeSolid(group); }
Example 15
Source File: Skylight_BulletPhysics_CellFracture.java From PixelFlow with MIT License | 4 votes |
public PShape createVoronoiCellShape(WB_VoronoiCell3D cell, Vector3f center_of_mass){ boolean[] on_bounds = cell.getVerticesOnBoundary(); PShape voronoi_cell = createShape(GROUP); WB_Mesh mesh = cell.getMesh(); int[][] faces = mesh.getFacesAsInt(); int on_boundary = 0; for(int j = 0; j < faces.length; j++){ int[] face = faces[j]; WB_Vector normal = mesh.getFaceNormal(j); PShape polygon = createShape(); polygon.beginShape(POLYGON); polygon.normal(normal.xf(), normal.yf(), normal.zf()); for(int k = 0; k < face.length; k++){ WB_Coord vtx = mesh.getVertex(face[k]); float x = vtx.xf() - center_of_mass.x; float y = vtx.yf() - center_of_mass.y; float z = vtx.zf() - center_of_mass.z; polygon.vertex(x,y,z); if(on_bounds[face[k]]){ on_boundary++; } } polygon.endShape(CLOSE); // polygon.setFill(true); // if(on_boundary == face.length){ // if(on_boundary > 0){ // polygon.setFill(color(8)); // } else { // polygon.setFill(color(255,0,0)); // } // // polygon.setStroke(false); voronoi_cell.addChild(polygon); } String wire = ""; voronoi_cell.setFill(true); // if(on_boundary == face.length){ if(on_boundary > 0){ voronoi_cell.setFill(color(32)); wire = "[wire]"; } else { voronoi_cell.setFill(color(255,8,0)); } voronoi_cell.setStroke(false); voronoi_cell.setStroke(color(64,4,0)); voronoi_cell.setName("[cvh] "+wire); return voronoi_cell; }
Example 16
Source File: TextToPShape.java From haxademic with MIT License | 4 votes |
public PShape stringToShape3d(String text, float depth, String fontFile) { // if letter is in the cache, just send it back if(textShape3d.get(text) != null) return textShape3d.get(text); // geomerative builds a mesh from text & cached font if(fontsCache.get(fontFile) == null) fontsCache.put(fontFile, new RFont(fontFile, 100, RFont.CENTER)); // RFont font = fontsCache.get(fontFile); RGroup grp = font.toGroup(text); RMesh rMesh = grp.toMesh(); // 3d measurements float halfDepth = depth / 2f; // convert to triangle strips from geomerative strips PShape newShape = P.p.createShape(P.GROUP); newShape.setName(text); for ( int i = 0; i < rMesh.strips.length; i++ ) { RPoint[] meshPoints = rMesh.strips[i].getPoints(); PShape triangle = P.p.createShape(); // back triangle.beginShape(P.TRIANGLE_STRIP); triangle.fill(255); triangle.noStroke(); for ( int ii = 0; ii < meshPoints.length; ii++ ) { triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, -halfDepth); } triangle.endShape(); newShape.addChild(triangle); // front triangle = P.p.createShape(); triangle.beginShape(P.TRIANGLE_STRIP); triangle.fill(255); triangle.noStroke(); for ( int ii = 0; ii < meshPoints.length; ii++ ) { triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, halfDepth); } triangle.endShape(); newShape.addChild(triangle); // wall (drawing quads across strip points, which is weird) triangle = P.p.createShape(); triangle.beginShape(P.QUADS); triangle.fill(255); triangle.noStroke(); for ( int ii = 0; ii < meshPoints.length - 2; ii++ ) { triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, -halfDepth); triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, halfDepth); triangle.vertex(meshPoints[ii+1].x, meshPoints[ii+1].y, halfDepth); triangle.vertex(meshPoints[ii+1].x, meshPoints[ii+1].y, -halfDepth); triangle.vertex(meshPoints[ii+2].x, meshPoints[ii+2].y, -halfDepth); triangle.vertex(meshPoints[ii+2].x, meshPoints[ii+2].y, halfDepth); triangle.vertex(meshPoints[ii+1].x, meshPoints[ii+1].y, halfDepth); triangle.vertex(meshPoints[ii+1].x, meshPoints[ii+1].y, -halfDepth); triangle.vertex(meshPoints[ii+2].x, meshPoints[ii+2].y, -halfDepth); triangle.vertex(meshPoints[ii+2].x, meshPoints[ii+2].y, halfDepth); triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, halfDepth); triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, -halfDepth); } triangle.endShape(); newShape.addChild(triangle); } // center it PShapeUtil.centerShape(newShape); // cache & return textShape3d.put(text, newShape); return newShape; }
Example 17
Source File: ParticleSystem.java From PixelFlow with MIT License | 4 votes |
public PShape createParticleShape(DwParticle2D particle){ final float rad = particle.rad; PShape shp_particle = papplet.createShape(PShape.GROUP); // compute circle resolution, depending on the radius we reduce/increase // the number of vertices we need to render float threshold1 = 1; // radius shortening for arc segments float threshold2 = 140; // arc between segments double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad); double arc2 = (180 - threshold2) * Math.PI / 180; double arc = Math.min(arc1, arc2); int num_vtx = (int)Math.ceil(2*Math.PI/arc); // actual circle PShape circle = papplet.createShape(PShape.GEOMETRY); circle.beginShape(); circle.noStroke(); circle.fill(200,100); for(int i = 0; i < num_vtx; i++){ float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * 1; float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * 1; circle.vertex(vx, vy); } circle.endShape(PConstants.CLOSE); // line, to indicate the velocity-direction of the particle PShape line = papplet.createShape(PShape.GEOMETRY); line.beginShape(PConstants.LINES); line.stroke(255, 100); line.strokeWeight(1f/rad); line.vertex(0, 0); line.vertex(-1, 0); line.endShape(); shp_particle.addChild(circle); shp_particle.addChild(line); return shp_particle; }
Example 18
Source File: PShapeUtil.java From haxademic with MIT License | 4 votes |
public static PShape shapeFromImage(PImage img) { img.loadPixels(); PShape newShape = P.p.createShape(P.GROUP); newShape.setStroke(false); for( int x=0; x < img.width; x++ ){ for(int y=0; y < img.height; y++){ int pixelColor = ImageUtil.getPixelColor( img, x, y ); // float pixelBrightness = P.p.brightness( pixelColor ); if(pixelColor != ImageUtil.TRANSPARENT_PNG) { // if( pixelColor != ImageUtil.EMPTY_WHITE_INT && pixelColor != ImageUtil.WHITE_INT ) { P.p.fill(EasingColor.redFromColorInt(pixelColor), EasingColor.greenFromColorInt(pixelColor), EasingColor.blueFromColorInt(pixelColor), 255); P.p.noStroke(); PShape sh = P.p.createShape(); sh.beginShape(P.TRIANGLES); sh.fill( EasingColor.redFromColorInt(pixelColor), EasingColor.greenFromColorInt(pixelColor), EasingColor.blueFromColorInt(pixelColor), 255 ); // BL, BR, TR, TL float size = 0.5f; // front sh.vertex(x - size, y + size, size); sh.vertex(x + size, y + size, size); sh.vertex(x + size, y - size, size); sh.vertex(x - size, y + size, size); sh.vertex(x + size, y - size, size); sh.vertex(x - size, y - size, size); // back sh.vertex(x - size, y + size, -size); sh.vertex(x + size, y + size, -size); sh.vertex(x + size, y - size, -size); sh.vertex(x - size, y + size, -size); sh.vertex(x + size, y - size, -size); sh.vertex(x - size, y - size, -size); // left sh.vertex(x - size, y + size, -size); sh.vertex(x - size, y + size, size); sh.vertex(x - size, y - size, size); sh.vertex(x - size, y + size, -size); sh.vertex(x - size, y - size, size); sh.vertex(x - size, y - size, -size); // right sh.vertex(x + size, y + size, -size); sh.vertex(x + size, y + size, size); sh.vertex(x + size, y - size, size); sh.vertex(x + size, y + size, -size); sh.vertex(x + size, y - size, size); sh.vertex(x + size, y - size, -size); // floor sh.vertex(x - size, y + size, -size); sh.vertex(x + size, y + size, -size); sh.vertex(x + size, y + size, size); sh.vertex(x + size, y + size, size); sh.vertex(x - size, y + size, size); sh.vertex(x - size, y + size, -size); // ceiling sh.vertex(x - size, y - size, -size); sh.vertex(x + size, y - size, -size); sh.vertex(x + size, y - size, size); sh.vertex(x + size, y - size, size); sh.vertex(x - size, y - size, size); sh.vertex(x - size, y - size, -size); sh.endShape(); newShape.addChild(sh); } } } return newShape; }
Example 19
Source File: ParticleSystem.java From PixelFlow with MIT License | 4 votes |
public PShape createParticleShape(DwParticle2D particle, PImage sprite_img){ final float rad = particle.rad; PShape shp_particle = papplet.createShape(PShape.GROUP); if( PARTICLE_SHAPE_IDX >= 0 && PARTICLE_SHAPE_IDX < 4){ PShape sprite = papplet.createShape(PShape.GEOMETRY); sprite.beginShape(PConstants.QUAD); sprite.noStroke(); sprite.noFill(); sprite.textureMode(PConstants.NORMAL); sprite.texture(sprite_img); sprite.normal(0, 0, 1); sprite.vertex(-rad, -rad, 0, 0); sprite.vertex(+rad, -rad, 1, 0); sprite.vertex(+rad, +rad, 1, 1); sprite.vertex(-rad, +rad, 0, 1); sprite.endShape(); shp_particle.addChild(sprite); } else if( PARTICLE_SHAPE_IDX == 4){ float threshold1 = 1; // radius shortening for arc segments float threshold2 = 140; // arc between segments double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad); double arc2 = (180 - threshold2) * Math.PI / 180; double arc = Math.min(arc1, arc2); int num_vtx = (int)Math.ceil(2*Math.PI/arc); // System.out.println(num_vtx); PShape circle = papplet.createShape(PShape.GEOMETRY); circle.beginShape(); circle.noStroke(); circle.fill(200,100); for(int i = 0; i < num_vtx; i++){ float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * rad; float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * rad; circle.vertex(vx, vy); } circle.endShape(PConstants.CLOSE); PShape line = papplet.createShape(PShape.GEOMETRY); line.beginShape(PConstants.LINES); line.stroke(0, 100); line.strokeWeight(1); line.vertex(0, 0); line.vertex(-(rad-1), 0); line.endShape(); // PShape circle = papplet.createShape(PConstants.ELLIPSE, 0, 0, rad*2, rad*2); // circle.setStroke(false); // circle.setFill(papplet.color(200,100)); // // PShape line = papplet.createShape(PConstants.LINE, 0, 0, -(rad-1), 0); // line.setStroke(papplet.color(0,200)); // line.setStrokeWeight(1); shp_particle.addChild(circle); shp_particle.addChild(line); } return shp_particle; }