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

The following examples show how to use processing.core.PGraphics#rectMode() . 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: PG.java    From haxademic with MIT License 6 votes vote down vote up
public static void drawStrokedRect(PGraphics pg, float w, float h, float strokeWeight, int colorBg, int colorStroke) {
	int prevRectMode = pg.rectMode;
	pg.push();
	
	// make sure rect stroke is drawing from the same top left as rect bg
	if(prevRectMode == PConstants.CENTER) pg.translate(P.round(-w/2), P.round(-h/2));
	pg.rectMode(PConstants.CORNER);
	
	// rect bg
	pg.noStroke();
	pg.fill(colorBg);
	pg.rect(0, 0, w, h);
	
	// pixel-perfect stroke by drawing 4 rects
	pg.fill(colorStroke);
	pg.rect(0, 0, w, strokeWeight);					// top
	pg.rect(0, h - strokeWeight, w, strokeWeight);	// bottom
	pg.rect(0, 0, strokeWeight, h);					// left
	pg.rect(w - strokeWeight, 0, strokeWeight, h);	// right
	pg.rectMode(prevRectMode);						// reset rectMode to whatever it was before

	pg.pop();
}
 
Example 2
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 3
Source File: TiledGrid.java    From haxademic with MIT License 5 votes vote down vote up
public void draw(PGraphics pg, float cols, float rows, boolean drawOutline) {
	int prevRectMode = pg.rectMode;
	PG.setTextureRepeat(pg, true);
	pg.pushMatrix();
	float drawW = cols * tileSize + strokeWeight;
	float drawH = rows * tileSize + strokeWeight;
	pg.noStroke();
	pg.beginShape();
	pg.textureMode(P.IMAGE);
	pg.texture(gridCell);
	if(prevRectMode == PConstants.CENTER) pg.translate(P.round(-drawW/2), P.round(-drawH/2));
	pg.vertex(0, 0, 0,			offsetX * tileSize + 0, 		offsetY * tileSize + 0);
	pg.vertex(drawW, 0, 0, 		offsetX * tileSize + drawW, 	offsetY * tileSize + 0);
	pg.vertex(drawW, drawH, 0, 	offsetX * tileSize + drawW, 	offsetY * tileSize + drawH);
	pg.vertex(0, drawH, 0, 		offsetX * tileSize + 0, 		offsetY * tileSize + drawH);
	pg.endShape();
	
	if(drawOutline) {
		pg.rectMode(PConstants.CORNER); // make sure rect is drawing from the same top left
		pg.fill(colorStroke);
		pg.rect(0, 0, drawW, strokeWeight);	// top
		pg.rect(0, drawH - strokeWeight, drawW, strokeWeight);	// bottom
		pg.rect(0, 0, strokeWeight, drawH);	// left
		pg.rect(drawW - strokeWeight, 0, strokeWeight, drawH);	// right
		pg.rectMode(prevRectMode);		// reset rect mode to whatever it was before
	}
	
	pg.popMatrix();
}
 
Example 4
Source File: PG.java    From haxademic with MIT License 4 votes vote down vote up
public static void setDrawCorner( PGraphics p ) {
	p.imageMode( PConstants.CORNER );
	p.rectMode( PConstants.CORNER );
	p.ellipseMode( PConstants.CORNER );
	p.shapeMode( PConstants.CORNER );
}
 
Example 5
Source File: PG.java    From haxademic with MIT License 4 votes vote down vote up
public static void setDrawCenter( PGraphics p ) {
	p.imageMode( PConstants.CENTER );
	p.rectMode( PConstants.CENTER );
	p.ellipseMode( PConstants.CENTER );
	p.shapeMode( PConstants.CENTER );
}