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

The following examples show how to use processing.core.PGraphics#rect() . 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: UIButton.java    From haxademic with MIT License 6 votes vote down vote up
public void draw(PGraphics pg) {
	PG.setDrawCorner(pg);

	// outline
	pg.noStroke();
	if(over || pressed) pg.fill(ColorsHax.BUTTON_OUTLINE_HOVER);
	else pg.fill(ColorsHax.BUTTON_OUTLINE);
	pg.rect(rect.x, rect.y, rect.width, rect.height);

	// background
	if(over && value == 0 && !pressed) pg.fill(ColorsHax.BUTTON_BG_HOVER);
	else if(pressed) pg.fill(ColorsHax.BUTTON_BG_PRESS);
	else if(toggles && value == 1) pg.fill(ColorsHax.WHITE);
	else pg.fill(ColorsHax.BUTTON_BG);
	pg.rect(rect.x+1, rect.y+1, rect.width-2, rect.height-2);

	// text label
	IUIControl.setFont(pg);
	if(toggles && value == 1) pg.fill(ColorsHax.BLACK);
	else pg.fill(ColorsHax.BUTTON_TEXT);
	pg.text(label, rect.x + TEXT_INDENT, rect.y, rect.width, rect.height);
	
	// set active if drawing
	activeTime = P.p.millis();
}
 
Example 2
Source File: PG.java    From haxademic with MIT License 6 votes vote down vote up
public static void feedback(PGraphics pg, int color, float colorFade, float feedbackDistance) {
	PG.setDrawCorner(pg);
	PG.setDrawFlat2d(pg, true);
	pg.copy(
		pg, 
		0, 
		0, 
		pg.width, 
		pg.height, 
		P.round(-feedbackDistance), 
		P.round(-feedbackDistance), 
		P.round(pg.width + feedbackDistance * 2f), 
		P.round(pg.height + feedbackDistance * 2f)
	);
	if(color != -1) {
		pg.fill(color, colorFade * 255f);
		pg.noStroke();
		pg.rect(0, 0, pg.width, pg.height);
	}
	PG.setDrawFlat2d(pg, false);
}
 
Example 3
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 4
Source File: UITitle.java    From haxademic with MIT License 6 votes vote down vote up
public void draw(PGraphics pg) {
	PG.setDrawCorner(pg);

	// outline
	pg.noStroke();
	pg.fill(ColorsHax.BUTTON_OUTLINE);
	pg.rect(rect.x, rect.y, rect.width, rect.height);

	// background
	pg.fill(ColorsHax.TITLE_BG);
	pg.rect(rect.x+1, rect.y+1, rect.width-2, rect.height-2);

	// text label
	IUIControl.setFont(pg);
	pg.fill(ColorsHax.BUTTON_TEXT);
	pg.text(label, rect.x + TEXT_INDENT, rect.y);
}
 
Example 5
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 6
Source File: BFLinewaveRender.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawGraphics( PGraphics pg ) {
	pg.beginDraw();
	pg.clear();
	PG.setDrawCorner(pg);
	
	// timeline
	float percentComplete = ((float)(p.frameCount%_frames)/_frames);
	float frameOsc = P.sin( PConstants.TWO_PI * percentComplete);

	// reference image
	pg.image(_print, 0, 0, p.width, p.height);
	
	// white bg
	pg.fill(255, 255);
	pg.noStroke();
	pg.rect(266, 175, 373, 537);
	
	// draw lines
	int numLines = _lines.size();
	for (int i = 0; i < numLines; i++) {
		_lines.get(i).update(pg, frameOsc);
	}
	
	pg.endDraw();
}
 
Example 7
Source File: PG.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawRainbow(PGraphics pg) {
	int colors[] = ColorsHax.PRIDE;
	pg.beginDraw();
	pg.noStroke();
	float colorHeight = P.round(pg.height / colors.length);
	for (int i = 0; i < colors.length; i++) {
		pg.fill(colors[i]);
		pg.rect(0, colorHeight * i, pg.width, colorHeight);
	}
	pg.endDraw();
}
 
Example 8
Source File: PG.java    From haxademic with MIT License 5 votes vote down vote up
public static void fadeInOut(PGraphics pg, int color, int startFrame, int stopFrame, int transitionFrames) {
	int frames = stopFrame - startFrame;
	PG.setDrawCorner(pg);
	if(P.p.frameCount <= startFrame + transitionFrames) {
		pg.fill(color, P.map(P.p.frameCount, 1f, transitionFrames, 255f, 0));
		pg.rect(0,0,pg.width, pg.height);
	} else if(P.p.frameCount >= frames - transitionFrames) {
		pg.fill(color, P.map(P.p.frameCount, frames - transitionFrames, frames, 0, 255f));
		pg.rect(0, 0, pg.width, pg.height);
	} 
}
 
Example 9
Source File: SavedPointUI.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawPoint(PGraphics pg) {
	PG.setDrawCenter(pg);
	pg.noFill();
	if(active) {
		pg.stroke(0, 255, 0);
	} else {
		pg.stroke(255);
	}
	pg.strokeWeight((active) ? 3 : 1.5f);
	float indicatorSize = 20f + 3f * P.sin(P.p.frameCount / 10f);
	pg.ellipse(position.x, position.y, indicatorSize, indicatorSize);
	pg.strokeWeight(1f);
	pg.rect(position.x, position.y, 3, 3);
	PG.setDrawCorner(pg);
}
 
Example 10
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 11
Source File: DwMagnifier.java    From PixelFlow with MIT License 5 votes vote down vote up
public void display(PGraphics pg_canvas, int x, int y){
  setDisplayPosition(x, y);
  pg_canvas.image(pg_region, x, y, w, h);
  pg_canvas.rectMode(PConstants.CORNER);
  pg_canvas.stroke(128);
  pg_canvas.strokeWeight(1);
  pg_canvas.noFill();
  pg_canvas.rect(x, y, w, h);
}
 
Example 12
Source File: MoireProposal.java    From haxademic with MIT License 5 votes vote down vote up
public void drawDoorOnTexture(PGraphics tex) {
	float doorW = tex.width * 0.2f;
	float doorH = tex.height * 0.6f;
	tex.beginDraw();
	tex.fill(0);
	tex.rect(tex.width / 2 - doorW / 2, tex.height - doorH, doorW, doorH);
	tex.endDraw();
}
 
Example 13
Source File: ImageGradient.java    From haxademic with MIT License 5 votes vote down vote up
public void drawDebug(PGraphics pg) {
	pg.image(gradientImg, 0, 0);
	pg.stroke(255, 0, 0);
	pg.noFill();
	pg.rect(sampleX - 1, 0, 3, gradientImg.height);
	pg.fill(255);
	pg.noStroke();
}
 
Example 14
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 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: Rectangle.java    From haxademic with MIT License 4 votes vote down vote up
public void draw(PGraphics pg) {
	pg.stroke(255);
	pg.noFill();
	if(collided) pg.fill(0, 255, 0, 50);
	pg.rect(x, y, width, height);
}
 
Example 17
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 18
Source File: PG.java    From haxademic with MIT License 4 votes vote down vote up
public static void fadeToBlack(PGraphics pg, float blackVal) {
	pg.blendMode(P.SUBTRACT);
	pg.fill(blackVal);
	pg.rect(0, 0, pg.width * 3, pg.height * 3);
	pg.blendMode(P.BLEND);
}
 
Example 19
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();
}
 
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();
    }
}