Java Code Examples for processing.core.PGraphics#beginDraw()
The following examples show how to use
processing.core.PGraphics#beginDraw() .
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 |
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 2
Source File: GifRenderEllo025LoadingAnimationV3.java From haxademic with MIT License | 6 votes |
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 3
Source File: TextureSvg3dExtruded.java From haxademic with MIT License | 6 votes |
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 4
Source File: Demo_MaskConcentric.java From haxademic with MIT License | 6 votes |
public void updateShadows() { for (int i = 0; i < numCircles; i++) { PGraphics shadow = shadows[i]; shadow.beginDraw(); shadow.clear(); shadow.image(images[i], 0, 0); BlurProcessingFilter.instance(p).setBlurSize(12); BlurProcessingFilter.instance(p).setSigma(2.4f); for (int j = 0; j < 6; j++) { BlurProcessingFilter.instance(p).applyTo(shadow); } colorTransformShader.set("color", 0f, 0f, 0f); shadow.filter(colorTransformShader); shadow.endDraw(); } }
Example 5
Source File: PG.java From haxademic with MIT License | 6 votes |
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 6
Source File: PG.java From haxademic with MIT License | 6 votes |
public static void drawTestPattern(PGraphics pg) { pg.beginDraw(); pg.noStroke(); int cellSize = pg.pixelWidth / 20; int twoCells = cellSize * 2; for( int x=0; x < pg.width; x+= cellSize) { for( int y=0; y < pg.height; y+= cellSize) { if( ( x % twoCells == 0 && y % twoCells == 0 ) || ( x % twoCells == cellSize && y % twoCells == cellSize ) ) { pg.fill(0); } else { pg.fill(255); } pg.rect(x,y,cellSize,cellSize); } } pg.endDraw(); }
Example 7
Source File: HaiBlobsSSAO.java From haxademic with MIT License | 6 votes |
protected void builtGradientTextureLoop() { int textureW = p.width * 1; int textureH = p.height; int gradientW = textureW / 4; PGraphics img = p.createGraphics(textureW, textureH, P.P2D); img.smooth(8); tickerFXBuffer = p.createGraphics(textureW, textureH, P.P2D); tickerFXBuffer.smooth(8); img.beginDraw(); img.noStroke(); img.translate(gradientW / 2, textureH/2); Gradients.linear(img, gradientW, textureH, COLOR_1, COLOR_3); img.translate(gradientW, 0); Gradients.linear(img, gradientW, textureH, COLOR_3, COLOR_2); img.translate(gradientW, 0); Gradients.linear(img, gradientW, textureH, COLOR_2, COLOR_4); img.translate(gradientW, 0); Gradients.linear(img, gradientW, textureH, COLOR_4, COLOR_1); img.endDraw(); BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width); BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width); BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width); BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width); ticker = new TickerScroller(img, p.color(255), textureW, textureH, (float)textureW / (float)_frames); }
Example 8
Source File: Demo_PGraphicsKeystone_Grid.java From haxademic with MIT License | 5 votes |
protected void drawApp() { p.background(0); // update textures shaderPattern.set("time", p.frameCount * 0.01f); shaderPattern2.set("time", p.frameCount * 0.01f); // update buffers for (int i = 0; i < keystoneQuads.length; i++) { PGraphics pg = keystoneQuads[i].pg(); pg.beginDraw(); if(i % 2 == 1) pg.filter(shaderPattern); else pg.filter(shaderPattern2); pg.image(overlayImage, 0, 0, pg.width, pg.height); pg.endDraw(); } // draw test patterns if(testPattern == true) { for (int i = 0; i < keystoneQuads.length; i++) { keystoneQuads[i].drawTestPattern(); } } // draw to screen for (int i = 0; i < keystoneQuads.length; i++) { keystoneQuads[i].update(p.g); keystoneQuads[i].fillSolidColor(p.g, p.color(255, 0, 0, 127)); } }
Example 9
Source File: SavedPointUI.java From haxademic with MIT License | 5 votes |
public void drawDebug(PGraphics pg, boolean offscreen) { if(isShowing()) { if(offscreen) pg.beginDraw(); drawPoint(pg); if(offscreen) pg.endDraw(); } }
Example 10
Source File: MoireProposal.java From haxademic with MIT License | 5 votes |
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 11
Source File: PG.java From haxademic with MIT License | 5 votes |
public static void rotateRedraw(PGraphics pg, float radians) { pg.beginDraw(); PG.setDrawCenter(pg); pg.pushMatrix(); PG.setCenterScreen(pg); pg.rotate(radians); pg.image(pg, 0, 0); pg.popMatrix(); PG.setDrawCorner(pg); pg.endDraw(); }
Example 12
Source File: MoireProposal.java From haxademic with MIT License | 5 votes |
public void drawNumberToTexture(String str, PGraphics tex) { tex.beginDraw(); tex.fill(0); tex.textFont(font); tex.textAlign(P.CENTER, P.TOP); tex.text(str, 0, p.height * 0.2f, p.width, p.height * 0.8f); tex.endDraw(); }
Example 13
Source File: HaiBlobs.java From haxademic with MIT License | 5 votes |
protected void builtGradientTextureLoop() { int textureW = p.width * 4; int textureH = p.height; int gradientW = textureW / 6; PGraphics img = p.createGraphics(textureW, textureH, P.P2D); img.smooth(8); tickerFXBuffer = p.createGraphics(textureW, textureH, P.P2D); tickerFXBuffer.smooth(8); img.beginDraw(); img.noStroke(); img.translate(gradientW / 2, textureH/2); Gradients.linear(img, gradientW, textureH, COLOR_1, COLOR_2); img.translate(gradientW, 0); Gradients.linear(img, gradientW, textureH, COLOR_2, COLOR_3); img.translate(gradientW, 0); Gradients.linear(img, gradientW, textureH, COLOR_3, COLOR_4); img.translate(gradientW, 0); Gradients.linear(img, gradientW, textureH, COLOR_4, COLOR_5); img.translate(gradientW, 0); Gradients.linear(img, gradientW, textureH, COLOR_5, COLOR_6); img.translate(gradientW, 0); Gradients.linear(img, gradientW, textureH, COLOR_6, COLOR_1); img.endDraw(); BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width); BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width); BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width); BlurHFilter.instance(p).setBlurByPercent(0.5f, img.width); ticker = new TickerScroller(img, p.color(255), textureW, textureH, (float)textureW / (float)_frames); }
Example 14
Source File: ImageUtil.java From haxademic with MIT License | 5 votes |
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 15
Source File: ImageUtil.java From haxademic with MIT License | 5 votes |
public static PImage imageToImageWithPadding(PImage img, float scaleCanvasUp) { PGraphics pg = P.p.createGraphics(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.copy(); }
Example 16
Source File: Clocktower.java From haxademic with MIT License | 5 votes |
protected void drawTemplateOverlay(PGraphics pg) { pg.beginDraw(); pg.blendMode(PBlendModes.BLEND); PG.resetPImageAlpha(pg); PG.setDrawCorner(pg); pg.shape(template, 0, 0); pg.endDraw(); }
Example 17
Source File: PG.java From haxademic with MIT License | 5 votes |
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 18
Source File: BezierSurface.java From sketch-mapper with MIT License | 4 votes |
/** * Actual rendering of the surface. Is called from the render method. * Should normally not be accessed directly. * * @param g * @param tex */ private void renderSurface(PGraphics g, PImage tex) { float tWidth = 1; float tHeight = 1; float tOffX = 0; float tOffY = 0; tWidth = tex.width * (textureWindow[1].x); tHeight = tex.height * (textureWindow[1].y); tOffX = tex.width * textureWindow[0].x; tOffY = tex.height * textureWindow[0].y; if (this.isUsingEdgeBlend() || this.isUsingSurfaceMask()) { if (bufferScreen == null || bufferScreen.width != this.getBufferScreenWidth()) { bufferScreen = parent.createGraphics(this.getBufferScreenWidth(), this.getBufferScreenWidth()); } bufferScreen.beginDraw(); bufferScreen.beginShape(PApplet.QUADS); bufferScreen.texture(tex); bufferScreen.vertex(0, 0, tOffX, tOffY); bufferScreen.vertex(bufferScreen.width, 0, tWidth + tOffX, tOffY); bufferScreen.vertex(bufferScreen.width, bufferScreen.height, tWidth + tOffX, tHeight + tOffY); bufferScreen.vertex(0, bufferScreen.height, tOffX, tHeight + tOffY); bufferScreen.endShape(PApplet.CLOSE); bufferScreen.endDraw(); if (this.isUsingSurfaceMask()) { // maskFilter.setParameterValue("mask_factor", 0.0f); // maskFilter.apply(new GLTexture[]{bufferScreen.getTexture(), surfaceMask}, maskedTex); // applyEdgeBlendToTexture(maskedTex); } else { applyEdgeBlendToTexture(bufferScreen.get()); } } g.beginDraw(); g.noStroke(); g.beginShape(PApplet.QUADS); if (this.isUsingSurfaceMask() || this.isUsingEdgeBlend()) { g.texture(maskedTex); tOffX = 0; tOffY = 0; tWidth = maskedTex.width; tHeight = maskedTex.height; } else { g.texture(tex); if (bufferScreen != null) bufferScreen = null; } for (int i = 0; i < GRID_RESOLUTION; i++) { for (int j = 0; j < GRID_RESOLUTION; j++) { g.vertex(vertexPoints[i][j].x, vertexPoints[i][j].y, vertexPoints[i][j].z + currentZ, ((float) i / GRID_RESOLUTION) * tWidth + tOffX, ((float) j / GRID_RESOLUTION) * tHeight + tOffY); g.vertex(vertexPoints[i + 1][j].x, vertexPoints[i + 1][j].y, vertexPoints[i + 1][j].z + currentZ, (((float) i + 1) / GRID_RESOLUTION) * tWidth + tOffX, ((float) j / GRID_RESOLUTION) * tHeight + tOffY); g.vertex(vertexPoints[i + 1][j + 1].x, vertexPoints[i + 1][j + 1].y, vertexPoints[i + 1][j + 1].z + currentZ, (((float) i + 1) / GRID_RESOLUTION) * tWidth + tOffX, (((float) j + 1) / GRID_RESOLUTION) * tHeight + tOffY); g.vertex(vertexPoints[i][j + 1].x, vertexPoints[i][j + 1].y, vertexPoints[i][j + 1].z + currentZ, ((float) i / GRID_RESOLUTION) * tWidth + tOffX, (((float) j + 1) / GRID_RESOLUTION) * tHeight + tOffY); } } g.endShape(PApplet.CLOSE); g.endDraw(); }
Example 19
Source File: Demo_Kinect_FloorWatchMapped.java From haxademic with MIT License | 4 votes |
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 20
Source File: Silhouect.java From haxademic with MIT License | 4 votes |
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"); }