Java Code Examples for processing.core.PShape#endShape()
The following examples show how to use
processing.core.PShape#endShape() .
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 void displayGridXZ(PShape pg, float[][] normals, int iy, PGraphics2D tex){ pg.beginShape(PConstants.TRIANGLE_STRIP); pg.textureMode(PConstants.NORMAL); pg.texture(tex); pg.fill(material_color); int iz, ix; for(iz = 0; iz < nodes_z-1; iz++){ for(ix = 0; ix < nodes_x; ix++){ vertex(pg, getNode3D(ix, iy, iz+0), normals[(iz+0)*nodes_x+ix], ix * tx_inv, (iz+0) * tz_inv); vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_x+ix], ix * tx_inv, (iz+1) * tz_inv); } ix -= 1; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_x+ix], 0, 0); ix = 0; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_x+ix], 0, 0); } pg.endShape(); }
Example 2
Source File: Icosahedron.java From haxademic with MIT License | 6 votes |
public static PShape createIcosahedron(PGraphics pg, int level, PImage img) { // the icosahedron is created with positions, normals and texture coordinates in the above class Icosahedron ico = new Icosahedron(level); pg.textureMode(P.NORMAL); // set textureMode to normalized (range 0 to 1); PShape mesh = pg.createShape(); // create the initial PShape mesh.beginShape(P.TRIANGLES); // define the PShape type: TRIANGLES mesh.noStroke(); if(img != null) mesh.texture(img); // put all the vertices, uv texture coordinates and normals into the PShape for (int i=0; i<ico.positions.size(); i++) { PVector pos = ico.positions.get(i); PVector t = ico.texCoords.get(i); PVector n = ico.normals.get(i); mesh.normal(n.x, n.y, n.z); mesh.vertex(pos.x, pos.y, pos.z, t.x, t.y); } mesh.endShape(); return mesh; }
Example 3
Source File: Demo_TextTextureRepeat.java From haxademic with MIT License | 6 votes |
public PShape drawCurlyStrip(float radius, float height, int detail, float rotations, float thickness) { P.p.textureMode(P.NORMAL); PShape sh = P.p.createShape(); sh.beginShape(P.QUAD_STRIP); sh.noStroke(); for (int i = 0; i <= detail; i++) { float progress = (float) i / (float) detail; float angle = P.TWO_PI / detail * rotations; float x = P.sin(i * angle); float z = P.cos(i * angle); float y = height * 0.5f - progress * height; float u = (float)i / detail; // sh.normal(x, 0, z); sh.vertex(x * radius, y - thickness/2, z * radius, u, 0); sh.vertex(x * radius, y + thickness/2, z * radius, u, 1); } sh.endShape(); P.p.textureMode(P.IMAGE); // reset return sh; }
Example 4
Source File: DepthOfField_Demo.java From PixelFlow with MIT License | 6 votes |
public PShape createGridXY(int lines, float s){ PShape shp_gridxy = createShape(); shp_gridxy.beginShape(LINES); shp_gridxy.stroke(0); shp_gridxy.strokeWeight(1f); float d = lines*s; for(int i = 0; i <= lines; i++){ shp_gridxy.vertex(-d,-i*s,0); shp_gridxy.vertex(d,-i*s,0); shp_gridxy.vertex(-d,+i*s,0); shp_gridxy.vertex(d,+i*s,0); shp_gridxy.vertex(-i*s,-d,0); shp_gridxy.vertex(-i*s,d,0); shp_gridxy.vertex(+i*s,-d,0); shp_gridxy.vertex(+i*s,d,0); } shp_gridxy.endShape(); return shp_gridxy; }
Example 5
Source File: TextureSphere.java From haxademic with MIT License | 6 votes |
PShape createIcosahedron(int level, String imagePath) { // the icosahedron is created with positions, normals and texture coordinates in the above class Icosahedron ico = new Icosahedron(level); textureMode(NORMAL); // set textureMode to normalized (range 0 to 1); PImage tex = loadImage(imagePath); // load the texture PShape mesh = createShape(); // create the initial PShape mesh.beginShape(TRIANGLES); // define the PShape type: TRIANGLES mesh.noStroke(); mesh.texture(tex); // set the texture // put all the vertices, uv texture coordinates and normals into the PShape for (int i=0; i<ico.positions.size(); i++) { PVector p = ico.positions.get(i); PVector t = ico.texCoords.get(i); PVector n = ico.normals.get(i); mesh.normal(n.x, n.y, n.z); mesh.vertex(p.x, p.y, p.z, t.x, t.y); } mesh.endShape(); return mesh; // our work is done here, return DA MESH! ;-) }
Example 6
Source File: AntiAliasingComparison.java From PixelFlow with MIT License | 6 votes |
public PShape createGridXY(int lines, float s){ PShape shp_gridxy = createShape(); shp_gridxy.beginShape(LINES); shp_gridxy.stroke(0); shp_gridxy.strokeWeight(1f); float d = lines*s; for(int i = 0; i <= lines; i++){ shp_gridxy.vertex(-d,-i*s,0); shp_gridxy.vertex(d,-i*s,0); shp_gridxy.vertex(-d,+i*s,0); shp_gridxy.vertex(d,+i*s,0); shp_gridxy.vertex(-i*s,-d,0); shp_gridxy.vertex(-i*s,d,0); shp_gridxy.vertex(+i*s,-d,0); shp_gridxy.vertex(+i*s,d,0); } shp_gridxy.endShape(); return shp_gridxy; }
Example 7
Source File: TextureEQLinesTerrain.java From haxademic with MIT License | 5 votes |
public TextureEQLinesTerrain( int width, int height ) { super(width, height); // build scrolling audio map history eqHistory = PG.newPG(256, 256, false, false); eqHistory.noSmooth(); OpenGLUtil.setTextureQualityLow(eqHistory); eqHistoryCopy = PG.newPG(256, 256); eqHistoryCopy.noSmooth(); OpenGLUtil.setTextureQualityLow(eqHistoryCopy); // build sheet mesh shape = P.p.createShape(P.GROUP); int rows = eqHistory.height; int cols = eqHistory.width; for (int y = 0; y < rows; y++) { PShape line = P.p.createShape(); line.beginShape(); line.stroke(255); line.strokeWeight(1); line.noFill(); for (int x = 0; x < cols; x++) { line.vertex(x * 20f, y * 20f, 0); } line.endShape(); shape.addChild(line); } // normalize & texture mesh PShapeUtil.centerShape(shape); PShapeUtil.scaleShapeToHeight(shape, height * 1f); PShapeUtil.addTextureUVToShape(shape, eqHistory); shapeExtent = PShapeUtil.getMaxExtent(shape); shape.disableStyle(); shape.setTexture(eqHistory); }
Example 8
Source File: DwMeshUtils.java From PixelFlow with MIT License | 5 votes |
static public void createPolyhedronShapeNormals(PShape shape, DwIndexedFaceSetAble ifs, float scale, float normal_len){ shape.beginShape(PConstants.LINES); shape.stroke(0); int [][] faces = ifs.getFaces(); float[][] verts = ifs.getVerts(); for(int[] face : faces){ float nx = 0, ny = 0, nz = 0; int num_verts = face.length; // compute face normal for(int i = 0; i < num_verts; i++){ int vi = face[i]; nx += verts[vi][0]; ny += verts[vi][1]; nz += verts[vi][2]; } nx /= num_verts; ny /= num_verts; nz /= num_verts; float ax = nx*scale; float ay = ny*scale; float az = nz*scale; float bx = ax + nx*normal_len; float by = ay + ny*normal_len; float bz = az + nz*normal_len; shape.vertex(ax, ay, az); shape.vertex(bx, by, bz); } shape.endShape(); }
Example 9
Source File: KinectShaderVertexDeform.java From haxademic with MIT License | 5 votes |
PShape createSheet(int detail, PImage tex) { p.textureMode(NORMAL); PShape sh = p.createShape(); sh.beginShape(QUADS); sh.noStroke(); sh.noFill(); sh.texture(tex); float cellW = tex.width / detail; float cellH = tex.height / detail; int numVertices = 0; for (int col = 0; col < tex.width; col += cellW) { for (int row = 0; row < tex.height; row += cellH) { float xU = col; float yV = row; float x = -tex.width/2f + xU; float y = -tex.height/2f + yV; float z = 0; sh.normal(x, y, z); sh.vertex(x, y, z, P.map(xU, 0, tex.width, 0, 1f), P.map(yV, 0, tex.height, 0, 1f)); sh.vertex(x, y + cellH, z, P.map(xU, 0, tex.width, 0, 1f), P.map(yV + cellH, 0, tex.height, 0, 1f)); sh.vertex(x + cellW, y + cellH, z, P.map(xU + cellW, 0, tex.width, 0, 1f), P.map(yV + cellH, 0, tex.height, 0, 1f)); sh.vertex(x + cellW, y, z, P.map(xU + cellW, 0, tex.width, 0, 1f), P.map(yV, 0, tex.height, 0, 1f)); numVertices++; } } P.println(numVertices, "vertices"); sh.endShape(); return sh; }
Example 10
Source File: DwSoftBall2D.java From PixelFlow with MIT License | 5 votes |
private PShape createShape(PGraphics pg) { PShape shp = pg.createShape(); shp.beginShape(); shp.fill(material_color); shp.noStroke(); for(int i = 0; i < num_nodes; i++){ DwParticle2D pa = particles[i]; if(pa.all_springs_deactivated) continue; shp.vertex(pa.cx, pa.cy); } shp.endShape(); return shp; }
Example 11
Source File: DwSoftBall3D.java From PixelFlow with MIT License | 5 votes |
private PShape createShape(PGraphics pg){ int faces_count = mesh.ifs.getFacesCount(); int[][] faces = mesh.ifs.getFaces(); float[] n = new float[3]; // normal buffer PShape shp = pg.createShape(); shp.beginShape(PConstants.TRIANGLES); shp.noStroke(); shp.fill(material_color); for(int i = 0; i < faces_count; i++){ int v0 = faces[i][0]; int v1 = faces[i][1]; int v2 = faces[i][2]; DwParticle3D p0 = particles[v0]; if(p0.all_springs_deactivated) continue; DwParticle3D p1 = particles[v1]; if(p1.all_springs_deactivated) continue; DwParticle3D p2 = particles[v2]; if(p2.all_springs_deactivated) continue; if(FLAT_SHADING){ n[0] = n[1] = n[2] = 0; DwParticle3D.crossAccum(p0, p1, p2, n); shp.normal(n[0], n[1], n[2]); shp.vertex(p0.cx, p0.cy, p0.cz); shp.vertex(p1.cx, p1.cy, p1.cz); shp.vertex(p2.cx, p2.cy, p2.cz); } else { n = normals[v0]; shp.normal(n[0], n[1], n[2]); shp.vertex(p0.cx, p0.cy, p0.cz); n = normals[v1]; shp.normal(n[0], n[1], n[2]); shp.vertex(p1.cx, p1.cy, p1.cz); n = normals[v2]; shp.normal(n[0], n[1], n[2]); shp.vertex(p2.cx, p2.cy, p2.cz); } } shp.endShape(); return shp; }
Example 12
Source File: Demo_RuttEtraGPU.java From haxademic with MIT License | 5 votes |
protected void firstFrame() { // set up webcam WebCam.instance().setDelegate(this); webcamBuffer = p.createGraphics(p.width, p.height, PRenderers.P2D); webcamLerped = p.createGraphics(p.width, p.height, PRenderers.P2D); // build sheet mesh shape = p.createShape(P.GROUP); int rows = 100; int cols = 200; for (int y = 0; y < rows; y++) { PShape line = P.p.createShape(); line.beginShape(); line.stroke(255); line.strokeWeight(1); line.noFill(); for (int x = 0; x < cols; x++) { line.vertex(x * 10f, y * 10f, 0); } line.endShape(); shape.addChild(line); } PShapeUtil.centerShape(shape); PShapeUtil.scaleShapeToHeight(shape, p.height * 0.5f); PShapeUtil.addTextureUVToShape(shape, webcamBuffer); shapeExtent = PShapeUtil.getMaxExtent(shape); shape.disableStyle(); shape.setTexture(webcamBuffer); DebugView.setValue("shape.getVertexCount();", PShapeUtil.vertexCount(shape)); }
Example 13
Source File: Shapes.java From haxademic with MIT License | 5 votes |
public static PShape createSheet(int detail, float width, float height) { P.p.textureMode(P.NORMAL); // P.println("Shapes.createSheet() setting textureMode is weird to do here... Maybe should be PAppletHax default?"); PShape sh = P.p.createShape(); sh.beginShape(P.QUADS); sh.noStroke(); // sh.texture(tex); float cellW = width / detail; float cellH = height / detail; // int numVertices = 0; for (int col = 0; col < detail; col++) { for (int row = 0; row < detail; row++) { float xU = col * cellW; float yV = row * cellH; float x = -width/2f + col * cellW; float y = -height/2f + row * cellH; float z = 0; sh.normal(x, y, z); sh.vertex(x, y, z, P.map(xU, 0, width, 0, 1), P.map(yV, 0, height, 0, 1)); sh.vertex(x, y + cellH, z, P.map(xU, 0, width, 0, 1), P.map(yV + cellH, 0, height, 0, 1)); sh.vertex(x + cellW, y + cellH, z, P.map(xU + cellW, 0, width, 0, 1), P.map(yV + cellH, 0, height, 0, 1)); sh.vertex(x + cellW, y, z, P.map(xU + cellW, 0, width, 0, 1), P.map(yV, 0, height, 0, 1)); // numVertices += 4; } } // P.println("createSheet() vertices:", numVertices); sh.endShape(); P.p.textureMode(P.IMAGE); // reset return sh; }
Example 14
Source File: Demo_LinesDeformAndTextureFiler_Tunnel.java From haxademic with MIT License | 5 votes |
protected void firstFrame() { // load texture noiseBuffer = p.createGraphics(p.width, p.height, PRenderers.P2D); noiseTexture = new TextureShader(TextureShader.noise_simplex_2d_iq, 0.0005f); DebugView.setTexture("noiseBuffer", noiseBuffer); // build sheet mesh shape = p.createShape(P.GROUP); int rows = 200; int circleSegments = 200; float radius = 200; float segmentRads = P.TWO_PI / (float) circleSegments; for (int y = 0; y < rows; y++) { PShape line = P.p.createShape(); line.beginShape(); line.stroke(255); line.strokeWeight(1); line.noFill(); for (int i = 0; i <= circleSegments; i++) { line.vertex(radius * P.sin(segmentRads * i), y * 10f, radius * P.cos(segmentRads * i)); } line.endShape(); shape.addChild(line); } PShapeUtil.centerShape(shape); PShapeUtil.scaleShapeToHeight(shape, p.height * 2f); PShapeUtil.addTextureUVSpherical(shape, noiseBuffer); shapeExtent = PShapeUtil.getMaxExtent(shape); shape.disableStyle(); shape.setTexture(noiseBuffer); DebugView.setValue("shape.getVertexCount();", PShapeUtil.vertexCount(shape)); }
Example 15
Source File: Shapes.java From haxademic with MIT License | 4 votes |
public static PShape createBoxSingleUV(float size, float uvX, float uvY) { PShape sh = P.p.createShape(); sh.beginShape(P.QUADS); sh.textureMode(P.NORMAL); // BL, BR, TR, TL // front sh.vertex(-size, size, size, uvX, uvY); sh.vertex( size, size, size, uvX, uvY); sh.vertex( size, -size, size, uvX, uvY); sh.vertex(-size, -size, size, uvX, uvY); // back sh.vertex( size, size, -size, uvX, uvY); sh.vertex(-size, size, -size, uvX, uvY); sh.vertex(-size, -size, -size, uvX, uvY); sh.vertex( size, -size, -size, uvX, uvY); // left sh.vertex(-size, size, -size, uvX, uvY); sh.vertex(-size, size, size, uvX, uvY); sh.vertex(-size, -size, size, uvX, uvY); sh.vertex(-size, -size, -size, uvX, uvY); // right sh.vertex( size, size, size, uvX, uvY); sh.vertex( size, size, -size, uvX, uvY); sh.vertex( size, -size, -size, uvX, uvY); sh.vertex( size, -size, size, uvX, uvY); // floor sh.vertex(-size, size, -size, uvX, uvY); sh.vertex( size, size, -size, uvX, uvY); sh.vertex( size, size, size, uvX, uvY); sh.vertex(-size, size, size, uvX, uvY); // ceiling sh.vertex(-size, -size, -size, uvX, uvY); sh.vertex( size, -size, -size, uvX, uvY); sh.vertex( size, -size, size, uvX, uvY); sh.vertex(-size, -size, size, uvX, uvY); sh.endShape(); return sh; }
Example 16
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 17
Source File: Shapes.java From haxademic with MIT License | 4 votes |
public static PShape createDisc(float radius, int vertices, int rows, PImage tex) { P.p.textureMode(P.NORMAL); PShape sh = P.p.createShape(); sh.beginShape(P.TRIANGLES); sh.textureMode(P.NORMAL); if(tex != null) sh.texture(tex); sh.noStroke(); float radiusTwo = radius * 2f; float rowSize = radius / (float) rows; float segmentRads = P.TWO_PI / vertices; for( int v = 0; v < vertices; v++ ) { for( int r = 0; r < rows; r++ ) { float curRads = v * segmentRads; float nextRads = (v+1) * segmentRads; float curRadius = r * rowSize; float nextRadius = (r+1) * rowSize; float x1 = P.cos(curRads) * curRadius; float y1 = P.sin(curRads) * curRadius; float u1 = (x1 + radius) / radiusTwo; // normalize within texture - move from being centered float v1 = (y1 + radius) / radiusTwo; float x2 = P.cos(curRads) * nextRadius; float y2 = P.sin(curRads) * nextRadius; float u2 = (x2 + radius) / radiusTwo; // normalize within texture - move from being centered float v2 = (y2 + radius) / radiusTwo; float x3 = P.cos(nextRads) * nextRadius; float y3 = P.sin(nextRads) * nextRadius; float u3 = (x3 + radius) / radiusTwo; // normalize within texture - move from being centered float v3 = (y3 + radius) / radiusTwo; float x4 = P.cos(nextRads) * curRadius; float y4 = P.sin(nextRads) * curRadius; float u4 = (x4 + radius) / radiusTwo; // normalize within texture - move from being centered float v4 = (y4 + radius) / radiusTwo; sh.vertex( x1, y1, 0, u1, v1 ); sh.vertex( x2, y2, 0, u2, v2 ); sh.vertex( x3, y3, 0, u3, v3 ); sh.vertex( x1, y1, 0, u1, v1 ); sh.vertex( x4, y4, 0, u4, v4 ); sh.vertex( x3, y3, 0, u3, v3 ); } } sh.endShape(); return sh; }
Example 18
Source File: Softbody3D_Playground.java From PixelFlow with MIT License | 4 votes |
public void displayAABB(float[] aabb){ if(shp_aabb == null){ float xmin = aabb[0], xmax = aabb[3]; float ymin = aabb[1], ymax = aabb[4]; float zmin = aabb[2], zmax = aabb[5]; shp_aabb = createShape(GROUP); PShape plane_zmin = createShape(); plane_zmin.beginShape(QUAD); plane_zmin.stroke(0); plane_zmin.strokeWeight(1); plane_zmin.fill(192); plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymin, zmin); plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymin, zmin); plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymax, zmin); plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymax, zmin); plane_zmin.endShape(CLOSE); shp_aabb.addChild(plane_zmin); PShape plane_zmax = createShape(); plane_zmax.beginShape(QUAD); plane_zmax.noFill(); plane_zmax.stroke(0); plane_zmax.strokeWeight(1); plane_zmax.vertex(xmin, ymin, zmax); plane_zmax.vertex(xmax, ymin, zmax); plane_zmax.vertex(xmax, ymax, zmax); plane_zmax.vertex(xmin, ymax, zmax); plane_zmax.endShape(CLOSE); shp_aabb.addChild(plane_zmax); PShape vert_lines = createShape(); vert_lines.beginShape(LINES); vert_lines.stroke(0); vert_lines.strokeWeight(1); vert_lines.vertex(xmin, ymin, zmin); vert_lines.vertex(xmin, ymin, zmax); vert_lines.vertex(xmax, ymin, zmin); vert_lines.vertex(xmax, ymin, zmax); vert_lines.vertex(xmax, ymax, zmin); vert_lines.vertex(xmax, ymax, zmax); vert_lines.vertex(xmin, ymax, zmin); vert_lines.vertex(xmin, ymax, zmax); vert_lines.endShape(); shp_aabb.addChild(vert_lines); PShape corners = createShape(); corners.beginShape(POINTS); corners.stroke(0); corners.strokeWeight(7); corners.vertex(xmin, ymin, zmin); corners.vertex(xmin, ymin, zmax); corners.vertex(xmax, ymin, zmin); corners.vertex(xmax, ymin, zmax); corners.vertex(xmax, ymax, zmin); corners.vertex(xmax, ymax, zmax); corners.vertex(xmin, ymax, zmin); corners.vertex(xmin, ymax, zmax); corners.endShape(); shp_aabb.addChild(corners); } shape(shp_aabb); }
Example 19
Source File: Shapes.java From haxademic with MIT License | 4 votes |
public static PShape createBox(float size) { PShape sh = P.p.createShape(); sh.beginShape(P.QUADS); // BL, BR, TR, TL // front sh.vertex(-size, size, size, 0, 1); sh.vertex( size, size, size, 1, 1); sh.vertex( size, -size, size, 1, 0); sh.vertex(-size, -size, size, 0, 0); // back sh.vertex( size, size, -size, 0, 1); sh.vertex(-size, size, -size, 1, 1); sh.vertex(-size, -size, -size, 1, 0); sh.vertex( size, -size, -size, 0, 0); // left sh.vertex(-size, size, -size, 0, 1); sh.vertex(-size, size, size, 1, 1); sh.vertex(-size, -size, size, 1, 0); sh.vertex(-size, -size, -size, 0, 0); // right sh.vertex( size, size, size, 0, 1); sh.vertex( size, size, -size, 1, 1); sh.vertex( size, -size, -size, 1, 0); sh.vertex( size, -size, size, 0, 0); // floor sh.vertex(-size, size, -size, 0, 0); sh.vertex( size, size, -size, 1, 0); sh.vertex( size, size, size, 1, 1); sh.vertex(-size, size, size, 0, 1); // ceiling sh.vertex(-size, -size, -size, 0, 0); sh.vertex( size, -size, -size, 1, 0); sh.vertex( size, -size, size, 1, 1); sh.vertex(-size, -size, size, 0, 1); sh.endShape(); return sh; }
Example 20
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; }