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

The following examples show how to use processing.core.PGraphics#endShape() . 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: ConstellationPolygonMarker.java    From constellation with Apache License 2.0 6 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;
    }

    graphics.pushStyle();
    graphics.strokeWeight(size == MarkerUtilities.DEFAULT_SIZE ? strokeWeight : size);
    graphics.stroke(strokeColor);
    graphics.fill(getFillColor());
    graphics.beginShape();
    positions.forEach(position -> {
        graphics.vertex(position.x, position.y);
    });
    graphics.endShape(PConstants.CLOSE);
    graphics.popStyle();

    return true;
}
 
Example 2
Source File: Shapes.java    From haxademic with MIT License 6 votes vote down vote up
public static void drawDisc( PGraphics p, float radius, float innerRadius, int numSegments ) {
	p.pushMatrix();
	
	float segmentRads = P.TWO_PI / numSegments;
	for( int i = 0; i < numSegments; i++ ) {
		p.beginShape(P.TRIANGLES);
		
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, 0 );
		p.vertex( P.cos( i * segmentRads ) * radius, P.sin( i * segmentRads ) * radius, 0 );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, 0 );
		
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, 0 );
		p.vertex( P.cos( (i + 1) * segmentRads ) * innerRadius, P.sin( (i + 1) * segmentRads ) * innerRadius, 0 );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, 0 );
		p.endShape();
	}
	
	p.popMatrix();
}
 
Example 3
Source File: PGraphicsKeystone.java    From haxademic with MIT License 5 votes vote down vote up
public void fillSolidColor( PGraphics canvas, int fill ) {
	// default single mapped quad
	canvas.noStroke();
	canvas.fill(fill);
	canvas.beginShape(PConstants.QUAD);
	canvas.vertex(topLeft.x, topLeft.y, 0);
	canvas.vertex(topRight.x, topRight.y, 0);
	canvas.vertex(bottomRight.x, bottomRight.y, 0);
	canvas.vertex(bottomLeft.x, bottomLeft.y, 0);
	canvas.endShape();
}
 
Example 4
Source File: DrawToxiMesh.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawMeshWithAudio( PGraphics p, WETriangleMesh mesh, AudioInputWrapper audioInput, boolean isWireframe, int fillColor, int strokeColor, float baseAlpha ) {
	p.beginShape(PConstants.TRIANGLES);
	int faceIndex = 0;
	int color = fillColor;
	int colorStroke = strokeColor;
	float alpha;
	Face f;

	int numVertices = mesh.getNumVertices();
	int eqStep = Math.round( 512f / (float) numVertices );

	for (Iterator<Face> i = mesh.faces.iterator(); i.hasNext();) {
		// set colors
		alpha = baseAlpha + audioInput.getFFT().spectrum[(faceIndex*eqStep)%512];
		if( isWireframe ) {
			p.noFill();
			p.stroke( colorStroke, ( baseAlpha + alpha ) * 255 );
		} else {
			p.noStroke();
			p.fill( color, ( baseAlpha + alpha ) * 255 );
		}
		
		f = i.next();
		normalMap.applyTo(f.a.normal);
		p.normal(f.a.normal.x, f.a.normal.y, f.a.normal.z);
		p.vertex(f.a.x, f.a.y, f.a.z);
		normalMap.applyTo(f.b.normal);
		p.normal(f.b.normal.x, f.b.normal.y, f.b.normal.z);
		p.vertex(f.b.x, f.b.y, f.b.z);
		normalMap.applyTo(f.c.normal);
		p.normal(f.c.normal.x, f.c.normal.y, f.c.normal.z);
		p.vertex(f.c.x, f.c.y, f.c.z);
		
		faceIndex ++;
	}
	p.endShape();
}
 
Example 5
Source File: BFLinewaveRender.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg, float frameOsc) {
	_x.update();
	_y.update();
	
	
	pg.noFill();
	pg.stroke(0);
	pg.strokeWeight(HEIGHT);
	p.strokeCap(P.SQUARE);

	float third = 1f/3f;
	float twoThird = 2f/3f;
	float sixth = 1f/6f;
	float curveAdd = 1.25f;
	curveAdd = curveAdd/2f + frameOsc * curveAdd/2f;
	
	pg.beginShape();
	pg.vertex(_x.value(), _y.value());
	pg.bezierVertex(
			_x.value() + WIDTH * sixth, _y.value(), 
			_x.value() + WIDTH * sixth, _y.value() + _index * curveAdd, 
			_x.value() + WIDTH * third, _y.value() + _index * curveAdd
			);
	pg.bezierVertex(
			_x.value() + WIDTH * (third + sixth), _y.value() + _index * curveAdd, 
			_x.value() + WIDTH * (third + sixth), _y.value(), 
			_x.value() + WIDTH * twoThird, _y.value()
			);
	pg.bezierVertex(
			_x.value() + WIDTH * (twoThird + sixth), _y.value(),
			_x.value() + WIDTH * (twoThird + sixth), _y.value() + _index * curveAdd, 
			_x.value() + WIDTH, _y.value() + _index * curveAdd
			);
	pg.endShape();
}
 
Example 6
Source File: TexturePoly.java    From haxademic with MIT License 5 votes vote down vote up
public void draw( PGraphics pg ) {
	if( _texture != null ) {
		pg.beginShape(PConstants.TRIANGLE);
		pg.texture(_texture);
		if( _mappingStyleIsFullImage == true ) {
			if( mappingOrientation == 0 ) {
				pg.vertex(x1, y1, 0, 		0, 0);
				pg.vertex(x2, y2, 0, 		_texture.width, _texture.height/2);
				pg.vertex(x3, y3, 0, 		0, _texture.height);
			} else if( mappingOrientation == 1 ) {
				pg.vertex(x1, y1, 0, 		0, 0);
				pg.vertex(x2, y2, 0, 		_texture.width, 0);
				pg.vertex(x3, y3, 0, 		_texture.width/2, _texture.height);
			} else if( mappingOrientation == 2 ) {
				pg.vertex(x1, y1, 0, 		0, _texture.height/2);
				pg.vertex(x2, y2, 0, 		_texture.width, 0);
				pg.vertex(x3, y3, 0, 		_texture.width, _texture.height);
			} else if( mappingOrientation == 3 ) {
				pg.vertex(x1, y1, 0, 		0, _texture.height);
				pg.vertex(x2, y2, 0, 		_texture.width/2, 0);
				pg.vertex(x3, y3, 0, 		_texture.width, _texture.height);
			}
		} else {
			float texScreenRatioW = (float) _texture.width / (float) pg.width;
			float texScreenRatioH = (float) _texture.height / (float) pg.height;
			pg.vertex(x1, y1, 0, 		x1 * texScreenRatioW, y1 * texScreenRatioH);
			pg.vertex(x2, y2, 0, 		x2 * texScreenRatioW, y2 * texScreenRatioH);
			pg.vertex(x3, y3, 0, 		x3 * texScreenRatioW, y3 * texScreenRatioH);
		}
		pg.endShape();
	}
}
 
Example 7
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 8
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawStar( PGraphics p, float spikes, float outerrad, float innerradpercent, float h, float rot)
{
	p.pushMatrix();

	int pi;
	float futil;
	p.beginShape(P.TRIANGLE_STRIP);
	for(pi=0;pi<spikes+1;pi++)
	{
		p.vertex(0,0,h/2);
	    futil=(pi/spikes)  * P.TWO_PI;    //current angle 
	    p.vertex(  P.cos(futil+rot)*outerrad, P.sin(futil+rot)*outerrad, 0);
	    futil=futil+ (  (1/spikes)/2 *P.TWO_PI  );
	    p.vertex(  P.cos(futil+rot)*outerrad*innerradpercent, P.sin(futil+rot)*outerrad*innerradpercent, 0);
	}
	p.endShape();
	p.beginShape(P.TRIANGLE_STRIP);
	for(pi=0;pi<spikes+1;pi++)
	{
		p.vertex(0,0,-h/2);
		futil=(pi/spikes)  * P.TWO_PI;    //current angle 
		p.vertex(  P.cos(futil+rot)*outerrad, P.sin(futil+rot)*outerrad, 0);
		futil=futil+ (  (1/spikes)/2 *P.TWO_PI  );
		p.vertex(  P.cos(futil+rot)*outerrad*innerradpercent, P.sin(futil+rot)*outerrad*innerradpercent, 0);
	}
	p.endShape();
	
	p.popMatrix();
}
 
Example 9
Source File: Polygon.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawShapeBg(PGraphics pg) {
	ArrayList<Edge> curEdges = (edgesAnim == null) ? edges : edgesAnim;
	
	pg.fill(bgColor);
	// if(collided) pg.fill(0, 255, 0, 50);
	pg.noStroke();
	pg.beginShape();
	for (int i = 0; i < curEdges.size(); i++) {
		PVector v = curEdges.get(i).v1();
		pg.vertex(v.x, v.y, v.z, v.x/pg.width, v.y/pg.height);
	}
	pg.endShape(P.CLOSE);
}
 
Example 10
Source File: DwFoldingSoftBody.java    From PixelFlow with MIT License 5 votes vote down vote up
@Override
public void displayNormals(PGraphics pg){
  pg.beginShape(PConstants.LINES);
  int     faces_count = foldingmodel.ifs.getFacesCount();
  int[][] faces       = foldingmodel.ifs.getFaces();
  for(int i = 0; i < faces_count; i++){
    int ia = faces[i][0];
    DwDisplayUtils.normal(pg, particles[ia], normals_face[i], display_normal_length);
  }
  pg.endShape();
}
 
Example 11
Source File: DwIndexedFaceSet.java    From PixelFlow with MIT License 5 votes vote down vote up
public void display(PGraphics pg){
  for(int i = 0; i < faces.length; i++){
    int[] face = faces[i];
    pg.beginShape();
    for(int j = 0; j < face.length; j++){
      vertex(pg, verts[face[j]]);
    }
    pg.endShape(PConstants.CLOSE);
  }
}
 
Example 12
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawTexturedRect(PGraphics pg, PImage texture) {
	pg.beginShape(P.QUAD);
	pg.textureMode(P.NORMAL);
	pg.texture(texture);
	pg.vertex(-texture.width/2, -texture.height/2, 			0, 0);
	pg.vertex( texture.width/2, -texture.height/2, 			1, 0);
	pg.vertex( texture.width/2,  texture.height/2, 			1, 1);
	pg.vertex(-texture.width/2,  texture.height/2, 			0, 1);
	pg.endShape();
}
 
Example 13
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawSphereWithQuads(PGraphics pg, float size) {
	float radius = size;
	float rho = radius;
	float x, y, z;

	float phi = 0;
	int phiSteps = 20;
	float phiFactor = P.PI / phiSteps;

	float theta;
	int thetaSteps = 20;
	float thetaFactor = P.TWO_PI / thetaSteps;

	for(int p = 0; p < phiSteps; p++) {
		pg.beginShape(P.QUAD_STRIP);
		theta = 0.0f;
		for(int t = 0; t < thetaSteps + 1; t++) {
			x = rho * P.sin(phi) * P.cos(theta);
			z = rho * P.sin(phi) * P.sin(theta);
			y = -rho * P.cos(phi);

			pg.normal(x, y, z);
			pg.vertex(x, y, z);

			x = rho * P.sin(phi + phiFactor) * P.cos(theta);
			z = rho * P.sin(phi + phiFactor) * P.sin(theta);
			y = -rho * P.cos(phi + phiFactor);

			pg.normal(x, y, z);
			pg.vertex(x, y, z);

			theta += thetaFactor;
		}
		phi += phiFactor;
		pg.endShape(P.CLOSE);
	}
}
 
Example 14
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawPyramid( PGraphics p, float shapeHeight, float baseWidth, boolean drawBase ){
	baseWidth *= P.HALF_PI;
	
	p.pushMatrix();
	p.rotateZ(P.radians(-45.0f));
	p.beginShape(P.TRIANGLES);
	
	int numSides = 4;
	float segmentCircumference = (2f*P.PI) / numSides;
	float halfBaseW = baseWidth / 2f;

	for( int i = 0; i < numSides; i++ )
	{
		p.vertex( 0, 0, shapeHeight );
		p.vertex( P.sin( i * segmentCircumference ) * halfBaseW, P.cos( i * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( (i + 1) * segmentCircumference ) * halfBaseW, P.cos( (i + 1) * segmentCircumference ) * halfBaseW, 0 );
	}
	
	if( drawBase ) {
		// base
		p.vertex( P.sin( 0 * segmentCircumference ) * halfBaseW, P.cos( 0 * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( 1 * segmentCircumference ) * halfBaseW, P.cos( 1 * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( 2 * segmentCircumference ) * halfBaseW, P.cos( 2 * segmentCircumference ) * halfBaseW, 0 );

		p.vertex( P.sin( 2 * segmentCircumference ) * halfBaseW, P.cos( 2 * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( 3 * segmentCircumference ) * halfBaseW, P.cos( 3 * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( 0 * segmentCircumference ) * halfBaseW, P.cos( 0 * segmentCircumference ) * halfBaseW, 0 );
	}
	
	p.endShape();
	p.popMatrix();
}
 
Example 15
Source File: QuadSurface.java    From sketch-mapper with MIT License 4 votes vote down vote up
/**
     * Actual rendering of the QUAD. Is called from the render method. Should
     * normally not be accessed directly.
     *
     * @param g
     * @param tex
     */
    private void renderQuad(PGraphics g, PImage tex) {

        tOffX = tex.width * textureWindow[0].x;
        tOffY = tex.height * textureWindow[0].y;
        tWidth = tex.width * (textureWindow[1].x);
        tHeight = tex.height * (textureWindow[1].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);
        g.texture(tex);

        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;
            }
            if (blendScreen != null) {
                blendScreen = null;
            }
        }

        for (int i = 0; i < GRID_RESOLUTION - 1; i++) {
            for (int j = 0; j < GRID_RESOLUTION - 1; j++) {

                g.vertex(vertexPoints[i][j].x,
                        vertexPoints[i][j].y,
                        vertexPoints[i][j].z + currentZ,
                        ((float) i / (GRID_RESOLUTION - 1)) * tWidth + tOffX,
                        ((float) j / (GRID_RESOLUTION - 1)) * 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 - 1)) * tWidth + tOffX,
                        ((float) j / (GRID_RESOLUTION - 1)) * 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 - 1)) * tWidth + tOffX,
                        (((float) j + 1) / (GRID_RESOLUTION - 1)) * tHeight + tOffY);

                g.vertex(vertexPoints[i][j + 1].x,
                        vertexPoints[i][j + 1].y,
                        vertexPoints[i][j + 1].z + currentZ,
                        ((float) i / (GRID_RESOLUTION - 1)) * tWidth + tOffX,
                        (((float) j + 1) / (GRID_RESOLUTION - 1)) * tHeight + tOffY);

            }
        }
        g.endShape(PApplet.CLOSE);
        g.endDraw();
    }
 
Example 16
Source File: Shapes.java    From haxademic with MIT License 4 votes vote down vote up
public static void drawDisc3D( PGraphics p, float radius, float innerRadius, float cylinderHeight, int numSegments, int color, int wallcolor ) {
	// draw triangles
	p.beginShape(P.TRIANGLES);
	
	float segmentRads = P.TWO_PI / numSegments;
	float halfHeight = cylinderHeight / 2;
	
	for( int i = 0; i < numSegments; i++ )
	{
		if( color > 0 ) p.fill( color );
		
		// top disc
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, halfHeight );
		p.vertex( P.cos( i * segmentRads ) * radius, P.sin( i * segmentRads ) * radius, halfHeight );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, halfHeight );
		
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, halfHeight );
		p.vertex( P.cos( (i + 1) * segmentRads ) * innerRadius, P.sin( (i + 1) * segmentRads ) * innerRadius, halfHeight );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, halfHeight );
		
		// bottom disc
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, -halfHeight );
		p.vertex( P.cos( i * segmentRads ) * radius, P.sin( i * segmentRads ) * radius, -halfHeight );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, -halfHeight );
		
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, -halfHeight );
		p.vertex( P.cos( (i + 1) * segmentRads ) * innerRadius, P.sin( (i + 1) * segmentRads ) * innerRadius, -halfHeight );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, -halfHeight );
		
		if( wallcolor > 0 ) p.fill( wallcolor );
		// outer wall
		p.vertex( P.cos( i * segmentRads ) * radius, P.sin( i * segmentRads ) * radius, halfHeight );
		p.vertex( P.cos( i * segmentRads ) * radius, P.sin( i * segmentRads ) * radius, -halfHeight );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, halfHeight );
		
		p.vertex( P.cos( i * segmentRads ) * radius, P.sin( i * segmentRads ) * radius, -halfHeight );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, halfHeight );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, -halfHeight );
		
		// only draw inner radius if needed
		if( innerRadius > 0 )
		{
			if( wallcolor > 0 ) p.fill(wallcolor);
			// inner wall
			p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, halfHeight );
			p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, -halfHeight );
			p.vertex( P.cos( (i + 1) * segmentRads ) * innerRadius, P.sin( (i + 1) * segmentRads ) * innerRadius, halfHeight );
			
			p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, -halfHeight );
			p.vertex( P.cos( (i + 1) * segmentRads ) * innerRadius, P.sin( (i + 1) * segmentRads ) * innerRadius, halfHeight );
			p.vertex( P.cos( (i + 1) * segmentRads ) * innerRadius, P.sin( (i + 1) * segmentRads ) * innerRadius, -halfHeight );
		}
	}
	
	p.endShape();
}
 
Example 17
Source File: ImageUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static void drawTextureMappedRect(PGraphics dest, PImage texture, int subdivideX, int subdivideY, float topLeftX, float topLeftY, float topRightX, float topRightY, float bottomRightX, float bottomRightY, float bottomLeftX, float bottomLeftY) {
	// draw to screen with pinned corner coords
	// generalized version ported from PGraphicsKeystone
	// inspired by: https://github.com/davidbouchard/keystone & http://marcinignac.com/blog/projectedquads-source-code/
	dest.textureMode(PConstants.IMAGE);
	dest.noStroke();
	dest.fill(255);
	dest.beginShape(PConstants.QUAD);
	dest.texture(texture);
	
	if(subdivideX > 0) {
		// subdivide quad for better resolution
		float stepsX = subdivideX;
		float stepsY = subdivideY;

		for( float x=0; x < stepsX; x += 1f ) {
			// calculate spread of mesh grid and uv coordinates
			float xPercent = x/stepsX;
			float xPercentNext = (x+1f)/stepsX;
			if( xPercentNext > 1 ) xPercentNext = 1;
			float uPercent = xPercent;
			float uPercentNext = xPercentNext;

			for( float y=0; y < stepsY; y += 1f ) {
				// calculate spread of mesh grid and uv coordinates
				float yPercent = y/stepsY;
				float yPercentNext = (y+1f)/stepsY;
				if( yPercentNext > 1 ) yPercentNext = 1;
				float vPercent = yPercent;
				float vPercentNext = yPercentNext;

				// calc grid positions based on interpolating columns between corners
				float colTopX = interp(topLeftX, topRightX, xPercent);
				float colTopY = interp(topLeftY, topRightY, xPercent);
				float colBotX = interp(bottomLeftX, bottomRightX, xPercent);
				float colBotY = interp(bottomLeftY, bottomRightY, xPercent);
				
				float nextColTopX = interp(topLeftX, topRightX, xPercentNext);
				float nextColTopY = interp(topLeftY, topRightY, xPercentNext);
				float nextColBotX = interp(bottomLeftX, bottomRightX, xPercentNext);
				float nextColBotY = interp(bottomLeftY, bottomRightY, xPercentNext);
				
				// calc quad coords
				float quadTopLeftX = interp(colTopX, colBotX, yPercent);
				float quadTopLeftY = interp(colTopY, colBotY, yPercent);
				float quadTopRightX = interp(nextColTopX, nextColBotX, yPercent);
				float quadTopRightY = interp(nextColTopY, nextColBotY, yPercent);
				float quadBotRightX = interp(nextColTopX, nextColBotX, yPercentNext);
				float quadBotRightY = interp(nextColTopY, nextColBotY, yPercentNext);
				float quadBotLeftX = interp(colTopX, colBotX, yPercentNext);
				float quadBotLeftY = interp(colTopY, colBotY, yPercentNext);
				
				// draw subdivided quads
				dest.vertex(quadTopLeftX, quadTopLeftY, 0, 	texture.width * uPercent, 		texture.height * vPercent);
				dest.vertex(quadTopRightX, quadTopRightY, 0, 	texture.width * uPercentNext, 	texture.height * vPercent);
				dest.vertex(quadBotRightX, quadBotRightY, 0, 	texture.width * uPercentNext, 	texture.height * vPercentNext);
				dest.vertex(quadBotLeftX, quadBotLeftY, 0, 	texture.width * uPercent, 		texture.height * vPercentNext);
			}
		}
	} else {
		// default single mapped quad
		dest.vertex(topLeftX, topLeftY, 0, 			0, 0);
		dest.vertex(topRightX, topRightY, 0, 			texture.width, 0);
		dest.vertex(bottomRightX, bottomRightY, 0, 	texture.width, texture.height);
		dest.vertex(bottomLeftX, bottomLeftY, 0, 	0,  texture.height);
	}

	dest.endShape();
}
 
Example 18
Source File: MappedTriangle.java    From haxademic with MIT License 4 votes vote down vote up
public void draw( PGraphics pg ) {
		if( _texture != null ) {
			updateVertices();
			if( _mappingStyle == MAP_STYLE_CONTAIN_TEXTURE ) {
				pg.beginShape(PConstants.TRIANGLE);
				pg.texture(_texture);
				if( _mappingOrientation == 0 ) {
					setUVCoordinates(0, 0, _texture.width, _texture.height/2, 0, _texture.height);
				} else if( _mappingOrientation == 1 ) {
					setUVCoordinates(0, 0, _texture.width, 0, _texture.width/2, _texture.height);
				} else if( _mappingOrientation == 2 ) {
					setUVCoordinates(0, _texture.height/2, _texture.width, 0, _texture.width, _texture.height);
				} else if( _mappingOrientation == 3 ) {
					setUVCoordinates(0, _texture.height, _texture.width/2, 0, _texture.width, _texture.height);
				}
				pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1), 		_UVx1.value(), _UVy1.value());
				pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2), 		_UVx2.value(), _UVy2.value());
				pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3), 		_UVx3.value(), _UVy3.value());
				pg.endShape();
			} else if( _mappingStyle == MAP_STYLE_MASK ) {
				pg.beginShape(PConstants.TRIANGLE);
				pg.texture(_texture);
				// map the screen coordinates to the texture coordinates
				// crop to fill the mapped area with the current texture
				setUVCoordinates(_maskTriangle[0].x, _maskTriangle[0].y, _maskTriangle[1].x, _maskTriangle[1].y, _maskTriangle[2].x, _maskTriangle[2].y);
				pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1), 		_UVx1.value(), _UVy1.value());
				pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2), 		_UVx2.value(), _UVy2.value());
				pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3), 		_UVx3.value(), _UVy3.value());
				pg.endShape();
			} else if( _mappingStyle == MAP_STYLE_CONTAIN_RANDOM_TEX_AREA ) {
				pg.beginShape(PConstants.TRIANGLE);
				pg.texture(_texture);
				// map the polygon coordinates to the random sampling coordinates
				setUVCoordinates(_randTriangle[0].x, _randTriangle[0].y, _randTriangle[1].x, _randTriangle[1].y, _randTriangle[2].x, _randTriangle[2].y);
				pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1), 		_UVx1.value(), _UVy1.value());
				pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2), 		_UVx2.value(), _UVy2.value());
				pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3), 		_UVx3.value(), _UVy3.value());
				pg.endShape();
			} else if( _mappingStyle == MAP_STYLE_EQ ) {
				_curColor = P.p.lerpColor(_curColor, _color, 0.1f);
				pg.beginShape(PConstants.TRIANGLE);
				pg.fill(pg.color(_curColor, P.constrain( AudioIn.audioFreq(_eqIndex) * 255, 0, 255 )));
				pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1));
				pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2));				
				pg.fill(pg.color(_curColor, P.constrain( AudioIn.audioFreq(_eqIndex) * 100, 0, 190 )));
				pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3));
				pg.endShape();
			}
			
			
			// flash fade overlay
			drawFlashFadeOverlay(pg);
			
			// overlay with gradient, oscillating from white to black over time
			float whiteFade = P.sin(P.p.frameCount / _gradientFadeDivisor); //P.constrain( AudioIn.getEqBand((_eqIndex)) * 200 * _isFlash, 0, 50 );
			pg.noStroke();
			pg.beginShape(PConstants.TRIANGLE);
			pg.fill(255*whiteFade,fakeLightAlpha);
			pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1));
			pg.fill(255*whiteFade,0);
			pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2));				
			pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3));
			pg.endShape();

//			// show debug info
//			pg.fill(255);
//			pg.textSize(20);
//			pg.text(_mappingStyle+"", _centerX, _centerY);
		}
	}
 
Example 19
Source File: Shapes.java    From haxademic with MIT License 4 votes vote down vote up
public static void drawTexturedCube(PGraphics pg, float size, PImage texture) {
	pg.beginShape(P.QUADS);
	pg.texture(texture);

	// BL, BR, TR, TL
	// front
	pg.vertex(-size,  size,  size, 		0, texture.height);
	pg.vertex( size,  size,  size, 		texture.width, texture.height);
	pg.vertex( size, -size,  size,		texture.width, 0);
	pg.vertex(-size, -size,  size,		0, 0);

	// back
	pg.vertex( size,  size, -size, 		0, texture.height);
	pg.vertex(-size,  size, -size, 		texture.width, texture.height);
	pg.vertex(-size, -size, -size,		texture.width, 0);
	pg.vertex( size, -size, -size,		0, 0);

	// left
	pg.vertex(-size,  size, -size, 		0, texture.height);
	pg.vertex(-size,  size,  size, 		texture.width, texture.height);
	pg.vertex(-size, -size,  size,		texture.width, 0);
	pg.vertex(-size, -size, -size,		0, 0);

	// right
	pg.vertex( size,  size,  size, 		0, texture.height);
	pg.vertex( size,  size, -size, 		texture.width, texture.height);
	pg.vertex( size, -size, -size,		texture.width, 0);
	pg.vertex( size, -size,  size,		0, 0);
	
	// floor
	pg.vertex(-size,  size, -size, 		0, 0);
	pg.vertex( size,  size, -size, 		texture.width, 0);
	pg.vertex( size,  size,  size,		texture.width, texture.height);
	pg.vertex(-size,  size,  size,		0, texture.height);

	// ceiling
	pg.vertex(-size, -size, -size, 		0, 0);
	pg.vertex( size, -size, -size, 		texture.width, 0);
	pg.vertex( size, -size,  size,		texture.width, texture.height);
	pg.vertex(-size, -size,  size,		0, texture.height);

	pg.endShape();
}
 
Example 20
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);
		}