Java Code Examples for processing.core.PApplet#pushStyle()
The following examples show how to use
processing.core.PApplet#pushStyle() .
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: 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 2
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(); }