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

The following examples show how to use processing.core.PGraphics#rotate() . 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: GifRenderEllo025LoadingAnimationV3.java    From haxademic with MIT License 6 votes vote down vote up
public void drawGraphics(PGraphics pg) {
		
		float frameRadians = PConstants.TWO_PI / _frames;
		float percentComplete = ((float)(p.frameCount%_frames)/_frames);
//		float easedPercent = Penner.easeInOutExpo(percentComplete, 0, 1, 1);
//		float easedPercent = Penner.easeInOutQuart(percentComplete, 0, 1, 1);
		float easedPercent = Penner.easeInOutCubic(percentComplete, 0, 1, 1);

		float frameOsc = P.sin( PConstants.TWO_PI * percentComplete);
		float elloSize = (float)(p.width);
		
		PG.setDrawCenter(pg);
		pg.beginDraw();
		pg.clear();
		pg.background(255);
		pg.noStroke();

		pg.translate(pg.width/2, pg.height/2);
		float rotations = 2;
		pg.rotate(easedPercent * PConstants.TWO_PI * rotations);
		pg.shape(_logo, 0, 0, elloSize, elloSize);

		pg.endDraw();
	}
 
Example 2
Source File: BiglyText.java    From haxademic with MIT License 6 votes vote down vote up
public void drawGraphics( PGraphics pg ) {
//		if(p.frameCount == 1) p.background(255);
		pg.beginDraw();
		pg.clear();

//		pg.background(255);
		pg.noStroke();
		
		float frameRadians = PConstants.TWO_PI / _frames;
		float percentComplete = ((float)(p.frameCount%_frames)/_frames);
		float progressRads = percentComplete * P.TWO_PI;
		float easedPercent = Penner.easeInOutQuart(percentComplete, 0, 1, 1);

		
		// Bread!
		pg.translate(p.width/2, p.height/2);
		PG.setDrawCenter(pg);
		PG.setPImageAlpha(pg, 0.3f);
		pg.scale(0.9f + P.sin(progressRads) * 0.1f);
		pg.rotate(0.01f * P.sin(P.PI/2 + progressRads));
		pg.image(biglyImg, 0, 0);

		pg.endDraw();
	}
 
Example 3
Source File: Particle2d.java    From haxademic with MIT License 6 votes vote down vote up
public void update(PGraphics pg) {
	if(available(pg)) return;
	
	// update position
	speed.add(gravity);
	pos.add(speed);
	
	// update size
	sizeProgress.update();
	float curSize = size * Penner.easeOutExpo(sizeProgress.value());
	if(sizeProgress.value() == 1) sizeProgress.setTarget(0);
	
	// draw image
	pg.pushMatrix();
	pg.translate(pos.x, pos.y);
	pg.rotate(pos.z);
	pg.tint(color);
	pg.image(image, 0, 0, curSize, curSize);
	pg.tint(255);
	pg.popMatrix();
}
 
Example 4
Source File: Utility.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Rotates a PImage object by a given angle in radians.
 *
 * @param img PImage image to rotate.
 * @param angle Angle in radians.
 * @return new PImage object transformed.
 */
public static PImage rotateImage(PImage img, float angle) {
	PGraphics pg = applet.createGraphics((int) (img.width * 1.5), (int) (img.height * 1.5));

	pg.beginDraw();
	pg.clear();
	pg.imageMode(PApplet.CENTER);
	pg.translate(pg.width / 2, pg.height / 2);
	pg.rotate(angle);
	pg.image(img, 0, 0);
	pg.endDraw();

	return pg;
}
 
Example 5
Source File: Demo_MotionBlurPGraphics.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawGraphics( PGraphics pg ) {
	// redraw pgraphics grid
	PG.setDrawCenter(pg);
	pg.beginDraw();
	pg.clear();
	pg.stroke(0);
	pg.fill(255);
	pg.translate((p.frameCount * 3) % p.width, p.height/2);
	pg.rotate(p.frameCount * 0.1f);
	pg.rect(0, 0, 50, 50);
	pg.endDraw();
}
 
Example 6
Source File: Demo_FrameDifferenceShapesLauncher.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	if(available()) return;
	// update position
	gravity.x *= 0.97f;
	speed.add(gravity);
	pos.add(speed);
	rotation += gravity.z;
	// update size
	sizeProgress.update();
	float curSize = size * Penner.easeOutBack(sizeProgress.value());
	if(sizeProgress.value() == 1) sizeProgress.setTarget(0);
	// draw image or polygon
	if(image != null) {
		// draw image
		pg.pushMatrix();
		pg.translate(pos.x, pos.y);
		pg.rotate(rotation);
		pg.image(image, 0, 0, curSize * 2f, curSize * 2f);
		pg.popMatrix();
	} else {
		// draw shape
		float segmentRads = P.TWO_PI / vertices;
		pg.fill(color); // , 150);
		pg.stroke(255);
		pg.pushMatrix();
		pg.translate(pos.x, pos.y);
		pg.rotate(rotation);
		pg.beginShape(P.POLYGON);
		for(float i = 0; i <= vertices; i++) {
			pg.vertex(P.cos(segmentRads * i) * curSize, P.sin(segmentRads * i) * curSize);
		}
		pg.endShape();
		pg.popMatrix();
		// pg.rect(pos.x, pos.y, 2, 2);
	}
}
 
Example 7
Source File: ParticleSwirl.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	if(available(pg)) return;
	
	// update position
	radians += speed.x;
	radius += speed.y;
	speed.add(gravity);
	
	pos.set(
			pg.width/2 + P.cos(radians) * radius, 
			pg.height/2 + P.sin(radians) * radius, 
			pos.z + speed.z	// rotation
			);
	
	// update size
	sizeProgress.update();
	float curSize = size * Penner.easeOutExpo(sizeProgress.value());
	if(sizeProgress.value() == 1) sizeProgress.setTarget(0);
	
	// draw image
	pg.pushMatrix();
	pg.translate(pos.x, pos.y);
	pg.rotate(pos.z);
	pg.tint(color);
	pg.image(image, 0, 0, curSize, curSize);
	pg.tint(255);
	pg.popMatrix();
}
 
Example 8
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 9
Source File: PG.java    From haxademic with MIT License 5 votes vote down vote up
public static void rotateRedraw(PGraphics pg, float radians) {
	pg.beginDraw();
	PG.setDrawCenter(pg);
	pg.pushMatrix();
	PG.setCenterScreen(pg);
	pg.rotate(radians);
	pg.image(pg, 0, 0);
	pg.popMatrix();
	PG.setDrawCorner(pg);
	pg.endDraw();
}
 
Example 10
Source File: ImageUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawImageCropFill(PImage img, PGraphics dest, boolean cropFill, boolean rotate180, boolean openDestContext) {
	float ratioW = MathUtil.scaleToTarget(img.width, dest.width);
	float ratioH = MathUtil.scaleToTarget(img.height, dest.height);
	float scale = (ratioH < ratioW) ? ratioH : ratioW;			// letterbox
	if(cropFill) scale = (ratioH > ratioW) ? ratioH : ratioW;		// crop fill
	if(openDestContext) dest.beginDraw();
	dest.pushMatrix();
	PG.setDrawCenter(dest);
	dest.translate(dest.width/2, dest.height/2);
	if(rotate180) dest.rotate(P.PI);
	dest.image(img, 0, 0, img.width * scale, img.height * scale);
	PG.setDrawCorner(dest);
	dest.popMatrix();
	if(openDestContext) dest.endDraw();
}
 
Example 11
Source File: ImageUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawImageCropFillRotated90deg(PImage img, PGraphics dest, boolean cropFill, boolean positive, boolean openDestContext) {
	float ratioW = MathUtil.scaleToTarget(img.height, dest.width);
	float ratioH = MathUtil.scaleToTarget(img.width, dest.height);
	float scale = (ratioH < ratioW) ? ratioH : ratioW;				// letterbox
	if(cropFill) scale = (ratioH > ratioW) ? ratioH : ratioW;		// crop fill
	if(openDestContext) dest.beginDraw();
	PG.push(dest);
	PG.setDrawCenter(dest);
	PG.setCenterScreen(dest);
	dest.rotate(P.HALF_PI * ((positive) ? 1f : -1f));
	dest.image(img, 0, 0, img.width * scale, img.height * scale);
	PG.setDrawCorner(dest);
	PG.pop(dest);
	if(openDestContext) dest.endDraw();
}
 
Example 12
Source File: Demo_OpenGLUtil_setBlendModeAll.java    From haxademic with MIT License 4 votes vote down vote up
protected void drawApp() {
		DebugView.setValue("mouseControlled", mouseControlled);
		DebugView.setValue("drawBuffer", drawBuffer);
		
		p.background(0);
		PGraphics pg = (drawBuffer) ? buffer : p.g;
		
		// set context
		if(drawBuffer) pg.beginDraw();
		pg.background(0);
		pg.noStroke();
		PG.setDrawCenter(pg);

		// show presets or use spacebar to find new presets
		if(mouseControlled) loadPresetFromMouse(Mouse.xNorm);
		
		// draw under image
		ImageUtil.drawImageCropFill(DemoAssets.smallTexture(), pg, true);
		
		// set custom blend mode on context
		OpenGLUtil.setBlending( pg, true );
		OpenGLUtil.setBlendModeCustom(pg, GLBlendModes.blendFunctions[blendSrcIndex], GLBlendModes.blendFunctions[blendDestIndex], GLBlendModes.blendEquations[blendEquationIndex]);
//		GLBlendModes.setBlendModeFromPreset(pg, P.floor(Mouse.xNorm * GLBlendModes.presets.length));

		// draw shapes
		float numShapes = 100;
		for( float i=0; i < numShapes; i++ ) {
			float red = i/numShapes * 255f;
			float green = 255f - i/numShapes * 255f;
			float blue = 255f - i/numShapes * 255f;
			pg.fill(red, green, blue, 20);

			float radius = 180 + 26f * P.sin(i+p.frameCount*0.02f);
			float radians = ((i+p.frameCount*0.25f)/P.TWO_PI) * 0.5f;// * P.sin((i/10f+p.frameCount/10f));
			float xRot = P.sin(radians);
			float yRot = P.cos(radians);
			pg.pushMatrix();
			pg.translate(pg.width/2f + xRot * radius, pg.height/2f + yRot * radius);
			pg.rotate(-radians);
			pg.rect(0, 0, radius/3f, radius/3f);
			pg.popMatrix();
		}

		// draw over image
//		PG.setPImageAlpha(pg,  0.5f);
		ImageUtil.drawImageCropFill(DemoAssets.textureJupiter(), pg, true);
//		PG.resetPImageAlpha(pg);
		
		// reset blending to default
		OpenGLUtil.setBlending( pg, false );
		pg.endDraw();
		
		// draw buffer to screen
		if(drawBuffer) {
			PG.setDrawCorner(p);
			p.image(pg, 0, 0);
		}
	}
 
Example 13
Source File: Partycles.java    From haxademic with MIT License 4 votes vote down vote up
public void update(PGraphics pg) {
			if(available()) return;
			
			// update position
			gravity.x *= 0.97f;
			speed.add(gravity);
			pos.add(speed);
			rotation += gravity.z;
			
			// update size
			sizeProgress.update();
			float audioAmp = (1f + 1f * AudioIn.audioFreq(audioIndex));
			if(sizeProgress.value() == 1) shrink -= 0.01f;
			float curSize = (sizeProgress.value() == 1) ?
					size * shrink * audioAmp:
					size * Penner.easeOutQuad(sizeProgress.value()) * audioAmp;
//			if(sizeProgress.value() == 1) sizeProgress.setTarget(0);
			
			// draw image or polygon
			if(image != null) {
				// draw image
				pg.pushMatrix();
				pg.translate(pos.x, pos.y);
				pg.rotate(rotation);
				pg.tint(color);
				pg.image(image, 0, 0, curSize * 2f, curSize * 2f);
				pg.tint(255);
				pg.popMatrix();
			} else {
				// draw shape
				float segmentRads = P.TWO_PI / vertices;
				pg.fill(color); // , 150);
//				pg.stroke(255);
				pg.noStroke();
				pg.pushMatrix();
				pg.translate(pos.x, pos.y);
				pg.rotate(rotation);
				pg.beginShape(P.POLYGON);
				for(float i = 0; i <= vertices; i++) {
					pg.vertex(P.cos(segmentRads * i) * curSize, P.sin(segmentRads * i) * curSize);
				}
				pg.endShape();
				pg.popMatrix();
				// pg.rect(pos.x, pos.y, 2, 2);
			}
			pg.tint(255);
		}
 
Example 14
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);
	}
}