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

The following examples show how to use processing.core.PGraphics#translate() . 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: BlindSpotColored.java    From haxademic with MIT License 6 votes vote down vote up
protected void builtGradientTextureLoop() {
		int textureW = p.width * 4;
		int textureH = p.height * 1;
		int gradientW = textureW / 4;
		PGraphics img = p.createGraphics(textureW, textureH, P.P2D);
		img.smooth(8);
		tickerFXBuffer = p.createGraphics(textureW, textureH, P.P2D);
		tickerFXBuffer.smooth(8);
		img.beginDraw();
		img.noStroke();
		img.translate(gradientW / 2, textureH/2);
		Gradients.linear(img, gradientW, textureH, COLOR_1, COLOR_3);
		img.translate(gradientW, 0);
		Gradients.linear(img, gradientW, textureH, COLOR_3, COLOR_2);
		img.translate(gradientW, 0);
		Gradients.linear(img, gradientW, textureH, COLOR_2, COLOR_4);
		img.translate(gradientW, 0);
		Gradients.linear(img, gradientW, textureH, COLOR_4, COLOR_1);
		img.endDraw();
		BlurHFilter.instance(p).setBlurByPercent(0.75f, img.width);
		BlurHFilter.instance(p).applyTo(img);
//		BlurHFilter.instance(p).applyTo(img);
//		BlurHFilter.instance(p).applyTo(img);
		
		ticker = new TickerScroller(img, p.color(255), textureW, textureH, (float)textureW / (float)frames);
	}
 
Example 2
Source File: WashHands.java    From haxademic with MIT License 6 votes vote down vote up
public void update(PGraphics pg) {
			if(available()) return;
			
			pg.sphereDetail(6);
			
			// 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, pos.z);
			pg.rotateY(rotationMin);
			pg.fill(color);
			pg.box(curSize, curSize, curSize);
//			pg.sphere(curSize);
			pg.fill(255);
			pg.popMatrix();
		}
 
Example 3
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 4
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 5
Source File: Particle3d.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	if(available()) return;
	
	// update position
	if(gravity.mag() > 0) speed.add(gravity);
	if(acceleration != 1) speed.mult(acceleration);
	pos.add(speed);
	rotation.add(rotationSpeed);
	
	// update size
	sizeProgress.update();
	float curSize = size * Penner.easeOutSine(sizeProgress.value());
	if(sizeProgress.value() == 1) sizeProgress.setTarget(0);
	
	// draw image
	pg.pushMatrix();
	pg.translate(pos.x, pos.y, pos.z);
	pg.rotateX(rotation.x);
	pg.rotateY(rotation.y);
	pg.rotateZ(rotation.z);
	pg.fill(color);
	if(customShape != null) {
		pg.pushMatrix();
		pg.scale(Penner.easeOutExpo(sizeProgress.value()) * curSize / customShape.getHeight());
		pg.shape(customShape);
		pg.popMatrix();
	} else {
		if(isSphere) {
			pg.sphere(curSize/2f);
		} else {
			pg.box(curSize, curSize, curSize);
		}
	}
	pg.fill(255);
	pg.popMatrix();
}
 
Example 6
Source File: ImageSequenceMovieClip.java    From haxademic with MIT License 5 votes vote down vote up
public void drawToPGraphics(PGraphics pg, float x, float y, float scale) {
	pg.pushMatrix();
	pg.translate(x, y);
	if(isFlipped == true) pg.scale(-1, 1);
	pg.image(image(), 0, 0, image().width * scale, image().height * scale);
	pg.popMatrix();
}
 
Example 7
Source File: ImageUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static PGraphics imageToGraphicsWithPadding(PImage img, float fillAmount) {
	PGraphics image = ImageUtil.imageToGraphics(img);
	image.beginDraw();
	PG.setDrawCenter(image);
	image.clear();
	image.translate(image.width/2, image.height/2);
	image.image(img, 0, 0, img.width * fillAmount, img.height * fillAmount);
	image.endDraw();
	return image;
}
 
Example 8
Source File: SvgImageRedrawCollections.java    From haxademic with MIT License 5 votes vote down vote up
public void draw(PGraphics canvas, float x, float y, float drawSize) {
	if(scale < 1.0f) {
		if(isWhite) {
			canvas.shape(_whiteDot.shape, x, y, drawSize, drawSize);
		} else {
			canvas.shape(_blackDot.shape, x, y, drawSize, drawSize);
		}
	}
	canvas.pushMatrix();
	canvas.translate(x, y);
	canvas.shape(shape, 0, 0, drawSize * scale, drawSize * scale);
	canvas.popMatrix();
}
 
Example 9
Source File: StrokeText.java    From haxademic with MIT License 5 votes vote down vote up
public static void draw(PGraphics pg, String str, float x, float y, float w, float h, int strokeColor, int fillColor, float thickness, int resolution) {
	// translate
	pg.pushMatrix();
	pg.translate(x, y);
	
	// draw text around in a circle 
	pg.fill(strokeColor);
	float segmentRads = P.TWO_PI / resolution;
	for (int i = 0; i < resolution; i++) {
		float outlineX = P.cos(segmentRads * i);
		float outlineY = P.sin(segmentRads * i);
		if(w == -1) {
			pg.text(str, thickness * outlineX, thickness * outlineY);
		} else {
			pg.text(str, thickness * outlineX, thickness * outlineY, w, h);
		}
	}
	
	// fill in center
	pg.fill(fillColor);
	if(w == -1) {
		pg.text(str, 0, 0);
	} else {
		pg.text(str, 0, 0, w, h);
	}
	
	// pop
	pg.popMatrix();
}
 
Example 10
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 11
Source File: IDepthCamera.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawPointCloudForRect(PGraphics pg, IDepthCamera camera, boolean mirrored, int pixelSkip, float alpha, float scale, float depthClose, float depthFar, int top, int right, int bottom, int left ) {
	pg.pushMatrix();

	// Translate and rotate
	int curZ;
	
	// Scale up by 200
	float scaleFactor = scale;
	
	pg.noStroke();
	
	for (int x = left; x < right; x += pixelSkip) {
		for (int y = top; y < bottom; y += pixelSkip) {
			curZ = camera.getDepthAt(x, y);
			// draw a point within the specified depth range
			if( curZ > depthClose && curZ < depthFar ) {
				pg.fill( 255, alpha * 255f );
			} else {
				pg.fill( 255, 0, 0, alpha * 255f );
			}
			pg.pushMatrix();
			pg.translate( x * scaleFactor, y * scaleFactor, scaleFactor * curZ/40f );
			// Draw a point
			pg.point(0, 0);
			pg.rect(0, 0, 4, 4);
			pg.popMatrix();
		}
	}
	pg.popMatrix();
}
 
Example 12
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 13
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 14
Source File: Demo_DropShadowBlur.java    From haxademic with MIT License 5 votes vote down vote up
public PGraphics imageToImageWithPadding(PImage img, float scaleCanvasUp) {
	PGraphics pg = PG.newPG(P.ceil((float) img.width * scaleCanvasUp), P.ceil((float) img.height * scaleCanvasUp));
	pg.beginDraw();
	PG.setDrawCenter(pg);
	pg.clear();
	pg.translate(pg.width/2, pg.height/2);
	pg.image(img, 0, 0);
	pg.endDraw();
	return pg;
}
 
Example 15
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 16
Source File: BlobsForFun.java    From haxademic with MIT License 5 votes vote down vote up
protected void builtGradientTextureLoop() {
	int textureW = p.width * 4;
	int textureH = p.height;
	int gradientW = textureW / 6;
	PGraphics img = p.createGraphics(textureW, textureH, P.P2D);
	img.smooth(8);
	tickerFXBuffer = p.createGraphics(textureW, textureH, P.P2D);
	tickerFXBuffer.smooth(8);
	img.beginDraw();
	img.noStroke();
	img.translate(gradientW / 2, textureH/2);
	Gradients.linear(img, gradientW, textureH, COLOR_1, COLOR_2);
	img.translate(gradientW, 0);
	Gradients.linear(img, gradientW, textureH, COLOR_2, COLOR_3);
	img.translate(gradientW, 0);
	Gradients.linear(img, gradientW, textureH, COLOR_3, COLOR_4);
	img.translate(gradientW, 0);
	Gradients.linear(img, gradientW, textureH, COLOR_4, COLOR_5);
	img.translate(gradientW, 0);
	Gradients.linear(img, gradientW, textureH, COLOR_5, COLOR_6);
	img.translate(gradientW, 0);
	Gradients.linear(img, gradientW, textureH, COLOR_6, COLOR_1);
	img.endDraw();
	BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width);
	BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width);
	BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width);
	BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width);
	
	ticker = new TickerScroller(img, p.color(255), textureW, textureH, (float)textureW / (float)_frames);
}
 
Example 17
Source File: Demo_BackgroundGradientAndShadow.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawShape(PGraphics pg) {
	pg.noStroke();
	pg.pushMatrix();
	
	pg.translate(0, 180 * P.sin(FrameLoop.progressRads()));
	pg.rotateY(FrameLoop.progressRads());
	
	pg.box(400, 20, 50);
	pg.box(50, 20, 400);
	// PShapeUtil.drawTriangles(pg, obj, null, 1);
	
	pg.popMatrix();
}
 
Example 18
Source File: DebugView.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawTextLine(String textLine, boolean isTitle) {
	PGraphics pg = P.p.g;
	PG.setDrawCorner(pg);

	// set context
	pg.pushMatrix();
	pg.translate(controlX, controlY);
	
	// draw bg rect
	int fill = (isTitle) ? P.p.color(ColorsHax.TITLE_BG, BG_ALPHA) : P.p.color(ColorsHax.BUTTON_BG, BG_ALPHA);
	PG.drawStrokedRect(pg, IUIControl.controlW, controlH, 1, fill, ColorsHax.BUTTON_OUTLINE);

	// text label
	pg.fill(ColorsHax.BUTTON_TEXT);
	pg.text(textLine, IUIControl.TEXT_INDENT, 1f); // , IUIControl.controlW, controlH

	// if mouse hover, draw big afterwards
	if(!isTitle && CollisionUtil.rectangleContainsPoint(Mouse.x, Mouse.y, controlX, controlY, IUIControl.controlW, controlH)) {
		highlightedText = textLine;
	}
	
	// reset context
	pg.popMatrix();

	// move to next box
	controlY += controlH - 1;
	if(controlY > P.p.height - controlH) nextCol();
}
 
Example 19
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 20
Source File: GradientsBaseLayer2.java    From haxademic with MIT License 4 votes vote down vote up
protected void firstFrame() {
		int[] colors = new int[] {
				// superbowl: #0D131B
				ColorUtil.colorFromHex("#ff0D131B"),
				// team 1
//				ColorUtil.colorFromHex("#ff0B1630"),
//				ColorUtil.colorFromHex("#ffBB0022"),
//				ColorUtil.colorFromHex("#ff0B1630"),
//				ColorUtil.colorFromHex("#ffBB0022"),
				// team 2
//				ColorUtil.colorFromHex("#ff471D6C"),
//				ColorUtil.colorFromHex("#ffF5AB2C"),
//				ColorUtil.colorFromHex("#ff471D6C"),
//				ColorUtil.colorFromHex("#ffF5AB2C"),
				// team 3
				ColorUtil.colorFromHex("#ff9AAAA8"),
				ColorUtil.colorFromHex("#ff0E1210"),
				ColorUtil.colorFromHex("#ff9AAAA8"),
				ColorUtil.colorFromHex("#ff0E1210"),
//				// superbowl: #0D131B
				ColorUtil.colorFromHex("#ff0D131B"),
		};
		
		int gradientW = P.round(p.width * 0.25f);
		
		PGraphics img = p.createGraphics(gradientW * colors.length, p.height, P.P3D);
		img.smooth(8);
		
		img.beginDraw();
		img.noStroke();
		img.translate(gradientW/2, p.height/2);
		
		for (int i = 0; i < colors.length; i++) {
			Gradients.linear(img, gradientW, p.height, colors[i], colors[(i+1) % colors.length]);
			img.translate(gradientW, 0);
		}
		
		img.endDraw();
		
		// apply blur
		BlurHFilter.instance(p).setBlurByPercent(0.15f, img.width);
		for (int i = 0; i < 10; i++) BlurHFilter.instance(p).applyTo(img);
		
		// add to debug display
		DebugView.setTexture("gradient", img);
		
		// build ticker
		float tickerLoopSpeed = (float) img.width / (float) FRAMES;
		ticker = new TickerScroller(img, p.color(255), gradientW, p.height, tickerLoopSpeed);
	}