Java Code Examples for processing.core.PShape#strokeWeight()
The following examples show how to use
processing.core.PShape#strokeWeight() .
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: PShapeUtil.java From haxademic with MIT License | 6 votes |
public static PShape svgToUniformPointsShape(String fileName, float spacing) { // load svg and polygonize with Geomerative if(!RG.initialized()) RG.init(P.p); RShape rShape = RG.loadShape(fileName); rShape = RG.centerIn(rShape, P.p.g); RG.setPolygonizer(RG.UNIFORMLENGTH); RG.setPolygonizerLength(spacing); RPoint[] points = rShape.getPoints(); // create PShape PShape svg = P.p.createShape(); svg.beginShape(PConstants.POINTS); svg.stroke(255); svg.strokeWeight(1); svg.noFill(); for(int i=0; i < points.length; i++){ svg.vertex(points[i].x, points[i].y); } svg.endShape(P.CLOSE); return svg; }
Example 2
Source File: Shapes.java From haxademic with MIT License | 6 votes |
public static PShape createSheetPoints(int detail, float width, float height) { PShape sh = P.p.createShape(); sh.beginShape(PConstants.POINTS); sh.stroke(255); sh.strokeWeight(1); sh.noFill(); 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)); // numVertices += 1; } } // P.println("createSheet() vertices:", numVertices); sh.endShape(); return sh; }
Example 3
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 4
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 5
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 6
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static PShape meshShapeToPointsShape(PShape origShape) { PShape newShape = P.p.createShape(); newShape.beginShape(PConstants.POINTS); newShape.stroke(255); newShape.strokeWeight(1); newShape.noFill(); addVerticesToPointShape(origShape, newShape); newShape.endShape(); return newShape; }
Example 7
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 8
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 9
Source File: Demo_LinesDeformAndTextureFilter.java From haxademic with MIT License | 5 votes |
protected void firstFrame() { // load texture perlin = new PerlinTexture(p, 256, 256); texture = perlin.texture(); DebugView.setTexture("texture", texture); // build sheet mesh shape = p.createShape(P.GROUP); int rows = 200; int cols = 500; 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 * 2f); PShapeUtil.addTextureUVToShape(shape, texture); shapeExtent = PShapeUtil.getMaxExtent(shape); shape.disableStyle(); shape.setTexture(texture); DebugView.setValue("shape.getVertexCount();", PShapeUtil.vertexCount(shape)); }
Example 10
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 11
Source File: Skylight_ClothSimulation.java From PixelFlow with MIT License | 4 votes |
public void displayAABB(PGraphics3D canvas, 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(16,96,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); } canvas.shape(shp_aabb); }
Example 12
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 13
Source File: Softbody3D_Cloth.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(64); 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 14
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 15
Source File: Softbody3D_ParticleCollisionSystem.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 16
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 17
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; }