Java Code Examples for processing.core.PApplet#pushMatrix()
The following examples show how to use
processing.core.PApplet#pushMatrix() .
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: DrawToxiMesh.java From haxademic with MIT License | 5 votes |
public static void drawPointsWithAudio( PApplet p, WETriangleMesh mesh, AudioInputWrapper audioData, float spectrumFaceRatio, float pointSize, TColor fillColor, TColor strokeColor, float baseAlpha ) { p.rectMode( P.CENTER ); int faceIndex = 0; int color = fillColor.toARGB(); Face f; float alpha; baseAlpha = baseAlpha * 255; p.noStroke(); for (Iterator<Face> i = mesh.faces.iterator(); i.hasNext();) { if( faceIndex % 2 == 0 ) { // set colors alpha = audioData.getFFT().spectrum[(int)(faceIndex/spectrumFaceRatio) % 512] * 1.3f; p.fill( color, baseAlpha + alpha * 255 ); p.pushMatrix(); f = (Face) i.next(); Vec3D center = f.getCentroid(); p.translate( center.x, center.y, center.z ); p.rotateX( f.normal.x ); p.rotateY( f.normal.y ); p.rotateZ( f.normal.z ); p.rect( 0, 0, pointSize + pointSize * alpha, pointSize + pointSize * alpha ); p.popMatrix(); } faceIndex ++; } }
Example 2
Source File: KinectWrapperV2.java From haxademic with MIT License | 5 votes |
public void drawPointCloudForRect( PApplet p, boolean mirrored, int pixelSkip, float alpha, float scale, float depthClose, float depthFar, int top, int right, int bottom, int left ) { p.pushMatrix(); // Translate and rotate int curZ; // Scale up by 200 float scaleFactor = scale; p.noStroke(); for (int x = left; x < right; x += pixelSkip) { for (int y = top; y < bottom; y += pixelSkip) { curZ = getDepthAt(x, y); // draw a point within the specified depth range if( curZ > depthClose && curZ < depthFar ) { p.fill( 255, alpha * 255f ); } else { p.fill( 255, 0, 0, alpha * 255f ); } p.pushMatrix(); p.translate( x * scaleFactor, y * scaleFactor, scaleFactor * curZ/40f ); // Draw a point p.point(0, 0); p.rect(0, 0, 4, 4); p.popMatrix(); } } p.popMatrix(); }
Example 3
Source File: KinectWrapperV1.java From haxademic with MIT License | 5 votes |
public void drawPointCloudForRect( PApplet p, boolean mirrored, int pixelSkip, float alpha, float scale, float depthClose, float depthFar, int top, int right, int bottom, int left ) { p.pushMatrix(); // Translate and rotate int curZ; // Scale up by 200 float scaleFactor = scale; p.noStroke(); for (int x = left; x < right; x += pixelSkip) { for (int y = top; y < bottom; y += pixelSkip) { curZ = getDepthAt(x, y); // draw a point within the specified depth range if( curZ > depthClose && curZ < depthFar ) { p.fill( 255, alpha * 255f ); } else { p.fill( 255, 0, 0, alpha * 255f ); } p.pushMatrix(); p.translate( x * scaleFactor, y * scaleFactor, scaleFactor * curZ/40f ); // Draw a point p.point(0, 0); p.rect(0, 0, 4, 4); p.popMatrix(); } } p.popMatrix(); }
Example 4
Source File: ConcentricPolygonsLast.java From haxademic with MIT License | 4 votes |
public void drawDisc( PApplet p, float radius, float innerRadius, int numSegments, float offsetRads, float childDistAmp, int level, float x, float y ) { p.pushMatrix(); float segmentRads = P.TWO_PI / numSegments; // float halfThickness = lineWeight.value() / 2f; float leveActiveAmp = (level < 20) ? levelsActive[level].value() : 0; float nextRadius = radius * iterateShrink.value() * leveActiveAmp; float nextInnerRadius = innerRadius * iterateShrink.value() * leveActiveAmp; nextInnerRadius = nextRadius - lineWeight.value() * leveActiveAmp; offsetRads = (offsetRads == 0) ? (segmentRads / 2f) * offsetRotation.value() : 0; if(level < 1) offsetRads = 0; for( int i = 0; i < numSegments; i++ ) { // calc vertex float curRads = startRads + i * segmentRads + offsetRads; float nextRads = startRads + (i + 1) * segmentRads + offsetRads; // draw polygon mesh p.beginShape(P.TRIANGLES); p.vertex( P.cos( curRads ) * innerRadius, P.sin( curRads ) * innerRadius ); p.vertex( P.cos( curRads ) * radius, P.sin( curRads ) * radius ); p.vertex( P.cos( nextRads ) * radius, P.sin( nextRads ) * radius ); p.vertex( P.cos( curRads ) * innerRadius, P.sin( curRads ) * innerRadius ); p.vertex( P.cos( nextRads ) * innerRadius, P.sin( nextRads ) * innerRadius ); p.vertex( P.cos( nextRads ) * radius, P.sin( nextRads ) * radius ); p.endShape(); // update analysis numVertices += 6; minY = P.min(minY, y + P.sin( curRads ) * radius); maxY = P.max(maxY, y + P.sin( curRads ) * radius); // draw radial sticks if(radialConnections.value() > 0 && level < 99) { p.pushStyle(); p.stroke(255); p.strokeWeight(lineWeight.value() * radialConnections.value()); p.line(0, 0, P.cos( curRads ) * innerRadius, P.sin( curRads ) * innerRadius); p.popStyle(); } // draw circle if(circleRadius.value() > 0.0f && (level == circleLevelDisplay.target() || circleLevelDisplay.target() == 0) && level < 99) { float circleR = radius * circleRadius.value(); float circleInnerR = circleR - lineWeight.value() / 2f; if((numVertices < 300000 || RENDERING == true) && circleR > 1) drawDisc(p, circleR, circleInnerR, circleResolution, offsetRads, 999, 999, x, y); } // draw children if(level < maxLevels.target() && radius > 1) { // draw child polygon at vertices float radiusFromParent = (radius - ((radius - innerRadius))); radiusFromParent *= childDistAmp; float xAdd = P.cos( curRads ) * radiusFromParent; float yAdd = P.sin( curRads ) * radiusFromParent; p.pushMatrix(); p.translate(xAdd, yAdd); // recursion makes this additive if(numVertices < 300000 || RENDERING == true) drawDisc(p, nextRadius, nextInnerRadius, numSegments, offsetRads, childDistAmp, level + 1, x + xAdd, y + yAdd); p.popMatrix(); // draw stick from parent to child // if(radialConnections.value() > 0 && level < 99) { // p.pushStyle(); // p.stroke(255); // p.strokeWeight(lineWeight.value() * radialConnections.value()); // p.line(0, 0, xAdd, yAdd); // p.popStyle(); // } } } p.popMatrix(); }
Example 5
Source File: ConcentricPolygonsEased.java From haxademic with MIT License | 4 votes |
public void drawPolygon( PApplet p, float radius, float innerRadius, int numSegments, float offsetRads, float childDistAmp, int level, float x, float y ) { p.pushMatrix(); float segmentRads = P.TWO_PI / numSegments; // float halfThickness = lineWeight.value() / 2f; float leveActiveAmp = (level < 20) ? levelsActive[level].value() : 0; float nextRadius = radius * iterateShrink.value() * leveActiveAmp; float nextInnerRadius = innerRadius * iterateShrink.value() * leveActiveAmp; nextInnerRadius = nextRadius - lineWeight.value() * leveActiveAmp; offsetRads = (offsetRads == 0) ? (segmentRads / 2f) * offsetRotation.value() : 0; if(level < 1) offsetRads = 0; for( int i = 0; i < numSegments; i++ ) { // calc vertex float curRads = startRads + i * segmentRads + offsetRads; float nextRads = startRads + (i + 1) * segmentRads + offsetRads; // draw polygon mesh p.beginShape(P.TRIANGLES); p.vertex( P.cos( curRads ) * innerRadius, P.sin( curRads ) * innerRadius ); p.vertex( P.cos( curRads ) * radius, P.sin( curRads ) * radius ); p.vertex( P.cos( nextRads ) * radius, P.sin( nextRads ) * radius ); p.vertex( P.cos( curRads ) * innerRadius, P.sin( curRads ) * innerRadius ); p.vertex( P.cos( nextRads ) * innerRadius, P.sin( nextRads ) * innerRadius ); p.vertex( P.cos( nextRads ) * radius, P.sin( nextRads ) * radius ); p.endShape(); // update analysis numVertices += 6; minY = P.min(minY, y + P.sin( curRads ) * radius); maxY = P.max(maxY, y + P.sin( curRads ) * radius); // draw circles at vertices if(level < maxLevels.target() - 1) { if(circleRadius.value() > 0.0f && (level == circleLevelDisplay.target() || circleLevelDisplay.target() == 0) && level < 99) { float circleR = radius * circleRadius.value(); float circleInnerR = circleR - lineWeight.value() / 2f; p.pushMatrix(); p.translate(P.cos( curRads ) * innerRadius, P.sin( curRads ) * innerRadius); if(circleR > 1) drawPolygon(p, circleR, circleInnerR, circleResolution, offsetRads, 999, 999, x, y); p.popMatrix(); } } // draw radial sticks if(radialConnections.value() > 0 && level < 99) { p.pushStyle(); p.stroke(255); p.strokeWeight(lineWeight.value() * radialConnections.value()); p.line(0, 0, P.cos( curRads ) * innerRadius, P.sin( curRads ) * innerRadius); p.popStyle(); } // draw children if(level < maxLevels.target() && radius > 1) { // draw child polygon at vertices float radiusFromParent = (radius - ((radius - innerRadius))); radiusFromParent *= childDistAmp; float xAdd = P.cos( curRads ) * radiusFromParent; float yAdd = P.sin( curRads ) * radiusFromParent; p.pushMatrix(); p.translate(xAdd, yAdd); // recursion makes this additive drawPolygon(p, nextRadius, nextInnerRadius, numSegments, offsetRads, childDistAmp, level + 1, x + xAdd, y + yAdd); p.popMatrix(); // draw stick from parent to child // if(radialConnections.value() > 0 && level < 99) { // p.pushStyle(); // p.stroke(255); // p.strokeWeight(lineWeight.value() * radialConnections.value()); // p.line(0, 0, xAdd, yAdd); // p.popStyle(); // } } // draw circle from center of shape // if(circleRadius.value() > 0.0f && (level == circleLevelDisplay.target() || circleLevelDisplay.target() == 0) && level < 99) { // float circleR = radius * circleRadius.value(); // float circleInnerR = circleR - lineWeight.value() / 2f; // if(circleR > 1) drawPolygon(p, circleR, circleInnerR, circleResolution, offsetRads, 999, 999, x, y); // } } p.popMatrix(); }