Java Code Examples for processing.core.PGraphics#beginShape()
The following examples show how to use
processing.core.PGraphics#beginShape() .
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: ConstellationPolygonMarker.java From constellation with Apache License 2.0 | 6 votes |
@Override public boolean draw(final PGraphics graphics, final List<MapPosition> positions, final UnfoldingMap map) { if (positions.isEmpty() || isHidden()) { return false; } graphics.pushStyle(); graphics.strokeWeight(size == MarkerUtilities.DEFAULT_SIZE ? strokeWeight : size); graphics.stroke(strokeColor); graphics.fill(getFillColor()); graphics.beginShape(); positions.forEach(position -> { graphics.vertex(position.x, position.y); }); graphics.endShape(PConstants.CLOSE); graphics.popStyle(); return true; }
Example 2
Source File: Gradients.java From haxademic with MIT License | 6 votes |
public static void quad( PGraphics p, float width, float height, int colorTL, int colorTR, int colorBR, int colorBL ) { p.pushMatrix(); float halfW = width/2; float halfH = height/2; p.beginShape(); p.fill(colorTL); p.vertex(-halfW, -halfH); p.fill(colorTR); p.vertex(halfW, -halfH); p.fill(colorBR); p.vertex(halfW, halfH); p.fill(colorBL); p.vertex(-halfW, halfH); p.endShape(P.CLOSE); p.popMatrix(); }
Example 3
Source File: Gradients.java From haxademic with MIT License | 6 votes |
public static void radial( PGraphics p, float width, float height, int colorInner, int colorOuter, int numSegments ) { p.pushMatrix(); float halfW = width/2; float halfH = height/2; float segmentRadians = P.TWO_PI / numSegments; p.noStroke(); for(float r=0; r < P.TWO_PI; r += segmentRadians) { float r2 = r + segmentRadians; p.beginShape(); p.fill(colorInner); p.vertex(0,0); p.fill(colorOuter); p.vertex(P.sin(r) * halfW, P.cos(r) * halfH); p.vertex(P.sin(r2) * halfW, P.cos(r2) * halfH); p.endShape(P.CLOSE); } p.popMatrix(); }
Example 4
Source File: ConstellationLineMarker.java From constellation with Apache License 2.0 | 6 votes |
@Override public boolean draw(final PGraphics graphics, final List<MapPosition> positions, final UnfoldingMap map) { if (positions.isEmpty() || isHidden()) { return false; } graphics.pushStyle(); graphics.noFill(); graphics.strokeWeight(size == MarkerUtilities.DEFAULT_SIZE ? strokeWeight : size); graphics.stroke(getFillColor()); graphics.smooth(); graphics.beginShape(PConstants.LINES); for (int i = 0; i < positions.size() - 1; ++i) { final MapPosition lastPosition = positions.get(i); final MapPosition currentPosition = positions.get(i + 1); graphics.vertex(lastPosition.x, lastPosition.y); graphics.vertex(currentPosition.x, currentPosition.y); } graphics.endShape(); graphics.popStyle(); return true; }
Example 5
Source File: DwSoftBall3D.java From PixelFlow with MIT License | 5 votes |
@Override public void displayNormals(PGraphics pg){ pg.beginShape(PConstants.LINES); for(int ia = 0; ia < num_nodes; ia++){ normal(pg, particles[ia], normals[ia], display_normal_length); } pg.endShape(); }
Example 6
Source File: Shapes.java From haxademic with MIT License | 5 votes |
public static void drawSphereWithQuads(PGraphics pg, float size) { float radius = size; float rho = radius; float x, y, z; float phi = 0; int phiSteps = 20; float phiFactor = P.PI / phiSteps; float theta; int thetaSteps = 20; float thetaFactor = P.TWO_PI / thetaSteps; for(int p = 0; p < phiSteps; p++) { pg.beginShape(P.QUAD_STRIP); theta = 0.0f; for(int t = 0; t < thetaSteps + 1; t++) { x = rho * P.sin(phi) * P.cos(theta); z = rho * P.sin(phi) * P.sin(theta); y = -rho * P.cos(phi); pg.normal(x, y, z); pg.vertex(x, y, z); x = rho * P.sin(phi + phiFactor) * P.cos(theta); z = rho * P.sin(phi + phiFactor) * P.sin(theta); y = -rho * P.cos(phi + phiFactor); pg.normal(x, y, z); pg.vertex(x, y, z); theta += thetaFactor; } phi += phiFactor; pg.endShape(P.CLOSE); } }
Example 7
Source File: BFLinewaveRender.java From haxademic with MIT License | 5 votes |
public void update(PGraphics pg, float frameOsc) { _x.update(); _y.update(); pg.noFill(); pg.stroke(0); pg.strokeWeight(HEIGHT); p.strokeCap(P.SQUARE); float third = 1f/3f; float twoThird = 2f/3f; float sixth = 1f/6f; float curveAdd = 1.25f; curveAdd = curveAdd/2f + frameOsc * curveAdd/2f; pg.beginShape(); pg.vertex(_x.value(), _y.value()); pg.bezierVertex( _x.value() + WIDTH * sixth, _y.value(), _x.value() + WIDTH * sixth, _y.value() + _index * curveAdd, _x.value() + WIDTH * third, _y.value() + _index * curveAdd ); pg.bezierVertex( _x.value() + WIDTH * (third + sixth), _y.value() + _index * curveAdd, _x.value() + WIDTH * (third + sixth), _y.value(), _x.value() + WIDTH * twoThird, _y.value() ); pg.bezierVertex( _x.value() + WIDTH * (twoThird + sixth), _y.value(), _x.value() + WIDTH * (twoThird + sixth), _y.value() + _index * curveAdd, _x.value() + WIDTH, _y.value() + _index * curveAdd ); pg.endShape(); }
Example 8
Source File: DrawToxiMesh.java From haxademic with MIT License | 5 votes |
public static void drawMeshWithAudio( PGraphics p, WETriangleMesh mesh, AudioInputWrapper audioInput, boolean isWireframe, int fillColor, int strokeColor, float baseAlpha ) { p.beginShape(PConstants.TRIANGLES); int faceIndex = 0; int color = fillColor; int colorStroke = strokeColor; float alpha; Face f; int numVertices = mesh.getNumVertices(); int eqStep = Math.round( 512f / (float) numVertices ); for (Iterator<Face> i = mesh.faces.iterator(); i.hasNext();) { // set colors alpha = baseAlpha + audioInput.getFFT().spectrum[(faceIndex*eqStep)%512]; if( isWireframe ) { p.noFill(); p.stroke( colorStroke, ( baseAlpha + alpha ) * 255 ); } else { p.noStroke(); p.fill( color, ( baseAlpha + alpha ) * 255 ); } f = i.next(); normalMap.applyTo(f.a.normal); p.normal(f.a.normal.x, f.a.normal.y, f.a.normal.z); p.vertex(f.a.x, f.a.y, f.a.z); normalMap.applyTo(f.b.normal); p.normal(f.b.normal.x, f.b.normal.y, f.b.normal.z); p.vertex(f.b.x, f.b.y, f.b.z); normalMap.applyTo(f.c.normal); p.normal(f.c.normal.x, f.c.normal.y, f.c.normal.z); p.vertex(f.c.x, f.c.y, f.c.z); faceIndex ++; } p.endShape(); }
Example 9
Source File: DwSoftGrid3D.java From PixelFlow with MIT License | 5 votes |
private void displayNormalsXY(PGraphics pg, float[][] normals, int iz, float nlen){ pg.beginShape(PConstants.LINES); for(int iy = 0; iy < nodes_y; iy++){ for(int ix = 0; ix < nodes_x; ix++){ normal(pg, getNode3D(ix, iy, iz), normals[iy * nodes_x + ix], nlen); } } pg.endShape(); }
Example 10
Source File: Extrude2dPoints.java From haxademic with MIT License | 5 votes |
public static void drawExtruded2dPointList( PGraphics p, ArrayList<PVector> pointsArray, float depth ) { p.beginShape(); PVector v; // draw top p.beginShape(); for (int i = 0; i < pointsArray.size(); i++) { v = pointsArray.get(i); p.vertex(v.x, v.y, depth); } p.endShape(); // draw bottom p.beginShape(); for (int i = 0; i < pointsArray.size(); i++) { v = pointsArray.get(i); p.vertex(v.x, v.y, -depth); } p.endShape(); // draw walls between the 2 faces - close the 2 triangles p.beginShape(P.TRIANGLE_STRIP); for (int i = 0; i < pointsArray.size(); i++) { v = pointsArray.get(i); p.vertex(v.x, v.y, depth); p.vertex(v.x, v.y, -depth); } // connect the last to the first v = pointsArray.get(0); p.vertex(v.x, v.y, depth); p.vertex(v.x, v.y, -depth); p.endShape(); }
Example 11
Source File: Shapes.java From haxademic with MIT License | 5 votes |
public static void drawPyramid( PGraphics p, float shapeHeight, float baseWidth, boolean drawBase ){ baseWidth *= P.HALF_PI; p.pushMatrix(); p.rotateZ(P.radians(-45.0f)); p.beginShape(P.TRIANGLES); int numSides = 4; float segmentCircumference = (2f*P.PI) / numSides; float halfBaseW = baseWidth / 2f; for( int i = 0; i < numSides; i++ ) { p.vertex( 0, 0, shapeHeight ); p.vertex( P.sin( i * segmentCircumference ) * halfBaseW, P.cos( i * segmentCircumference ) * halfBaseW, 0 ); p.vertex( P.sin( (i + 1) * segmentCircumference ) * halfBaseW, P.cos( (i + 1) * segmentCircumference ) * halfBaseW, 0 ); } if( drawBase ) { // base p.vertex( P.sin( 0 * segmentCircumference ) * halfBaseW, P.cos( 0 * segmentCircumference ) * halfBaseW, 0 ); p.vertex( P.sin( 1 * segmentCircumference ) * halfBaseW, P.cos( 1 * segmentCircumference ) * halfBaseW, 0 ); p.vertex( P.sin( 2 * segmentCircumference ) * halfBaseW, P.cos( 2 * segmentCircumference ) * halfBaseW, 0 ); p.vertex( P.sin( 2 * segmentCircumference ) * halfBaseW, P.cos( 2 * segmentCircumference ) * halfBaseW, 0 ); p.vertex( P.sin( 3 * segmentCircumference ) * halfBaseW, P.cos( 3 * segmentCircumference ) * halfBaseW, 0 ); p.vertex( P.sin( 0 * segmentCircumference ) * halfBaseW, P.cos( 0 * segmentCircumference ) * halfBaseW, 0 ); } p.endShape(); p.popMatrix(); }
Example 12
Source File: Shapes.java From haxademic with MIT License | 5 votes |
public static void drawStar( PGraphics p, float spikes, float outerrad, float innerradpercent, float h, float rot) { p.pushMatrix(); int pi; float futil; p.beginShape(P.TRIANGLE_STRIP); for(pi=0;pi<spikes+1;pi++) { p.vertex(0,0,h/2); futil=(pi/spikes) * P.TWO_PI; //current angle p.vertex( P.cos(futil+rot)*outerrad, P.sin(futil+rot)*outerrad, 0); futil=futil+ ( (1/spikes)/2 *P.TWO_PI ); p.vertex( P.cos(futil+rot)*outerrad*innerradpercent, P.sin(futil+rot)*outerrad*innerradpercent, 0); } p.endShape(); p.beginShape(P.TRIANGLE_STRIP); for(pi=0;pi<spikes+1;pi++) { p.vertex(0,0,-h/2); futil=(pi/spikes) * P.TWO_PI; //current angle p.vertex( P.cos(futil+rot)*outerrad, P.sin(futil+rot)*outerrad, 0); futil=futil+ ( (1/spikes)/2 *P.TWO_PI ); p.vertex( P.cos(futil+rot)*outerrad*innerradpercent, P.sin(futil+rot)*outerrad*innerradpercent, 0); } p.endShape(); p.popMatrix(); }
Example 13
Source File: MappedTriangle.java From haxademic with MIT License | 5 votes |
public void rawDrawPolygon( PGraphics pg ) { pg.beginShape(PConstants.TRIANGLE); pg.vertex(_x1.value(), _y1.value()); pg.vertex(_x2.value(), _y2.value()); pg.vertex(_x3.value(), _y3.value()); pg.endShape(); }
Example 14
Source File: BezierSurface.java From sketch-mapper with MIT License | 4 votes |
/** * Renders the grid in the surface. (useful in calibration mode) * * @param g */ private void renderGrid(PGraphics g) { g.beginDraw(); g.fill(ccolor); g.noStroke(); for (int i = 0; i < GRID_RESOLUTION; i++) { for (int j = 0; j < GRID_RESOLUTION; j++) { g.beginShape(); g.vertex(vertexPoints[i][j].x, vertexPoints[i][j].y); g.vertex(vertexPoints[i + 1][j].x, vertexPoints[i + 1][j].y); g.vertex(vertexPoints[i + 1][j + 1].x, vertexPoints[i + 1][j + 1].y); g.vertex(vertexPoints[i][j + 1].x, vertexPoints[i][j + 1].y); g.endShape(); } } g.textFont(sm.getIdFont()); g.fill(255); g.textAlign(PApplet.CENTER, PApplet.CENTER); g.textSize(20); g.text("" + this.getSurfaceName(), (float) (this.getCenter().x), (float) this.getCenter().y); if (isLocked) { g.textSize(12); g.text("Surface locked", (float) this.getCenter().x, (float) this.getCenter().y + 26); } if (sketch != null) { g.textSize(10); g.text(sketch.getName(), (float) this.getCenter().x, (float) this.getCenter().y + 40); } g.noFill(); g.stroke(BezierSurface.GRID_LINE_COLOR); g.strokeWeight(2); if (isSelected) g.stroke(BezierSurface.GRID_LINE_SELECTED_COLOR); if (!isLocked) { for (int i = 0; i <= GRID_RESOLUTION; i++) { for (int j = 0; j <= GRID_RESOLUTION; j++) { g.point(vertexPoints[i][j].x, vertexPoints[i][j].y, vertexPoints[i][j].z); } } } if (isSelected) { g.strokeWeight(4); g.stroke(BezierSurface.GRID_LINE_SELECTED_COLOR); //draw the outline here for (int i = 0; i < poly.npoints - 1; i++) { g.line(poly.xpoints[i], poly.ypoints[i], poly.xpoints[i + 1], poly.ypoints[i + 1]); if (i == poly.npoints - 2) g.line(poly.xpoints[i + 1], poly.ypoints[i + 1], poly.xpoints[0], poly.ypoints[0]); } } g.strokeWeight(1); g.stroke(SELECTED_OUTLINE_INNER_COLOR); //draw the outline here for (int i = 0; i < poly.npoints - 1; i++) { g.line(poly.xpoints[i], poly.ypoints[i], poly.xpoints[i + 1], poly.ypoints[i + 1]); if (i == poly.npoints - 2) g.line(poly.xpoints[i + 1], poly.ypoints[i + 1], poly.xpoints[0], poly.ypoints[0]); } if (!isLocked) { // Draw the control points. for (int i = 0; i < this.cornerPoints.length; i++) { this.renderCornerPoint(g, this.cornerPoints[i].x, this.cornerPoints[i].y, (this.activePoint == i), i); } for (int i = 0; i < this.bezierPoints.length; i++) { this.renderBezierPoint(g, this.bezierPoints[i].x, this.bezierPoints[i].y, (this.selectedBezierControl == i), i); g.strokeWeight(1); g.stroke(255); g.line(this.bezierPoints[i].x, this.bezierPoints[i].y, this.cornerPoints[(int) (i / 2)].x, this.cornerPoints[(int) (i / 2)].y); } } g.endDraw(); }
Example 15
Source File: BezierSurface.java From sketch-mapper with MIT License | 4 votes |
/** * Actual rendering of the surface. Is called from the render method. * Should normally not be accessed directly. * * @param g * @param tex */ private void renderSurface(PGraphics g, PImage tex) { float tWidth = 1; float tHeight = 1; float tOffX = 0; float tOffY = 0; tWidth = tex.width * (textureWindow[1].x); tHeight = tex.height * (textureWindow[1].y); tOffX = tex.width * textureWindow[0].x; tOffY = tex.height * textureWindow[0].y; if (this.isUsingEdgeBlend() || this.isUsingSurfaceMask()) { if (bufferScreen == null || bufferScreen.width != this.getBufferScreenWidth()) { bufferScreen = parent.createGraphics(this.getBufferScreenWidth(), this.getBufferScreenWidth()); } bufferScreen.beginDraw(); bufferScreen.beginShape(PApplet.QUADS); bufferScreen.texture(tex); bufferScreen.vertex(0, 0, tOffX, tOffY); bufferScreen.vertex(bufferScreen.width, 0, tWidth + tOffX, tOffY); bufferScreen.vertex(bufferScreen.width, bufferScreen.height, tWidth + tOffX, tHeight + tOffY); bufferScreen.vertex(0, bufferScreen.height, tOffX, tHeight + tOffY); bufferScreen.endShape(PApplet.CLOSE); bufferScreen.endDraw(); if (this.isUsingSurfaceMask()) { // maskFilter.setParameterValue("mask_factor", 0.0f); // maskFilter.apply(new GLTexture[]{bufferScreen.getTexture(), surfaceMask}, maskedTex); // applyEdgeBlendToTexture(maskedTex); } else { applyEdgeBlendToTexture(bufferScreen.get()); } } g.beginDraw(); g.noStroke(); g.beginShape(PApplet.QUADS); if (this.isUsingSurfaceMask() || this.isUsingEdgeBlend()) { g.texture(maskedTex); tOffX = 0; tOffY = 0; tWidth = maskedTex.width; tHeight = maskedTex.height; } else { g.texture(tex); if (bufferScreen != null) bufferScreen = null; } for (int i = 0; i < GRID_RESOLUTION; i++) { for (int j = 0; j < GRID_RESOLUTION; j++) { g.vertex(vertexPoints[i][j].x, vertexPoints[i][j].y, vertexPoints[i][j].z + currentZ, ((float) i / GRID_RESOLUTION) * tWidth + tOffX, ((float) j / GRID_RESOLUTION) * tHeight + tOffY); g.vertex(vertexPoints[i + 1][j].x, vertexPoints[i + 1][j].y, vertexPoints[i + 1][j].z + currentZ, (((float) i + 1) / GRID_RESOLUTION) * tWidth + tOffX, ((float) j / GRID_RESOLUTION) * tHeight + tOffY); g.vertex(vertexPoints[i + 1][j + 1].x, vertexPoints[i + 1][j + 1].y, vertexPoints[i + 1][j + 1].z + currentZ, (((float) i + 1) / GRID_RESOLUTION) * tWidth + tOffX, (((float) j + 1) / GRID_RESOLUTION) * tHeight + tOffY); g.vertex(vertexPoints[i][j + 1].x, vertexPoints[i][j + 1].y, vertexPoints[i][j + 1].z + currentZ, ((float) i / GRID_RESOLUTION) * tWidth + tOffX, (((float) j + 1) / GRID_RESOLUTION) * tHeight + tOffY); } } g.endShape(PApplet.CLOSE); g.endDraw(); }
Example 16
Source File: QuadSurface.java From sketch-mapper with MIT License | 4 votes |
/** * Actual rendering of the QUAD. Is called from the render method. Should * normally not be accessed directly. * * @param g * @param tex */ private void renderQuad(PGraphics g, PImage tex) { tOffX = tex.width * textureWindow[0].x; tOffY = tex.height * textureWindow[0].y; tWidth = tex.width * (textureWindow[1].x); tHeight = tex.height * (textureWindow[1].y); if (this.isUsingEdgeBlend() || this.isUsingSurfaceMask()) { // // if (bufferScreen == null || bufferScreen.width != this.getBufferScreenWidth()) { // bufferScreen = parent.createGraphics(this.getBufferScreenWidth(), this.getBufferScreenWidth()); // } // bufferScreen.beginDraw(); // bufferScreen.beginShape(PApplet.QUADS); // bufferScreen.texture(tex); // bufferScreen.vertex(0, 0, tOffX, tOffY); // bufferScreen.vertex(bufferScreen.width, 0, tWidth + tOffX, tOffY); // bufferScreen.vertex(bufferScreen.width, bufferScreen.height, tWidth + tOffX, tHeight + tOffY); // bufferScreen.vertex(0, bufferScreen.height, tOffX, tHeight + tOffY); // bufferScreen.endShape(PApplet.CLOSE); // bufferScreen.endDraw(); // // // if (this.isUsingSurfaceMask()) { //// maskFilter.setParameterValue("mask_factor", 0.0f); //// maskFilter.apply(new GLTexture[]{bufferScreen.getTexture(), surfaceMask}, maskedTex); //// applyEdgeBlendToTexture(maskedTex); // } else { // applyEdgeBlendToTexture(bufferScreen.get()); // } } g.beginDraw(); g.noStroke(); g.beginShape(PApplet.QUADS); g.texture(tex); if (this.isUsingSurfaceMask() || this.isUsingEdgeBlend()) { g.texture(maskedTex); tOffX = 0; tOffY = 0; tWidth = maskedTex.width; tHeight = maskedTex.height; } else { g.texture(tex); if (bufferScreen != null) { bufferScreen = null; } if (blendScreen != null) { blendScreen = null; } } for (int i = 0; i < GRID_RESOLUTION - 1; i++) { for (int j = 0; j < GRID_RESOLUTION - 1; j++) { g.vertex(vertexPoints[i][j].x, vertexPoints[i][j].y, vertexPoints[i][j].z + currentZ, ((float) i / (GRID_RESOLUTION - 1)) * tWidth + tOffX, ((float) j / (GRID_RESOLUTION - 1)) * tHeight + tOffY); g.vertex(vertexPoints[i + 1][j].x, vertexPoints[i + 1][j].y, vertexPoints[i + 1][j].z + currentZ, (((float) i + 1) / (GRID_RESOLUTION - 1)) * tWidth + tOffX, ((float) j / (GRID_RESOLUTION - 1)) * tHeight + tOffY); g.vertex(vertexPoints[i + 1][j + 1].x, vertexPoints[i + 1][j + 1].y, vertexPoints[i + 1][j + 1].z + currentZ, (((float) i + 1) / (GRID_RESOLUTION - 1)) * tWidth + tOffX, (((float) j + 1) / (GRID_RESOLUTION - 1)) * tHeight + tOffY); g.vertex(vertexPoints[i][j + 1].x, vertexPoints[i][j + 1].y, vertexPoints[i][j + 1].z + currentZ, ((float) i / (GRID_RESOLUTION - 1)) * tWidth + tOffX, (((float) j + 1) / (GRID_RESOLUTION - 1)) * tHeight + tOffY); } } g.endShape(PApplet.CLOSE); g.endDraw(); }
Example 17
Source File: ImageUtil.java From haxademic with MIT License | 4 votes |
public static void drawTextureMappedRect(PGraphics dest, PImage texture, int subdivideX, int subdivideY, float topLeftX, float topLeftY, float topRightX, float topRightY, float bottomRightX, float bottomRightY, float bottomLeftX, float bottomLeftY) { // draw to screen with pinned corner coords // generalized version ported from PGraphicsKeystone // inspired by: https://github.com/davidbouchard/keystone & http://marcinignac.com/blog/projectedquads-source-code/ dest.textureMode(PConstants.IMAGE); dest.noStroke(); dest.fill(255); dest.beginShape(PConstants.QUAD); dest.texture(texture); if(subdivideX > 0) { // subdivide quad for better resolution float stepsX = subdivideX; float stepsY = subdivideY; for( float x=0; x < stepsX; x += 1f ) { // calculate spread of mesh grid and uv coordinates float xPercent = x/stepsX; float xPercentNext = (x+1f)/stepsX; if( xPercentNext > 1 ) xPercentNext = 1; float uPercent = xPercent; float uPercentNext = xPercentNext; for( float y=0; y < stepsY; y += 1f ) { // calculate spread of mesh grid and uv coordinates float yPercent = y/stepsY; float yPercentNext = (y+1f)/stepsY; if( yPercentNext > 1 ) yPercentNext = 1; float vPercent = yPercent; float vPercentNext = yPercentNext; // calc grid positions based on interpolating columns between corners float colTopX = interp(topLeftX, topRightX, xPercent); float colTopY = interp(topLeftY, topRightY, xPercent); float colBotX = interp(bottomLeftX, bottomRightX, xPercent); float colBotY = interp(bottomLeftY, bottomRightY, xPercent); float nextColTopX = interp(topLeftX, topRightX, xPercentNext); float nextColTopY = interp(topLeftY, topRightY, xPercentNext); float nextColBotX = interp(bottomLeftX, bottomRightX, xPercentNext); float nextColBotY = interp(bottomLeftY, bottomRightY, xPercentNext); // calc quad coords float quadTopLeftX = interp(colTopX, colBotX, yPercent); float quadTopLeftY = interp(colTopY, colBotY, yPercent); float quadTopRightX = interp(nextColTopX, nextColBotX, yPercent); float quadTopRightY = interp(nextColTopY, nextColBotY, yPercent); float quadBotRightX = interp(nextColTopX, nextColBotX, yPercentNext); float quadBotRightY = interp(nextColTopY, nextColBotY, yPercentNext); float quadBotLeftX = interp(colTopX, colBotX, yPercentNext); float quadBotLeftY = interp(colTopY, colBotY, yPercentNext); // draw subdivided quads dest.vertex(quadTopLeftX, quadTopLeftY, 0, texture.width * uPercent, texture.height * vPercent); dest.vertex(quadTopRightX, quadTopRightY, 0, texture.width * uPercentNext, texture.height * vPercent); dest.vertex(quadBotRightX, quadBotRightY, 0, texture.width * uPercentNext, texture.height * vPercentNext); dest.vertex(quadBotLeftX, quadBotLeftY, 0, texture.width * uPercent, texture.height * vPercentNext); } } } else { // default single mapped quad dest.vertex(topLeftX, topLeftY, 0, 0, 0); dest.vertex(topRightX, topRightY, 0, texture.width, 0); dest.vertex(bottomRightX, bottomRightY, 0, texture.width, texture.height); dest.vertex(bottomLeftX, bottomLeftY, 0, 0, texture.height); } dest.endShape(); }
Example 18
Source File: Shapes.java From haxademic with MIT License | 4 votes |
public static void drawTexturedCube(PGraphics pg, float size, PImage texture) { pg.beginShape(P.QUADS); pg.texture(texture); // BL, BR, TR, TL // front pg.vertex(-size, size, size, 0, texture.height); pg.vertex( size, size, size, texture.width, texture.height); pg.vertex( size, -size, size, texture.width, 0); pg.vertex(-size, -size, size, 0, 0); // back pg.vertex( size, size, -size, 0, texture.height); pg.vertex(-size, size, -size, texture.width, texture.height); pg.vertex(-size, -size, -size, texture.width, 0); pg.vertex( size, -size, -size, 0, 0); // left pg.vertex(-size, size, -size, 0, texture.height); pg.vertex(-size, size, size, texture.width, texture.height); pg.vertex(-size, -size, size, texture.width, 0); pg.vertex(-size, -size, -size, 0, 0); // right pg.vertex( size, size, size, 0, texture.height); pg.vertex( size, size, -size, texture.width, texture.height); pg.vertex( size, -size, -size, texture.width, 0); pg.vertex( size, -size, size, 0, 0); // floor pg.vertex(-size, size, -size, 0, 0); pg.vertex( size, size, -size, texture.width, 0); pg.vertex( size, size, size, texture.width, texture.height); pg.vertex(-size, size, size, 0, texture.height); // ceiling pg.vertex(-size, -size, -size, 0, 0); pg.vertex( size, -size, -size, texture.width, 0); pg.vertex( size, -size, size, texture.width, texture.height); pg.vertex(-size, -size, size, 0, texture.height); pg.endShape(); }
Example 19
Source File: Shapes.java From haxademic with MIT License | 4 votes |
public static void textureQuadSubdivided(PGraphics pg, PImage texture, int subDivideSteps, float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4 ) { pg.beginShape(P.QUAD); pg.textureMode(PConstants.NORMAL); pg.texture(texture); // subdivide quad for better resolution // vertices go top-left, clockwise to bottom left float stepsX = subDivideSteps; float segmentX = 1f / subDivideSteps; float stepsY = subDivideSteps; float segmentY = 1f / stepsY; // draw a subdivided grid for( float x=0; x < stepsX; x++ ) { // calculate spread of mesh grid and uv coordinates float xNorm = x * segmentX; float xNormNext = (x+1) * segmentX; for( float y=0; y < stepsY; y++ ) { // calculate grid cells' uv coordinates float yNorm = y * segmentY; float yNormNext = (y+1) * segmentY; // calc grid positions based on interpolating columns between corners // we only need the xProgress for this, since we're slicing by column float colTopX = P.lerp(x1, x2, xNorm); float colTopY = P.lerp(y1, y2, xNorm); float colTopZ = P.lerp(z1, z2, xNorm); float colTopU = P.lerp(u1, u2, xNorm); float colTopV = P.lerp(v1, v2, xNorm); float colBotX = P.lerp(x4, x3, xNorm); float colBotY = P.lerp(y4, y3, xNorm); float colBotZ = P.lerp(z4, z3, xNorm); float colBotU = P.lerp(u4, u3, xNorm); float colBotV = P.lerp(v4, v3, xNorm); float nextColTopX = P.lerp(x1, x2, xNormNext); float nextColTopY = P.lerp(y1, y2, xNormNext); float nextColTopZ = P.lerp(z1, z2, xNormNext); float nextColTopU = P.lerp(u1, u2, xNormNext); float nextColTopV = P.lerp(v1, v2, xNormNext); float nextColBotX = P.lerp(x4, x3, xNormNext); float nextColBotY = P.lerp(y4, y3, xNormNext); float nextColBotZ = P.lerp(z4, z3, xNormNext); float nextColBotU = P.lerp(u4, u3, xNormNext); float nextColBotV = P.lerp(v4, v3, xNormNext); // calc quad coords float quadTopLeftX = P.lerp(colTopX, colBotX, yNorm); float quadTopLeftY = P.lerp(colTopY, colBotY, yNorm); float quadTopLeftZ = P.lerp(colTopZ, colBotZ, yNorm); float quadTopLeftU = P.lerp(colTopU, colBotU, yNorm); float quadTopLeftV = P.lerp(colTopV, colBotV, yNorm); float quadTopRightX = P.lerp(nextColTopX, nextColBotX, yNorm); float quadTopRightY = P.lerp(nextColTopY, nextColBotY, yNorm); float quadTopRightZ = P.lerp(nextColTopZ, nextColBotZ, yNorm); float quadTopRightU = P.lerp(nextColTopU, nextColBotU, yNorm); float quadTopRightV = P.lerp(nextColTopV, nextColBotV, yNorm); float quadBotRightX = P.lerp(nextColTopX, nextColBotX, yNormNext); float quadBotRightY = P.lerp(nextColTopY, nextColBotY, yNormNext); float quadBotRightZ = P.lerp(nextColTopZ, nextColBotZ, yNormNext); float quadBotRightU = P.lerp(nextColTopU, nextColBotU, yNormNext); float quadBotRightV = P.lerp(nextColTopV, nextColBotV, yNormNext); float quadBotLeftX = P.lerp(colTopX, colBotX, yNormNext); float quadBotLeftY = P.lerp(colTopY, colBotY, yNormNext); float quadBotLeftZ = P.lerp(colTopZ, colBotZ, yNormNext); float quadBotLeftU = P.lerp(colTopU, colBotU, yNormNext); float quadBotLeftV = P.lerp(colTopV, colBotV, yNormNext); // draw subdivided quads pg.vertex(quadTopLeftX, quadTopLeftY, quadTopLeftZ, quadTopLeftU, quadTopLeftV); pg.vertex(quadTopRightX, quadTopRightY, quadTopRightZ, quadTopRightU, quadTopRightV); pg.vertex(quadBotRightX, quadBotRightY, quadBotRightZ, quadBotRightU, quadBotRightV); pg.vertex(quadBotLeftX, quadBotLeftY, quadBotLeftZ, quadBotLeftU, quadBotLeftV); } } pg.endShape(P.CLOSE); }
Example 20
Source File: MappedQuad.java From haxademic with MIT License | 4 votes |
public void draw( PGraphics pg ) { if( _texture != null ) { if( _mappingStyle == MAP_STYLE_CONTAIN_TEXTURE ) { if( _mappingOrientation == 0 ) { pg.beginShape(PConstants.QUAD); pg.texture(_texture); pg.vertex(x1, y1, 0, 0, 0); pg.vertex(x2, y2, 0, _texture.width, 0); pg.vertex(x3, y3, 0, _texture.width, _texture.height); pg.vertex(x4, y4, 0, 0, _texture.height); pg.endShape(); } else if( _mappingOrientation == 1 ) { pg.vertex(x1, y1, 0, 0, 0); pg.vertex(x2, y2, 0, _texture.width, 0); pg.vertex(x3, y3, 0, _texture.width/2, _texture.height); } else if( _mappingOrientation == 2 ) { pg.vertex(x1, y1, 0, 0, _texture.height/2); pg.vertex(x2, y2, 0, _texture.width, 0); pg.vertex(x3, y3, 0, _texture.width, _texture.height); } else if( _mappingOrientation == 3 ) { pg.vertex(x1, y1, 0, 0, _texture.height); pg.vertex(x2, y2, 0, _texture.width/2, 0); pg.vertex(x3, y3, 0, _texture.width, _texture.height); } } else if( _mappingStyle == MAP_STYLE_MASK ) { pg.beginShape(PConstants.QUAD); pg.texture(_texture); // map the screen coordinates to the texture coordinates // crop to fill the mapped area with the current texture pg.vertex(x1, y1, 0, _maskRect[0].x, _maskRect[0].y); pg.vertex(x2, y2, 0, _maskRect[1].x, _maskRect[1].y); pg.vertex(x3, y3, 0, _maskRect[2].x, _maskRect[2].y); pg.vertex(x4, y4, 0, _maskRect[3].x, _maskRect[3].y); pg.endShape(); } else if( _mappingStyle == MAP_STYLE_CONTAIN_RANDOM_TEX_AREA ) { pg.beginShape(PConstants.QUAD); pg.texture(_texture); // map the polygon coordinates to the random sampling coordinates pg.vertex(x1, y1, 0, _randRect.x, _randRect.y); pg.vertex(x2, y2, 0, _randRect.x + _randRect.width, _randRect.y); pg.vertex(x3, y3, 0, _randRect.x + _randRect.width, _randRect.y + _randRect.height); pg.vertex(x4, y4, 0, _randRect.x, _randRect.y + _randRect.height); pg.endShape(); } else if( _mappingStyle == MAP_STYLE_EQ ) { pg.beginShape(PConstants.QUAD); pg.fill(pg.color(_color, P.constrain( AudioIn.audioFreq(_eqIndex) * 255, 0, 255 ))); pg.vertex(x1, y1, 0); pg.vertex(x2, y2, 0); pg.vertex(x3, y3, 0); pg.fill(pg.color(_color, P.constrain( AudioIn.audioFreq(_eqIndex) * 100, 0, 190 ))); pg.vertex(x4, y4, 0); pg.endShape(); } // flash fade overlay drawFlashFadeOverlay(pg); // overlay with gradient, oscillating from white to black over time float whiteFade = P.sin(P.p.frameCount / _gradientFadeDivisor); //P.constrain( AudioIn.getEqBand((_eqIndex)) * 200 * _isFlash, 0, 50 ); pg.noStroke(); pg.beginShape(PConstants.QUAD); pg.fill(255*whiteFade,fakeLightAlpha); pg.vertex(x2, y2, 0); pg.vertex(x3, y3, 0); pg.fill(255*whiteFade,0); pg.vertex(x4, y4, 0); pg.vertex(x1, y1, 0); pg.endShape(); } // show debug info // pg.fill(255); // pg.textSize(20); // pg.text(_mappingStyle+"", _centerX, _centerY); }