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

The following examples show how to use processing.core.PGraphics#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: 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 2
Source File: Shapes.java    From haxademic with MIT License 6 votes vote down vote up
public static void drawDisc( PGraphics p, float radius, float innerRadius, int numSegments ) {
	p.pushMatrix();
	
	float segmentRads = P.TWO_PI / numSegments;
	for( int i = 0; i < numSegments; i++ ) {
		p.beginShape(P.TRIANGLES);
		
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, 0 );
		p.vertex( P.cos( i * segmentRads ) * radius, P.sin( i * segmentRads ) * radius, 0 );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, 0 );
		
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, 0 );
		p.vertex( P.cos( (i + 1) * segmentRads ) * innerRadius, P.sin( (i + 1) * segmentRads ) * innerRadius, 0 );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, 0 );
		p.endShape();
	}
	
	p.popMatrix();
}
 
Example 3
Source File: ShaderSSAO.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawCubesInCircle(PGraphics pg) {
	// spin it
	pg.rotateZ(progressRads);

	// draw plane
	pg.fill(100);
	pg.rect(0, 0, p.width * 3, p.height * 3);

	float radius = pg.width * 0.2f;
	for (int i = 0; i < 14; i++) {
		pg.fill(200f + 55f * P.sin(i), 200f + 55f * P.cos(i * 2f), 200f + 55f * P.sin(i));
		pg.pushMatrix();
		pg.translate(radius * P.sin(i + progressRads), radius * P.cos(i + progressRads), 0);
		pg.rotateX(progressRads + i);
		pg.rotateY(progressRads + i);
		pg.box(pg.height * 0.2f);
		pg.popMatrix();
	}
}
 
Example 4
Source File: Gradients.java    From haxademic with MIT License 6 votes vote down vote up
public static void linear( PGraphics p, float width, float height, int colorStart, int colorStop )
{
	p.pushMatrix();
	
	float halfW = width/2;
	float halfH = height/2;
	
	p.beginShape();
	p.fill(colorStart);
	p.vertex(-halfW, -halfH);
	p.fill(colorStop);
	p.vertex(halfW, -halfH);
	p.fill(colorStop);
	p.vertex(halfW, halfH);
	p.fill(colorStart);
	p.vertex(-halfW, halfH);
	p.endShape(P.CLOSE);
	
	p.popMatrix();
}
 
Example 5
Source File: Gradients.java    From haxademic with MIT License 6 votes vote down vote up
public static void quad( PGraphics p, float width, float height, int colorTL, int colorTR, int colorBR, int colorBL )
{
	p.pushMatrix();
	
	float halfW = width/2;
	float halfH = height/2;
	
	p.beginShape();
	p.fill(colorTL);
	p.vertex(-halfW, -halfH);
	p.fill(colorTR);
	p.vertex(halfW, -halfH);
	p.fill(colorBR);
	p.vertex(halfW, halfH);
	p.fill(colorBL);
	p.vertex(-halfW, halfH);
	p.endShape(P.CLOSE);
	
	p.popMatrix();
}
 
Example 6
Source File: Gradients.java    From haxademic with MIT License 6 votes vote down vote up
public static void radial( PGraphics p, float width, float height, int colorInner, int colorOuter, int numSegments )
{
	p.pushMatrix();

	float halfW = width/2;
	float halfH = height/2;
	
	float segmentRadians = P.TWO_PI / numSegments;
	p.noStroke();
	for(float r=0; r < P.TWO_PI; r += segmentRadians) {
		float r2 = r + segmentRadians;
		p.beginShape();
		p.fill(colorInner);
		p.vertex(0,0);
		p.fill(colorOuter);
		p.vertex(P.sin(r) * halfW, P.cos(r) * halfH);
		p.vertex(P.sin(r2) * halfW, P.cos(r2) * halfH);
		p.endShape(P.CLOSE);
	}
	
	p.popMatrix();
}
 
Example 7
Source File: SlideCaption.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	showProgress.update();
	
	if(captionQueued != null && showProgress.value() == 0) {
		caption = captionQueued;
		captionQueued = null;
		showProgress.setTarget(1);	
	}
	
	if(caption != null) {
		PG.setDrawCorner(pg);
		pg.noStroke();
		
		// get eased y
		float easedProgress = Penner.easeInOutCubic(showProgress.value());
		float curY = pg.height - height * easedProgress;
		
		pg.pushMatrix();
		
		// draw bg
		pg.fill(0, 127);
		pg.rect(0, curY, pg.width, height); // curY

		// draw text
		// buffer.textLeading(font.getSize() * 0.75f);
		pg.fill(255);
		pg.textAlign(P.CENTER, P.CENTER);
		pg.textFont(font);
		pg.text(caption, textOffsetY * 5f, curY - textOffsetY, pg.width - 50, height);
		
		pg.popMatrix();
		PG.setDrawCenter(pg);
	}
}
 
Example 8
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 9
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 10
Source File: LeapRegion.java    From haxademic with MIT License 5 votes vote down vote up
public void drawDebug(PGraphics debugGraphics) {
	if( _blockColor == -1 ) return;
	
	// set box color for (in)active states
	debugGraphics.strokeWeight(5f);
	if(_isActive == true) {
		debugGraphics.stroke(_blockColor, 255);
		debugGraphics.noFill();
	} else {
		debugGraphics.stroke(255, 127);
		debugGraphics.noFill();
	}
	debugGraphics.pushMatrix();
	
	// move to center of box location & draw box
	debugGraphics.translate(P.lerp(_right, _left, 0.5f), P.lerp(_top, _bottom, 0.5f), -1f * P.lerp(_far, _near, 0.5f));
	debugGraphics.box(_right - _left, _top - _bottom, _far - _near);
	
	// draw text control values
	if(_isActive == true) {
		debugGraphics.noStroke();
		debugGraphics.fill(255);
		debugGraphics.textSize(24);
		debugGraphics.text(MathUtil.roundToPrecision(_controlX, 2)+", "+MathUtil.roundToPrecision(_controlY, 2)+", "+MathUtil.roundToPrecision(_controlZ, 2), -50, 0);
	}
	
	debugGraphics.popMatrix();
}
 
Example 11
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void cylinderBetween( PGraphics pg, PVector point1, PVector point2, int resolution, float radius, float radiusBot ) {
	pg.pushMatrix();
		
	// set orientation 
	OrientationUtil.setMidPoint(pg, point1, point2);
	OrientationUtil.setRotationTowards(pg, point1, point2);

	// draw box
	Shapes.drawCylinder(pg, resolution, radius, radiusBot, point1.dist(point2), false);

	pg.popMatrix(); 
}
 
Example 12
Source File: SlideTitle.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	showProgress.update();
	
	if(titleQueued != null && showProgress.value() == 0) {
		title = titleQueued;
		titleQueued = null;
		showProgress.setTarget(1);	
	}
	
	if(title != null) {
		PG.setDrawCorner(pg);
		pg.noStroke();
		
		// get eased y
		float easedProgress = Penner.easeInOutCubic(showProgress.value());
		
		pg.pushMatrix();
		
		// draw bg
		pg.fill(0, opacity * easedProgress);
		pg.rect(0, 0, pg.width, pg.height); 

		// draw text
		// buffer.textLeading(font.getSize() * 0.75f);
		pg.fill(255, 255 * easedProgress);
		pg.textAlign(P.CENTER, P.CENTER);
		pg.textFont(font);
		pg.text(title, 0, 0, pg.width, pg.height);
		
		pg.popMatrix();
		PG.setDrawCenter(pg);
	}
}
 
Example 13
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawStar( PGraphics p, float spikes, float outerrad, float innerradpercent, float h, float rot)
{
	p.pushMatrix();

	int pi;
	float futil;
	p.beginShape(P.TRIANGLE_STRIP);
	for(pi=0;pi<spikes+1;pi++)
	{
		p.vertex(0,0,h/2);
	    futil=(pi/spikes)  * P.TWO_PI;    //current angle 
	    p.vertex(  P.cos(futil+rot)*outerrad, P.sin(futil+rot)*outerrad, 0);
	    futil=futil+ (  (1/spikes)/2 *P.TWO_PI  );
	    p.vertex(  P.cos(futil+rot)*outerrad*innerradpercent, P.sin(futil+rot)*outerrad*innerradpercent, 0);
	}
	p.endShape();
	p.beginShape(P.TRIANGLE_STRIP);
	for(pi=0;pi<spikes+1;pi++)
	{
		p.vertex(0,0,-h/2);
		futil=(pi/spikes)  * P.TWO_PI;    //current angle 
		p.vertex(  P.cos(futil+rot)*outerrad, P.sin(futil+rot)*outerrad, 0);
		futil=futil+ (  (1/spikes)/2 *P.TWO_PI  );
		p.vertex(  P.cos(futil+rot)*outerrad*innerradpercent, P.sin(futil+rot)*outerrad*innerradpercent, 0);
	}
	p.endShape();
	
	p.popMatrix();
}
 
Example 14
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 15
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 16
Source File: UISlider.java    From haxademic with MIT License 5 votes vote down vote up
public void draw(PGraphics pg) {
		pg.pushMatrix();
		PG.setDrawCorner(pg);
		
		// outline
		pg.noStroke();
		pg.fill(ColorsHax.BUTTON_OUTLINE);
		pg.rect(x, y, w, h);
		
		// background
		if(mouseHovered) pg.fill(ColorsHax.BUTTON_BG_HOVER);
		else pg.fill(ColorsHax.BUTTON_BG);
		pg.rect(x+1, y+1, w-2, h-2);
		
		// draw current value
		pg.noStroke();
		if(mousePressed) pg.fill(ColorsHax.WHITE, 180);
		else pg.fill(0, 127, 0);
//		else pg.fill(ColorsHax.WHITE, 120);
		float handleW = 4;
		float mappedX = P.map(value, valueMin, valueMax, x+1, x + w - handleW);
		pg.rect(mappedX - 0.5f, y+1, handleW, h-2);
		
		// text label
		IUIControl.setFont(pg);
		pg.fill(ColorsHax.BUTTON_TEXT);
		pg.text(id + ": " + MathUtil.roundToPrecision(value, 5), P.round(x + TEXT_INDENT), y, w, h*2);
		uiRect.setBounds(x, y, w, h);
		
		// set active if drawing
		activeTime = P.p.millis();
		pg.popMatrix();
	}
 
Example 17
Source File: SlideImage.java    From haxademic with MIT License 4 votes vote down vote up
protected void draw(PGraphics buffer) {
	activeFrames++;

	buffer.pushMatrix();

	// update position
	if(state == SlideState.FADE_IN) {
		curX = startOffset.x * (float) buffer.width * easeInProgress(1f - fadeInProgress.value());	// ease in since progress is reversed
		curY = startOffset.y * (float) buffer.height * easeInProgress(1f - fadeInProgress.value());
	} else if(state == SlideState.FADE_OUT) {
		if(fadesAway == true) {
			fadeOutSpeedMult.update();
			curZ -= speedZ * fadeOutSpeedMult.value();
		}
		curX = endOffset.x * (float) buffer.width * easeInProgress(fadeOutProgress.value());
		curY = endOffset.y * (float) buffer.height * easeInProgress(fadeOutProgress.value());
	} else {
		curX = 0;
		curY = 0;
	}
	buffer.translate(curX, curY, curZ);

	// fade to black
	float curFade = 1f;
	if((state == SlideState.FADE_OUT && fadesOut == true) || state == SlideState.REMOVE) curFade = 1f - fadeOutProgress.value();
	if(state == SlideState.FADE_IN && fadesIn == true) curFade = fadeInProgress.value();
	buffer.tint( 255, curFade * 255 );

	// draw image
	if(cropOffset != null) {
		// image size
		float imageW = cropOffset[2];
		float imageH = cropOffset[3];
		if(state == SlideState.FADE_IN && scalesUp == true) {
			imageW *= easeOutProgress(fadeInProgress.value());
			imageH *= easeOutProgress(fadeInProgress.value());
		}
		if(state == SlideState.FADE_OUT && scalesDown == true) {
			imageW *= easeInProgress(1f - fadeOutProgress.value());
			imageH *= easeInProgress(1f - fadeOutProgress.value());
		}

		if(image != null) buffer.image(image, 0, 0, imageW, imageH);
		if(movie != null) buffer.image(movie, 0, 0, imageW, imageH);
		if(gif != null) buffer.image(gif, 0, 0, imageW, imageH);
		if(imageSequence != null) {
			PImage frameImg = (imageSequence.isPlaying() == true) ? imageSequence.image() : imageSequence.getFrame(imageSequence.numImages() - 1);
			buffer.image(frameImg, 0, 0, imageW, imageH);
		}
	}
	PG.resetPImageAlpha(buffer);

	buffer.popMatrix();
}
 
Example 18
Source File: Interphase.java    From haxademic with MIT License 4 votes vote down vote up
protected void drawSequencer(PGraphics pg) {
		float spacing = 40;
		float boxSize = 25;
		float startx = (spacing * sequencers.length) / -2f + boxSize/2;
		float startY = (spacing * NUM_STEPS) / -2f + boxSize/2;
		pg.beginDraw();
		PG.setCenterScreen(pg);
		PG.basicCameraFromMouse(pg, 0.1f);
		PG.setBetterLights(pg);
		PG.setDrawCenter(pg);
		
		// draw cubes
		for (int x = 0; x < sequencers.length; x++) {
			for (int y = 0; y < NUM_STEPS; y++) {
//				float value = (sequencers[x].stepActive(y)) ? 1 : 0; 
				boolean isOn = (sequencers[x].stepActive(y)); 
				pg.fill(isOn ? P.p.color(255) : 30);
				pg.pushMatrix();
				pg.translate(startx + x * spacing, startY + y * spacing);
				pg.box(20);
				pg.popMatrix();
			}
		}
		
		// show beat/4
		for (int y = 0; y < NUM_STEPS; y+=4) {
//			float value = (sequencers[x].stepActive(y)) ? 1 : 0; 
			pg.stroke(255);
			pg.noFill();
			pg.pushMatrix();
			pg.translate(-boxSize/2, startY + y * spacing);
			Shapes.drawDashedBox(pg, spacing * (sequencers.length + 1), boxSize, boxSize, 10, true);
			pg.popMatrix();
		}
		
		// track current beat
		int curBeat = P.store.getInt(BEAT) % NUM_STEPS;
		pg.stroke(255);
		pg.noFill();
		pg.pushMatrix();
		pg.translate(-boxSize/2, startY + curBeat * spacing);
		pg.box(spacing * (sequencers.length + 1), boxSize, boxSize);
		pg.popMatrix();	
		
		pg.endDraw();
	}
 
Example 19
Source File: PG.java    From haxademic with MIT License 4 votes vote down vote up
public static void push(PGraphics pg) {
	pg.pushMatrix();
	pg.pushStyle();
}
 
Example 20
Source File: UITextInput.java    From haxademic with MIT License 4 votes vote down vote up
public void draw( PGraphics pg ) {
	pg.pushMatrix();
	PG.setDrawCorner(pg);
	
	// outline
	pg.noStroke();
	pg.fill(ColorsHax.BUTTON_OUTLINE);
	pg.rect(rect.x, rect.y, rect.width, rect.height);

	// draw input background
	if( pressed == true || focused == true ) {
		pg.fill(ColorsHax.BUTTON_BG_PRESS);
	} else if( over == true ) {
		pg.fill(ColorsHax.BUTTON_BG_HOVER);
	} else {
		pg.fill(ColorsHax.BUTTON_BG);
	}
	pg.rect(rect.x+1, rect.y+1, rect.width-2, rect.height-2);

	// set font on context
	boolean isUIComponent = (rect.height == IUIControl.controlH);
	if(isUIComponent) {  	// lock to UI size if we're a UI component
		IUIControl.setFont(pg);
		pg.fill(ColorsHax.BUTTON_TEXT);
	} else {
		PFont font = FontCacher.getFont(fontFile, fontSize);
		FontCacher.setFontOnContext(pg, font, ColorsHax.BUTTON_TEXT, 1f, align, PTextAlign.CENTER);
	}
	
	// get text width for cursor and to "scroll" text
	String displayText = value;
	float textW = pg.textWidth(displayText);
	int maxTextW = rect.width - padX * 2;
	while(textW > maxTextW) {
		displayText = displayText.substring(1);	// shift chars off the front of the text
		textW = pg.textWidth(displayText);
	}
	if(isUIComponent) {
		pg.text(displayText, rect.x + TEXT_INDENT, rect.y, rect.width, rect.height);
	} else {
		pg.text(displayText, rect.x + padX, rect.y - rect.height * 0.05f, rect.width, rect.height);
	}

	// draw blinking cursor
	cursorX = rect.x + padX + textW + cursorPadding;
	if(isUIComponent) cursorX -= 3;
	if(align == PTextAlign.CENTER) cursorX = rect.x + rect.width/2 + textW/2 + cursorPadding * 3f;
	if(focused == true) {
		pg.noStroke();
		pg.fill(ColorsHax.BUTTON_TEXT);
		if( P.p.millis() % 1000f > 500 ) pg.rect( cursorX, rect.y + rect.height * 0.25f, 2f, fontSize );
	}
	pg.popMatrix();
}