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

The following examples show how to use processing.core.PGraphics#background() . 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: TextureSvg3dExtruded.java    From haxademic with MIT License 6 votes vote down vote up
protected PGraphics buildTextureFromSvg(PShape svg) {
		// create logo texture with a slight under-blur
		float scaleToTex = MathUtil.scaleToTarget(svg.height, shapeHeight);
		PGraphics shapeTextureTemp = ImageUtil.shapeToGraphics(svg, scaleToTex);
		PGraphics shapeTexture = ImageUtil.shapeToGraphics(svg, scaleToTex);
		BlurProcessingFilter.instance(P.p).setBlurSize(4);
		BlurProcessingFilter.instance(P.p).setSigma(3);
		BlurProcessingFilter.instance(P.p).applyTo(shapeTexture);
		shapeTexture.beginDraw();
		shapeTexture.background(255);
		shapeTexture.image(shapeTextureTemp, 0, 0);
		shapeTexture.image(shapeTextureTemp, 0, 1);	// repeat down 1px to cover boxes
		shapeTexture.image(shapeTextureTemp, 1, 0);
		shapeTexture.image(shapeTextureTemp, 1, 1);	// repeat down 1px to cover boxes
		shapeTexture.endDraw();
//		DebugView.setTexture(curMeshTexture);
		return shapeTexture;
	}
 
Example 2
Source File: PG.java    From haxademic with MIT License 6 votes vote down vote up
public static void drawGrid(PGraphics pg, int bgColor, int strokeColor, float cols, float rows, float strokeSize) {
	// update texture
	pg.beginDraw();
	pg.background(bgColor);
	pg.fill(strokeColor);
	pg.noStroke();
	float cellW = (float) pg.width / (float) cols;
	cellW -= strokeSize / cols;
	float cellH = (float) pg.height / (float) rows;
	cellH -= strokeSize / rows;
	for (float x = 0; x <= pg.width; x += cellW) {
		pg.rect(x, 0, strokeSize, pg.height);
	}
	for (float y = 0; y <= pg.height; y += cellH) {
		pg.rect(0, y, pg.width, strokeSize);
	}
	pg.endDraw();
}
 
Example 3
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 4
Source File: PG.java    From haxademic with MIT License 6 votes vote down vote up
public static PGraphics newDataPG(int w, int h) {
//		PGraphics newPG = P.p.createGraphics(w, h, PRenderers.P3D);
//		PGraphics newPG = P.p.createGraphics(w, h, P.P32);
		PGraphics newPG = PGraphics32.createGraphics(P.p, w, h);
		newPG.noSmooth();
	    ((PGraphicsOpenGL)newPG).textureSampling(2);
		newPG.beginDraw();
//		newPG.hint(P.DISABLE_TEXTURE_MIPMAPS);
		newPG.hint(PConstants.DISABLE_DEPTH_SORT);
		newPG.hint(PConstants.DISABLE_DEPTH_TEST);
		newPG.hint(PConstants.DISABLE_DEPTH_MASK);
		newPG.background(0, 0);
		newPG.noStroke();
		newPG.endDraw();
		// moved these calls into this block for a full test of options
//		OpenGLUtil.setTextureQualityLow(newPG);		// necessary for proper texel lookup in GLSL!
//		OpenGLUtil.optimize2D(newPG);
		return newPG;
	}
 
Example 5
Source File: PG.java    From haxademic with MIT License 5 votes vote down vote up
public static PGraphics newPG2DFast(int w, int h) {
		PGraphics newPG = P.p.createGraphics(w, h, PRenderers.P2D);
//		newPG.noSmooth();
	    ((PGraphicsOpenGL)newPG).textureSampling(2);
		newPG.beginDraw();
		newPG.background(0, 0);
		newPG.noStroke();
//		newPG.hint(PConstants.DISABLE_DEPTH_SORT);
//		newPG.hint(PConstants.DISABLE_DEPTH_TEST);
//		newPG.hint(PConstants.DISABLE_DEPTH_MASK);
		newPG.endDraw();
		PG.setTextureRepeat(newPG, false);
		return newPG;
	}
 
Example 6
Source File: AudioIn.java    From haxademic with MIT License 5 votes vote down vote up
protected void updateAudioData() {
		// only draw if debugging
		PGraphics audioBuffer = (P.isHaxApp() && DebugView.active() == true) ? audioInputDebugBuffer : null;
		// set up context
		if(audioBuffer != null) {
			audioBuffer.beginDraw();
			audioBuffer.background(0);
		}
		// update actual audio data and draw if we have a buffer passed in
		audioInput.update(audioBuffer);
//		audioData = audioInput.audioData();
		// close context
		if(audioBuffer != null) audioBuffer.endDraw();
	}
 
Example 7
Source File: ImageUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static PGraphics shapeToGraphics(PShape shape, float scale, int bgColor) {
	PGraphics pg = P.p.createGraphics(P.ceil((float) shape.width * scale), P.ceil((float) shape.height * scale));
	pg.beginDraw();
	if(bgColor != -999) pg.background(bgColor);
	pg.shape(shape, 0, 0, pg.width, pg.height);
	pg.endDraw();
	return pg;
}
 
Example 8
Source File: ImageUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static PGraphics imageToGraphics(PImage img) {
	PGraphics pg = P.p.createGraphics(img.width, img.height, PRenderers.P3D);
	pg.beginDraw();
	pg.background(0, 0);
	pg.image(img, 0, 0);
	pg.endDraw();
	return pg;
}
 
Example 9
Source File: BloomFilter.java    From haxademic with MIT License 5 votes vote down vote up
public void applyTo(PGraphics pg) {
		// lazy-init buffer per passed-in buffer
		if(buffers.containsKey(pg) == false) {
			buffers.put(pg, PG.newPG(pg.width, pg.height));
		}
		PGraphics glowTexture = buffers.get(pg);
//		DebugView.setTexture(glowTexture);
		
		// copy image & create glow version
		glowTexture.beginDraw();
//		glowTexture.clear();
		glowTexture.background(0);
////		glowTexture.image(pg, 0, 0);
		glowTexture.endDraw();
		ImageUtil.copyImage(pg, glowTexture);
		LeaveWhiteFilter.instance(P.p).setCrossfade(0.95f);
		LeaveWhiteFilter.instance(P.p).applyTo(glowTexture);
		BlurHFilter.instance(P.p).setBlurByPercent(strength, glowTexture.width);
		BlurVFilter.instance(P.p).setBlurByPercent(strength, glowTexture.height);
		for (int i = 0; i < iterations; i++) {
			BlurHFilter.instance(P.p).applyTo(glowTexture);
			BlurVFilter.instance(P.p).applyTo(glowTexture);
		}
		
		// blend it
		if(blendMode == BLEND_SCREEN) {
			BlendTextureScreen.instance(P.p).setSourceTexture(glowTexture);
			BlendTextureScreen.instance(P.p).applyTo(pg);
		} else if(blendMode == BLEND_MULTIPLY) {
			BlendTextureMultiply.instance(P.p).setSourceTexture(glowTexture);
			BlendTextureMultiply.instance(P.p).applyTo(pg);
		} else if(blendMode == BLEND_DARKEST) {
			BlendTextureDarken.instance(P.p).setSourceTexture(glowTexture);
			BlendTextureDarken.instance(P.p).applyTo(pg);
		}
	}
 
Example 10
Source File: PG.java    From haxademic with MIT License 5 votes vote down vote up
public static PGraphics newPG32(int w, int h, boolean smooth, boolean hasAlpha) {
	PGraphics newPG = PGraphics32.createGraphics(P.p, w, h);
	if(smooth == false) newPG.noSmooth();
	if(hasAlpha == true) {
		newPG.beginDraw();
		newPG.background(0, 0);
		newPG.noStroke();
		newPG.endDraw();
	}
	PG.setTextureRepeat(newPG, true);
	return newPG;
}
 
Example 11
Source File: Demo_MaskConcentric.java    From haxademic with MIT License 5 votes vote down vote up
public void updateMaskedImages(PImage source) {
	for (int i = 0; i < numCircles; i++) {
		PGraphics image = images[i];
		image.beginDraw();
		image.background(255);
		image.noStroke();
		image.fill(255);
		ImageUtil.drawImageCropFill(source, image, true);
		image.endDraw();
		image.mask(masks[i]);
		// if(i < 4) DebugView.setTexture("image-"+i, image);
	}
}
 
Example 12
Source File: Demo_MaskConcentric.java    From haxademic with MIT License 5 votes vote down vote up
protected void firstFrame() {
	// build masks
	masks = new PGraphics[numCircles];
	for (int i = 0; i < numCircles; i++) {
		PGraphics mask = PG.newPG(p.width, p.height);
		masks[i] = mask;
		float radius = mask.width * 0.9f;
		radius = radius - radius * (float) i / (float) numCircles;
		mask.beginDraw();
		mask.background(0);
		PG.setCenterScreen(mask);
		PG.setDrawCenter(mask);
		mask.noStroke();
		mask.fill(255);
		mask.circle(0, 0, radius);
		mask.endDraw();
		// if(i < 4) DebugView.setTexture("mask-"+i, mask);
	}
	
	// build images
	images = new PGraphics[numCircles];
	for (int i = 0; i < numCircles; i++) {
		images[i] = PG.newPG(p.width, p.height);
	}
	
	// build shadows
	shadows = new PGraphics[numCircles];
	for (int i = 0; i < numCircles; i++) {
		shadows[i] = PG.newPG(p.width, p.height);
	}
	colorTransformShader = p.loadShader(FileUtil.getPath("haxademic/shaders/filters/opaque-pixels-to-color.glsl"));
}
 
Example 13
Source File: Skylight_Basic.java    From PixelFlow with MIT License 4 votes vote down vote up
public void displayScene(PGraphics canvas){
  if(canvas == skylight.renderer.pg_render){
    canvas.background(32);
  }
  canvas.shape(shape);
}
 
Example 14
Source File: Silhouect.java    From haxademic with MIT License 4 votes vote down vote up
protected void firstFrame() {
		// main buffer
		float scaleDown = 0.75f;
		mainBuffer = p.createGraphics(P.round(1920 * scaleDown), P.round(1080 * scaleDown), PRenderers.P3D);
//		mainBuffer.noSmooth();
		rdBuffer = p.createGraphics(P.round(1920 * scaleDown), P.round(1080 * scaleDown), PRenderers.P3D);
//		rdBuffer.noSmooth();
		keystone = new PGraphicsKeystone(p, mainBuffer, 10, FileUtil.getPath("text/keystoning/silhouect.txt"));
		
		// init kinect
		if(P.platform == P.MACOSX) {
			kinect = new KinectPV2(p);
//			kinect.enableDepthImg(true);
//			kinect.enableDepthMaskImg(true);
			kinect.enableBodyTrackImg(true);
//			kinect.enableInfraredImg(true);
			// kinect.enableColorImg(true);
			kinect.init();
		}
		
		// init instructions/slideshow
		String imagesPath = FileUtil.getPath("images/silhouect/slideshow");
		ArrayList<String> files = FileUtil.getFilesInDirOfTypes(imagesPath, "png,jpg");
		slideshow = new ArrayList<PGraphics>();
		for (int i = 0; i < files.size(); i++) {
			P.println("Loaded image:", i, files.get(i));
			String filePath = files.get(i);
			PImage imgSrc = p.loadImage(filePath);
			PGraphics image = ImageUtil.imageToGraphics(imgSrc);

			image.beginDraw();
			image.background(0, 0);
			image.image(imgSrc, 0, 0);
			image.endDraw();
			LeaveWhiteFilter.instance(p).applyTo(image);
			DebugView.setTexture("image", image);
			slideshow.add(image);
		}
		
		// load sponsor image if it exists
		String sponsorImgPath = FileUtil.getPath("images/silhouect/sponsor.png");
		if(FileUtil.fileExists(sponsorImgPath)) {
			sponsorImg = p.loadImage(sponsorImgPath);
		}
		
		// load audio texture
//		AudioLineIn.instance();
//		audioTextures = new BaseTexture[] {
//			new TextureOuterCube(mainBuffer.width/4, mainBuffer.height/4),
//			new TextureOuterSphere(mainBuffer.width/4, mainBuffer.height/4),
//			new TextureEQConcentricCircles(mainBuffer.width/4, mainBuffer.height/4),
//			new TextureLinesEQ(mainBuffer.width/4, mainBuffer.height/4),
//		};
		
		// init help menu
		DebugView.setHelpLine("Key Commands:", "");
		DebugView.setHelpLine("[R]", "Reset keystone");
		DebugView.setHelpLine("[D]", "Keystone test pattern");
	}
 
Example 15
Source File: Demo_KinectV1MultiCamWrapper.java    From haxademic with MIT License 4 votes vote down vote up
protected int drawKinectDepthPixels(KinectWrapperV1 kinect, PGraphics buffer, int pixelColor, boolean drawAllData) {
	// open context
	buffer.beginDraw();
	if(drawAllData == true) buffer.background(0, 0);
	buffer.noStroke();
	buffer.fill(pixelColor);

	// loop through kinect data within player's control range
	float pixelDepth;
	float avgX = 0;
	float avgY = 0;
	float numPoints = 0;
	
	float kinectDepthZone = slider(KINECT_FAR) - slider(KINECT_NEAR);
	float distancePixels = (float) KinectWrapperV1.KWIDTH / kinectDepthZone;		// map distance to width
	float pixelSkip = slider(PIXEL_SIZE);
	// float pixelHalf = pixelSkip / 2f;
	
	// TODO: Switch to ONLY loop through kinect points that we need
	for ( int x = 0; x < DepthCameraSize.WIDTH; x += pixelSkip ) {
		for ( int y = 0; y < KinectWrapperV2.KHEIGHT; y += pixelSkip ) {
			pixelDepth = kinect.getDepthAt( x, y );
			if(pixelDepth != 0 && pixelDepth > slider(KINECT_NEAR) && pixelDepth < slider(KINECT_FAR)) {
				// draw depth points
				float userZ = P.map(pixelDepth, slider(KINECT_NEAR), slider(KINECT_FAR), 0, kinectDepthZone * distancePixels);
				if(drawAllData == true || (y > slider(KINECT_TOP) && y < slider(KINECT_BOTTOM))) {
					buffer.rect(x - 5, userZ - 5, 10, 10);
				}
				
				// calc data processing
				numPoints++;
				avgX += x;
				avgY += userZ;
			}
		}
	}
	
	// show CoM
	buffer.fill(pixelColor);
	if(drawAllData == false) buffer.ellipse(avgX / numPoints, avgY / numPoints, 20, 20);
	
	// close buffer
	buffer.endDraw();
	return (int) numPoints;
}
 
Example 16
Source File: Demo_Kinect_FloorWatchMapped.java    From haxademic with MIT License 4 votes vote down vote up
protected int drawKinectDepthPixels(KinectWrapperV2 kinect, PGraphics buffer, int pixelColor, boolean drawAllData, boolean clearBg) {
	// open context
	buffer.beginDraw();
	if(clearBg == true) buffer.background(0);
	buffer.noStroke();
	buffer.fill(pixelColor);

	// loop through kinect data within player's control range
	float pixelDepth;
	float avgX = 0;
	float avgY = 0;
	float numPoints = 0;
	
	float kinectDepthZone = slider(KINECT_FAR) - slider(KINECT_NEAR);
	float distancePixels = (float) KinectWrapperV2.KWIDTH / kinectDepthZone;		// map distance to width
	float pixelSkip = slider(PIXEL_SIZE);
	// float pixelHalf = pixelSkip / 2f;
	
	// TODO: Switch to ONLY loop through kinect points that we need
	for ( int x = 0; x < DepthCameraSize.WIDTH; x += pixelSkip ) {
		for ( int y = 0; y < KinectWrapperV2.KHEIGHT; y += pixelSkip ) {
			pixelDepth = kinect.getDepthAt( x, y );
			if(pixelDepth != 0 && pixelDepth > slider(KINECT_NEAR) && pixelDepth < slider(KINECT_FAR)) {
				// draw depth points
				float userZ = P.map(pixelDepth, slider(KINECT_NEAR), slider(KINECT_FAR), 0, kinectDepthZone * distancePixels);
				if(drawAllData == true || (y > slider(KINECT_TOP) && y < slider(KINECT_BOTTOM))) {
					buffer.rect(x - 5, userZ - 5, 10, 10);
				}
				
				// calc data processing
				numPoints++;
				avgX += x;
				avgY += userZ;
			}
		}
	}
	DebugView.setValue("avgX/avgY", avgX + ", " + avgY);
	
	// close buffer
	buffer.endDraw();
	return (int) numPoints;
}
 
Example 17
Source File: ImageUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static void clearPGraphics( PGraphics pg ) {
//		pg.beginDraw();
		pg.background(0,0);
//		pg.endDraw();
	}
 
Example 18
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 19
Source File: Demo_ParticleSystem_FromMap.java    From haxademic with MIT License 4 votes vote down vote up
protected void drawBaseImage(PGraphics pg) {
	pg.background(0);
	if(video.width > 100) ImageUtil.cropFillCopyImage(video, pg, false);
	pg.loadPixels();
}