Java Code Examples for processing.core.PGraphics#pop()

The following examples show how to use processing.core.PGraphics#pop() . 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: WashHands.java    From haxademic with MIT License 6 votes vote down vote up
public void update(PGraphics pg) {
	pg.push();
	pg.translate(pg.width * x, pg.height * y, 0);	// -0.25f   -0.33f
	if(FrameLoop.isTick()) {
		if(FrameLoop.curTick() == tickShow) wordWashEase.setInc(0.07f).setTarget(1);
		if(FrameLoop.curTick() == tickShow + 4) wordWashEase.setInc(0.04f).setTarget(0);
		if(tickShow == 4 && FrameLoop.curTick() % 8 == 0)  wordWashEase.setInc(0.04f).setTarget(0);
	}
	wordWashEase.update();
	float easedProgress = Penner.easeInOutExpo(wordWashEase.value());
	pg.rotateY(rotY + FrameLoop.osc(0.125f, -0.2f, 0.2f));  // 0.4f
	if(tickShow != 4) pg.rotateX(rotX + FrameLoop.osc(0.225f, -0.05f, 0.05f));  // -0.1f
	else pg.rotateX(rotX*1.5f);
	pg.scale(easedProgress);
	pg.shape(wordWash);
	pg.pop();
}
 
Example 2
Source File: PG.java    From haxademic with MIT License 6 votes vote down vote up
public static void drawStrokedRect(PGraphics pg, float w, float h, float strokeWeight, int colorBg, int colorStroke) {
	int prevRectMode = pg.rectMode;
	pg.push();
	
	// make sure rect stroke is drawing from the same top left as rect bg
	if(prevRectMode == PConstants.CENTER) pg.translate(P.round(-w/2), P.round(-h/2));
	pg.rectMode(PConstants.CORNER);
	
	// rect bg
	pg.noStroke();
	pg.fill(colorBg);
	pg.rect(0, 0, w, h);
	
	// pixel-perfect stroke by drawing 4 rects
	pg.fill(colorStroke);
	pg.rect(0, 0, w, strokeWeight);					// top
	pg.rect(0, h - strokeWeight, w, strokeWeight);	// bottom
	pg.rect(0, 0, strokeWeight, h);					// left
	pg.rect(w - strokeWeight, 0, strokeWeight, h);	// right
	pg.rectMode(prevRectMode);						// reset rectMode to whatever it was before

	pg.pop();
}
 
Example 3
Source File: Demo_MultichannelAudio_BeadsJack.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	// draw
	pg.push();
	pg.noFill();
	pg.stroke(0, 255, 0);
	PG.setDrawCenter(pg);
	PG.setCenterScreen(pg);
	pg.ellipse(position.x, position.y, 20, 20);
	pg.pop();
	
	// set gains
	for (int i = 0; i < outputs; i++) {
		// get dist to speaker
		PVector speakerPos = stage.getSpeaker(i).position();
		float dist = speakerPos.dist(position);
		float distToGain = P.map(dist, 0, stage.radius() * 2, 1, 0);
		distToGain = P.constrain(distToGain, 0, 1);
		gains[i].setGain(distToGain);
		
		// draw debug to speakers
		pg.push();
		pg.noFill();
		pg.stroke(0, 255 * distToGain, 0);
		PG.setDrawCenter(pg);
		PG.setCenterScreen(pg);
		pg.line(position.x, position.y, speakerPos.x, speakerPos.y);
		float midX = (position.x + speakerPos.x) / 2f;
		float midY = (position.y + speakerPos.y) / 2f;
		pg.text(distToGain, midX, midY);
		pg.pop();
	}
}
 
Example 4
Source File: Demo_MultichannelAudio_BeadsJack.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	// draw stage
	pg.push();
	pg.noFill();
	pg.stroke(255);
	PG.setDrawCenter(pg);
	PG.setCenterScreen(pg);
	pg.ellipse(0, 0, radius * 2, radius * 2);
	pg.pop();
	
	// draw speakers
	for (int i = 0; i < numSpeakers; i++) {
		speakers[i].update(pg);
	}
}
 
Example 5
Source File: Demo_MultichannelAudio_BeadsJack.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	// draw stage
	pg.push();
	pg.noFill();
	pg.stroke(0, 0, 255);
	PG.setDrawCenter(pg);
	PG.setCenterScreen(pg);
	pg.ellipse(position.x, position.y, 30, 30);
	pg.pop();
}
 
Example 6
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawTexturedLine(PGraphics pg, PImage texture, float xStart, float yStart, float xEnd, float yEnd, int color, float thickness, float texOffset, float cornerRadius) {
	// calc textured rectangle rotation * distance
	float startToEndAngle = MathUtil.getRadiansToTarget(xStart, yStart, xEnd, yEnd);
	float dist = MathUtil.getDistance(xStart, yStart, xEnd, yEnd);
	float thicknessHalf = thickness/2f;
	float textureHeightHalf = texture.height/2f;
	
	// set context
	OpenGLUtil.setTextureRepeat(pg);
	pg.push();
	pg.translate(xStart, yStart);
	pg.rotate(startToEndAngle);
	
	// draw textured rect
	pg.noStroke();
	pg.beginShape();
	pg.texture(texture);
	pg.textureMode(P.IMAGE);
	pg.tint(color);
	if(cornerRadius <= 0) {
		pg.vertex(0, -thicknessHalf, 0, texOffset, 0);
		pg.vertex(dist, -thicknessHalf, 0, texOffset + dist, 0);
		pg.vertex(dist, thicknessHalf, 0, texOffset + dist, texture.height);
		pg.vertex(0, thicknessHalf, 0, texOffset, texture.height);
	} else {
		// diamond shape, left/center, clockwise to right/center
		pg.vertex(0, 0, 0, 									texOffset, textureHeightHalf);
		pg.vertex(cornerRadius, -thicknessHalf, 0, 			texOffset + cornerRadius, 0);
		pg.vertex(dist - cornerRadius, -thicknessHalf, 0, 	texOffset + dist - cornerRadius, 0);
		// right/center, clockwise to left/center
		pg.vertex(dist, 0, 0, 								texOffset + dist, textureHeightHalf);
		pg.vertex(dist - cornerRadius, thicknessHalf, 0, 	texOffset + dist - cornerRadius, texture.height);
		pg.vertex(cornerRadius, thicknessHalf, 0, 			texOffset + cornerRadius, texture.height);
	}
	pg.endShape();
	pg.noTint();
	pg.pop();
}
 
Example 7
Source File: LightBar.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawNumberValue(PGraphics pg, int val) {
	// channel info text
	pg.push();
	pg.translate(0, 0);
	pg.fill(255);
	pg.noStroke();
	float ellipseW = (val > 99) ? 30 : 20;	// make wider for 3 digits
	pg.ellipse(midPoint.x, midPoint.y, ellipseW, 20);

	PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, 12);
	FontCacher.setFontOnContext(pg, font, P.p.color(0), 1f, PTextAlign.CENTER, PTextAlign.CENTER);
	pg.text(val+"", midPoint.x, midPoint.y - 2, 30, 20);
	pg.pop();

}
 
Example 8
Source File: LightBar.java    From haxademic with MIT License 4 votes vote down vote up
public void update(PGraphics pg, int index) {
	// update midpoint
	midPoint.set(point1);
	midPoint.lerp(point2, 0.5f);
	
	// draw
	if(active) {
		// draw enclosing circle to highlight tube
		float highlightSize = point1.dist(point2) + 50;
		pg.noFill();
		pg.strokeWeight(1);
		pg.stroke(0, 255, 0);
		pg.ellipse(midPoint.x, midPoint.y, highlightSize, highlightSize);
		
		// flash color
		int rainbow = P.p.color(
				127 + 127 * P.sin(P.p.frameCount * 0.1f),
				127 + 127 * P.sin(P.p.frameCount * 0.15f),
				127 + 127 * P.sin(P.p.frameCount * 0.225f));
		dmxFixture.color().setCurrentInt((P.p.frameCount % 16 < 8) ? rainbow : P.p.color(0));
		// dmxFixture.color().setCurrentInt(0xffff0000);
	}
	
	// draw light
	pg.noStroke();
	pg.fill(dmxFixture.color().colorInt());
	pg.push();
	pg.translate(midPoint.x, midPoint.y);
	pg.rotate(MathUtil.getRadiansToTarget(point2.x, point2.y, point1.x, point1.y));
	pg.rect(0, 0, point1.dist(point2), 5);
	pg.pop();
	
	// small circular ends
	pg.ellipse(point1.x, point1.y, 3, 3);
	pg.ellipse(point2.x, point2.y, 3, 3);
	
	// show text labels overlay
	if(P.store.getBoolean(DMXEditor.SHOW_DMX_CHANNELS)) {
		drawNumberValue(pg, dmxChannel);
	}
	if(P.store.getBoolean(DMXEditor.SHOW_LIGHT_INDEX)) {
		drawNumberValue(pg, index);
	}
}