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

The following examples show how to use processing.core.PGraphics#image() . 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: TiledTexture.java    From haxademic with MIT License 6 votes vote down vote up
public void drawDebug(PGraphics pg) {
		// fit to small box
		// draw background
		pg.stroke(0);
		pg.fill(0);
		pg.rect(0, 0, texture.width, texture.height);
		// draw image
		pg.image(texture, 0, 0, texture.width, texture.height);
		// show texture grab area
//		float halfSizeX = (sizeX * (float) texture.width) / 2f;
//		float halfSizeY = (sizeY * (float) texture.height) / 2f;
		pg.stroke(255, 0, 0, 200);
		pg.noFill();
		pg.beginShape();
		pg.vertex(tlX, tlY);
		pg.vertex(trX, trY);
		pg.vertex(brX, brY);
		pg.vertex(blX, blY);
		pg.vertex(tlX, tlY);
		pg.endShape();

		
	}
 
Example 2
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 3
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 4
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 5
Source File: ImageSequenceRecorder.java    From haxademic with MIT License 5 votes vote down vote up
public void drawDebug(PGraphics pg) {
	pg.beginDraw();
	float frameW = (float) pg.width / (float) numFrames;
	float frameH = frameW * ((float) height / (float) width);
	for (int i = 0; i < numFrames; i++) {
		float x = frameW * i;
		int curIndex = (frameIndex - i) % numFrames;
		while(curIndex < 0) curIndex += numFrames; 
		pg.image(images[curIndex], x, 0, frameW, frameH);
	}
	pg.endDraw();
}
 
Example 6
Source File: ImageSequencePlayer.java    From haxademic with MIT License 5 votes vote down vote up
public int display(PGraphics pg, int x, int y, int frame) {
	boolean flipped = (frameIndexPlaybackSequence[frame] < 0);
	frame = P.abs(frameIndexPlaybackSequence[frame]);
	if(loaded == false) return -1;
	if(imageSequence.size() > frame) {
		pg.pushMatrix();
		pg.translate(x + imgW/2, y + imgH/2);
		if(flipped == true) pg.scale(-1, 1);
		pg.image(imageSequence.get(frame), 0, 0, imgW, imgH);
		pg.popMatrix();
	}
	return frame;
}
 
Example 7
Source File: ConstellationPointMarker.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public boolean draw(final PGraphics graphics, final List<MapPosition> positions, final UnfoldingMap map) {
    if (positions.isEmpty() || isHidden()) {
        return false;
    }

    final float x = positions.get(0).x;
    final float y = positions.get(0).y;

    graphics.pushStyle();

    if (size > MarkerUtilities.DEFAULT_SIZE) {
        graphics.strokeWeight(strokeWeight);
        graphics.stroke(strokeColor);
        graphics.fill(getFillColor());
        graphics.ellipseMode(PConstants.RADIUS);
        graphics.ellipse(x, y, size, size);
    } else {
        TEMPLATE_IMAGE.loadPixels();
        for (int i = 0; i < TEMPLATE_IMAGE.width * TEMPLATE_IMAGE.height; i++) {
            final int[] pixelArgb = MarkerUtilities.argb(TEMPLATE_IMAGE.pixels[i]);
            if (!(pixelArgb[0] == 0 || (pixelArgb[1] == 0 && pixelArgb[2] == 0 && pixelArgb[3] == 0))) {
                TEMPLATE_IMAGE.pixels[i] = getFillColor();
            }
        }
        TEMPLATE_IMAGE.updatePixels();

        graphics.imageMode(PConstants.CORNER);
        graphics.image(TEMPLATE_IMAGE, x - POINT_X_OFFSET, y - POINT_Y_OFFSET);
    }

    graphics.popStyle();

    return true;
}
 
Example 8
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 9
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 10
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 11
Source File: MotionBlurPGraphics.java    From haxademic with MIT License 5 votes vote down vote up
public void updateToCanvas(PImage img, PGraphics canvas, float maxAlpha) {
	// save current frame to buffer
	_pastFrames.add(img.copy());
	if(_pastFrames.size() > _blurFrames) {
		_pastFrames.remove(0);
	}
	
	// draw all frames to screen
	for (int f=0; f < _pastFrames.size(); f++) {
		float alpha = (f+1f) * maxAlpha / _pastFrames.size();
		PImage pastFrame = _pastFrames.get(f);
		PG.setPImageAlpha(canvas, alpha);
		canvas.image(pastFrame, 0, 0);
	}
}
 
Example 12
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 13
Source File: ImageSequenceMovieClip.java    From haxademic with MIT License 5 votes vote down vote up
public void preCacheImages(PGraphics pg) {
	if(preCacheFrame < imageSequence.size() && preCacheFrame != -1) {
		// draw image to buffer, which caches into Processing's PGrpahics Texture cache
		// doing this once, upfront will make performance faster after everything's loaded
		pg.image(imageSequence.get(preCacheFrame), pg.width * 3, pg.height * 3, 10, 10);
		preCacheFrame++;
	} else if(preCacheFrame == totalImages && preCacheFrame != -1) {
		if(delegate != null) delegate.movieClipPreCached(this);
		preCacheFrame = -1;
	}
}
 
Example 14
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 15
Source File: Utility.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
public static PImage resizeImage(PImage img, float scl) {
	PGraphics pg = applet.createGraphics((int) (img.width * scl), (int) (img.height * scl));

	pg.noSmooth();
	pg.beginDraw();
	pg.clear();
	pg.scale(scl, scl);
	pg.image(img, 0, 0);
	pg.endDraw();

	return pg;
}
 
Example 16
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 17
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 18
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 19
Source File: LeapRegionGrid.java    From haxademic with MIT License 4 votes vote down vote up
public void drawDebug(PGraphics pg) {
	if(_pg == null) return;
	pg.image(_pg, 0, 0);
}
 
Example 20
Source File: SurfaceMapper.java    From sketch-mapper with MIT License 4 votes vote down vote up
/**
 * Render method used when calibrating. Shouldn't be used for final rendering.
 *
 * @param glos
 */
public void render(PGraphics glos) {
    //        glos.beginDraw();
    //        glos.endDraw();
    if (MODE == MODE_CALIBRATE) {
        parent.cursor();
        glos.beginDraw();

        if (this.isUsingBackground()) {
            glos.image(backgroundTexture, 0, 0, width, height);
        }

        glos.fill(0, 40);
        glos.noStroke();
        glos.rect(-2, -2, width + 4, height + 4);
        glos.stroke(255, 255, 255, 40);
        glos.strokeWeight(1);
        /*
         * float gridRes = 32.0f;
*
* float step = (float) (width / gridRes);
*
* for (float i = 1; i < width; i += step) { glos.line(i, 0, i, parent.height); }
*
* step = (float) (height / gridRes);
*
* for (float i = 1; i < width; i += step) { glos.line(0, i, parent.width, i); }
*/
        glos.stroke(255);
        glos.strokeWeight(2);
        glos.line(1, 1, width - 1, 1);
        glos.line(width - 1, 1, width - 1, height - 1);
        glos.line(1, height - 1, width - 1, height - 1);
        glos.line(1, 1, 1, height - 1);
        glos.endDraw();

        for (int i = 0; i < surfaces.size(); i++) {
            surfaces.get(i).render(glos);
        }

        // Draw circles for SelectionDistance or SnapDistance (snap if CMD
        // is down)
        glos.beginDraw();
        if (enableSelectionMouse) {
            if (!ctrlDown) {
                glos.ellipseMode(PApplet.CENTER);
                glos.fill(this.getSelectionMouseColor(), 100);
                glos.noStroke();
                glos.ellipse(parent.mouseX, parent.mouseY, this.getSelectionDistance() * 2, this.getSelectionDistance() * 2);
            } else {
                glos.ellipseMode(PApplet.CENTER);
                glos.fill(255, 0, 0, 100);
                glos.noStroke();
                glos.ellipse(parent.mouseX, parent.mouseY, this.getSnapDistance() * 2, this.getSnapDistance() * 2);
            }
        }

        if (selectionTool != null && !disableSelectionTool) {
            glos.stroke(255, 100);
            glos.strokeWeight(1);
            glos.fill(0, 200, 255, 50);
            glos.rect(selectionTool.x, selectionTool.y, selectionTool.width, selectionTool.height);
            glos.noStroke();
        }

        glos.endDraw();

    } else {
        parent.noCursor();
    }
}