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

The following examples show how to use processing.core.PGraphics#box() . 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: 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 2
Source File: ShaderSSAO.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawFewCubes(PGraphics pg) {
		// spin it
		pg.rotateX(P.PI/3 + P.sin(progressRads) * 0.1f);

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

		float radius = pg.width * 0.2f;
		for (int i = 0; i < 24; i++) {
			pg.fill(60f + 55f * P.sin(i), 170f + 35f * P.cos(i * 2f), 150f + 75f * P.sin(i));
			pg.pushMatrix();
//			pg.translate(radius * P.sin(i/3f + progressRads), radius * P.cos(i/3f + progressRads), 0);
			pg.rotateX(P.TWO_PI * p.noise(i + 0.1f * P.cos(progressRads + i)));
			pg.rotateY(P.TWO_PI * p.noise(i + 0.1f * P.sin(progressRads + i)));
			pg.rotateZ(P.TWO_PI * p.noise(i + 0.1f * P.sin(progressRads + i * 20f)));
			pg.box(
					pg.height * P.sin(i + progressRads),
					pg.height * P.sin(i + progressRads) * 0.1f,
					pg.height * P.sin(i + progressRads) * 0.1f
					);
			pg.popMatrix();
		}
	}
 
Example 3
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 4
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 5
Source File: ShaderSSAO.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawCubesInGrid(PGraphics pg) {
	// spin it
	pg.rotateX(-P.PI/3f - 0.1f + P.sin(progressRads) * 0.1f);  
	pg.translate(0, 0, -pg.height * 0.5f);
	// draw plane
	pg.fill(100);
	pg.box(p.width * 3);

	// grid setup
	float boxSize = p.width / 10f;
	float numBoxes = 120f;

	for (int x = 0; x < numBoxes; x++) {
		for (int z = 0; z < numBoxes; z++) {
			pg.fill(255f);
			pg.pushMatrix();
			float xx = (-numBoxes/2f * boxSize) + x * boxSize;
			float yy = pg.height * 1.1f;
			float zz = (-numBoxes/2f * boxSize) + z * boxSize;
			pg.translate(xx, yy, zz);
			float dist = MathUtil.getDistance(0, 0, xx, zz);
			pg.box(
					boxSize,
					pg.height * (0.4f + 0.4f * P.sin(dist/250f + progressRads)),
					boxSize
				);
			pg.popMatrix();
		}
	}	
}
 
Example 6
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 7
Source File: VectorFlyer.java    From haxademic with MIT License 5 votes vote down vote up
public void update( PGraphics pg, boolean draws, boolean debugTarget ) {
	// color - if closer than threshold, ease towards saturated color
	pg.noStroke();
	if( distToDest < 200 ) {
		pg.fill(color.colorIntMixedWith(color2, 1f - distToDest/200f));
		// if( target != null ) BoxBetween.draw( p, new PVector(position.x, position.y, position.z), new PVector(target.x, target.y, target.z), 10 );
	} else {
		pg.fill(color.colorInt());
	}
	
	// store last position for rotation towards heading
	positionLast.set(position);
	
	//		accel = baseAccel * ( 0.5f + 0.6f * (float)Math.sin(p.frameCount * 0.01f) ); // was an effect to get particles to slow on following attractors 

	// always accelerate towards destination using basic xyz comparison & cap speed
	vector.x += ( position.x < target.x ) ? accel : -accel;
	vector.x = P.constrain(vector.x, -maxSpeed, maxSpeed);
	vector.y += ( position.y < target.y ) ? accel : -accel;
	vector.y = P.constrain(vector.y, -maxSpeed, maxSpeed);
	vector.z += ( position.z < target.z ) ? accel : -accel;
	vector.z = P.constrain(vector.z, -maxSpeed, maxSpeed);
	position.add(vector);
	
				
	if( draws == true ) { 
		// point and position
		pg.pushMatrix();
		pg.translate(position.x, position.y, position.z);
		OrientationUtil.setRotationTowards( pg, new PVector(position.x, position.y, position.z), new PVector(positionLast.x, positionLast.y, positionLast.z) );
		pg.box(10, 30, 10);
		pg.popMatrix();
		
		// line to target
		if(debugTarget) {
			pg.stroke(255);
			pg.line(position.x, position.y, position.z, target.x, target.y, target.z);
		}
	}
}
 
Example 8
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void boxBetween( PGraphics pg, PVector point1, PVector point2, float thickness ) {
	pg.pushMatrix();
		
	// set orientation 
	OrientationUtil.setMidPoint(pg, point1, point2);
	OrientationUtil.setRotationTowards(pg, point1, point2);

	// draw box
	pg.box( thickness, point1.dist(point2), thickness );

	pg.popMatrix(); 
}
 
Example 9
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 10
Source File: KinectRegion.java    From haxademic with MIT License 4 votes vote down vote up
public void update(PGraphics debugGraphics) {
	IDepthCamera depthCamera = DepthCamera.instance().camera;
	
	float depthDivider = 0.3f;
       if(debugGraphics != null) {
       	debugGraphics.beginShape(PShapeTypes.QUADS);
   		debugGraphics.stroke(debugColor);
   		debugGraphics.fill( 255, pixelCount / minPixels * 10f );
       	debugGraphics.vertex(left, bottom, -near * depthDivider);
       	debugGraphics.vertex(right, bottom, -near * depthDivider);
       	debugGraphics.vertex(right, bottom, -far * depthDivider);
       	debugGraphics.vertex(left, bottom, -far * depthDivider);
       	debugGraphics.endShape();
       	debugGraphics.noStroke();
       }
       // find kinect readings in the region
	_isActive = false;
	if( depthCamera != null ) {
		pixelCount = 0;
		float controlXTotal = 0;
		float controlZTotal = 0;
		float pixelDepth = 0;
		for ( int x = left; x < right; x += pixelSkip ) {
			for ( int y = top; y < bottom; y += pixelSkip ) {
				pixelDepth = depthCamera.getDepthAt( x, y );
				if( pixelDepth != 0 && pixelDepth > near && pixelDepth < far ) {
			        if(debugGraphics != null) {
			        	debugGraphics.fill( debugColor, 127 );
			        	debugGraphics.pushMatrix();
			        	debugGraphics.translate(x, y, -pixelDepth * depthDivider);
			        	debugGraphics.box(pixelSkip, pixelSkip, pixelSkip);
			        	debugGraphics.popMatrix();
					}
					// add up for calculations
					pixelCount++;
					controlXTotal += x;
					controlZTotal += pixelDepth;
				}
			}
		}

		// if we have enough blocks in a region, update the player's joystick position
		if( pixelCount > minPixels ) {
			_isActive = true;
			// compute averages
			if( controlXTotal > 0 && controlZTotal > 0 ) {
				float avgX = controlXTotal / pixelCount;
				_controlX = (MathUtil.getPercentWithinRange(left, right, avgX) - 0.5f) * 2f;
				float avgZ = controlZTotal / pixelCount;
				_controlZ = (MathUtil.getPercentWithinRange(near, far, avgZ) - 0.5f) * 2f;

				// show debug
		        if(debugGraphics != null) {
					debugGraphics.fill( 255, 127 );
					debugGraphics.pushMatrix();
					debugGraphics.translate(avgX, bottom - 250, -avgZ * depthDivider);
					debugGraphics.box(20, 500, 20);
					debugGraphics.popMatrix();
				}
			}
		}
	}
}
 
Example 11
Source File: LeapRegion.java    From haxademic with MIT License 4 votes vote down vote up
public void update(PGraphics debugGraphics) {
	// find kinect readings in the region
	_isActive = false;
	if( leapMotion != null ) {
		DebugView.setValue("leapMotion.getHands()", leapMotion.getHands().size());
	    for(Hand hand : leapMotion.getHands()){
	        PVector hand_position    = hand.getPosition();
	        // PVector hand_stabilized  = hand.getStabilizedPosition();
	        DebugView.setValue("hand "+hand.getId(), hand_position.toString());
	        
	        // draw debug hand position
	        if(debugGraphics != null) {
	        	debugGraphics.noStroke();
		        debugGraphics.fill(255);
		        debugGraphics.pushMatrix();
		        debugGraphics.translate(hand_position.x, hand_position.y, -1f * hand_position.z);
		        debugGraphics.box(40, 40, 40);
		        debugGraphics.popMatrix();
	        }
			
	        // set position if hand is in region
	        if(
	        	hand_position.x > _left && 
	        	hand_position.x < _right && 
	        	hand_position.y > _top && 
	        	hand_position.y < _bottom && 
	        	hand_position.z > _near && 
	        	hand_position.z < _far 
	        	) {
	        	_isActive = true;
	        	_controlX = (MathUtil.getPercentWithinRange(_left, _right, hand_position.x) - 0.5f) * 2f;
	        	_controlY = (MathUtil.getPercentWithinRange(_top, _bottom, hand_position.y) - 0.5f) * 2f;
	        	_controlZ = (MathUtil.getPercentWithinRange(_near, _far, hand_position.z) - 0.5f) * 2f;
	        }
	    }
	}
	
	// if none found, reset values
	if(_isActive == false) {
		_controlX = 0;
		_controlY = 0;
		_controlZ = 0;
	}
}
 
Example 12
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();
	}