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

The following examples show how to use processing.core.PGraphics#line() . 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: QuadSurface.java    From sketch-mapper with MIT License 6 votes vote down vote up
/**
 * Draws the Cornerpoints
 *
 * @param g
 * @param x
 * @param y
 * @param selected
 * @param cornerIndex
 */
private void renderCornerPoint(PGraphics g, float x, float y, boolean selected, int cornerIndex) {
    g.noFill();
    g.strokeWeight(2);
    if (selected) {
        g.stroke(QuadSurface.SELECTED_CORNER_MARKER_COLOR);
    } else {
        g.stroke(QuadSurface.CORNER_MARKER_COLOR);
    }
    if (cornerIndex == getSelectedCorner() && isSelected()) {
        g.fill(QuadSurface.SELECTED_CORNER_MARKER_COLOR, 100);
        g.stroke(QuadSurface.SELECTED_CORNER_MARKER_COLOR);
    }
    g.ellipse(x, y, 10, 10);
    g.line(x, y - 5, x, y + 5);
    g.line(x - 5, y, x + 5, y);
}
 
Example 2
Source File: BezierSurface.java    From sketch-mapper with MIT License 6 votes vote down vote up
/**
 * Draws the bezier points
 *
 * @param g
 * @param x
 * @param y
 * @param selected
 * @param cornerIndex
 */
private void renderBezierPoint(PGraphics g, float x, float y, boolean selected, int cornerIndex) {
    g.noFill();
    g.strokeWeight(1);
    if (selected) {
        g.stroke(BezierSurface.SELECTED_CORNER_MARKER_COLOR);
    } else {
        g.stroke(BezierSurface.CORNER_MARKER_COLOR);
    }
    if (cornerIndex == getSelectedBezierControl() && isSelected()) {
        g.fill(BezierSurface.SELECTED_CORNER_MARKER_COLOR, 100);
        g.stroke(BezierSurface.SELECTED_CORNER_MARKER_COLOR);
    }
    g.ellipse(x, y, 10, 10);
    g.line(x, y - 5, x, y + 5);
    g.line(x - 5, y, x + 5, y);
}
 
Example 3
Source File: BezierSurface.java    From sketch-mapper with MIT License 6 votes vote down vote up
/**
 * Draws the Corner points
 *
 * @param g
 * @param x
 * @param y
 * @param selected
 * @param cornerIndex
 */
private void renderCornerPoint(PGraphics g, float x, float y, boolean selected, int cornerIndex) {
    g.noFill();
    g.strokeWeight(2);
    if (selected) {
        g.stroke(BezierSurface.SELECTED_CORNER_MARKER_COLOR);
    } else {
        g.stroke(BezierSurface.CORNER_MARKER_COLOR);
    }
    if (cornerIndex == getSelectedCorner() && isSelected()) {
        g.fill(BezierSurface.SELECTED_CORNER_MARKER_COLOR, 100);
        g.stroke(BezierSurface.SELECTED_CORNER_MARKER_COLOR);
    }
    g.ellipse(x, y, 10, 10);
    g.line(x, y - 5, x, y + 5);
    g.line(x - 5, y, x + 5, y);
}
 
Example 4
Source File: Shapes.java    From haxademic with MIT License 6 votes vote down vote up
public static void drawDashedLine(PGraphics pg, float x1, float y1, float z1, float x2, float y2, float z2, float dashLength, boolean rounds) {
	float lineLength = MathUtil.distance3d(x1, y1, z1, x2, y2, z2);
	float numDashes = (rounds) ? P.round(lineLength / dashLength) : lineLength / dashLength;
	float numSegments = (numDashes * 2) - 1;
	for (float i = 0; i < numSegments; i++) {
		if(i % 2 == 0) {
			float lineProgress = i / numSegments;
			float curX = P.lerp(x1, x2, lineProgress);
			float curY = P.lerp(y1, y2, lineProgress);
			float curZ = P.lerp(z1, z2, lineProgress);
			float nextProgress = (i + 1) / numSegments;
			if(nextProgress > 1) nextProgress = 1;
			float nextX = P.lerp(x1, x2, nextProgress);
			float nextY = P.lerp(y1, y2, nextProgress);
			float nextZ = P.lerp(z1, z2, nextProgress);
			pg.line(curX, curY, curZ, nextX, nextY, nextZ);
		}
	}
}
 
Example 5
Source File: LineTrail.java    From haxademic with MIT License 6 votes vote down vote up
public void update(PGraphics pg, PVector newPos, int colorStart, int colorEnd) {
	// init points to start point
	if(trail == null) {
		trail = new PVector[size];
		for (int i = 0; i < size; i++) trail[i] = newPos.copy();
	}
	
	// copy all positions towards tail end each step
	for (int i = size - 1; i > 0; i--) {
		trail[i].set(trail[i-1]);
	}
	trail[0].set(newPos);
	
	// render
	for (int i = 0; i < size - 1; i++) {
		PVector curSegment = trail[i]; 
		PVector nexSegment = trail[i+1]; 
		if(curSegment.dist(nexSegment) != 0) {
			if(colorStart != NO_FILL) {
				float progress = (float) i / (float) size;
				pg.stroke(P.p.lerpColor(colorStart, colorEnd, progress));
			}
			pg.line(curSegment.x, curSegment.y,  curSegment.z, nexSegment.x, nexSegment.y, nexSegment.z);
		}
	}
}
 
Example 6
Source File: Fluid.java    From haxademic with MIT License 6 votes vote down vote up
public void renderV(PGraphics pg) {
	for (int j = 0; j < height; j++) {
		for (int i = 0; i < width; i++) {
			float x = i * scale;
			float y = j * scale;
			int indx = index(i, j);
			pg.stroke(255);
			pg.strokeWeight(1);
			float vxX = vx[indx];
			float vyY = vy[indx];
			if (vxX + vyY > 0.05) {
				pg.line(x, y, x + scale * vxX, y + scale * vyY);
			}
		}
	}
}
 
Example 7
Source File: OpticalFlow.java    From haxademic with MIT License 6 votes vote down vote up
public void debugDraw(PGraphics pg, boolean colors) {
	// NOTICE! Make sure to beginDraw/endDraw if PGraphics
	for(int ix=0;ix<gw;ix++) {
		int x0=ix*gridStep+gs2;
		for(int iy=0;iy<gh;iy++) {
			int y0=iy*gridStep+gs2;
			int ig=iy*gw+ix;

			float u=df*sflowx[ig];
			float v=df*sflowy[ig];

			// draw the line segments for optical flow
			float a=P.sqrt(u*u+v*v);
			if(a>=0.1f) { // draw only if the length >=2.0
				float r=0.5f*(1.0f+u/(a+0.1f));
				float g=0.5f*(1.0f+v/(a+0.1f));
				float b=0.5f*(2.0f-(r+g));
				if(colors == false) pg.stroke(255);
				else pg.stroke(255*r,255*g,255*b);
				pg.line(x0*scaleUp,y0*scaleUp,x0*scaleUp+u*scaleUp,y0*scaleUp+v*scaleUp);
			}
		}
	}
}
 
Example 8
Source File: Demo_MultichannelAudio_BeadsJack.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	// draw
	pg.push();
	pg.noFill();
	pg.stroke(0, 255, 0);
	PG.setDrawCenter(pg);
	PG.setCenterScreen(pg);
	pg.ellipse(position.x, position.y, 20, 20);
	pg.pop();
	
	// set gains
	for (int i = 0; i < outputs; i++) {
		// get dist to speaker
		PVector speakerPos = stage.getSpeaker(i).position();
		float dist = speakerPos.dist(position);
		float distToGain = P.map(dist, 0, stage.radius() * 2, 1, 0);
		distToGain = P.constrain(distToGain, 0, 1);
		gains[i].setGain(distToGain);
		
		// draw debug to speakers
		pg.push();
		pg.noFill();
		pg.stroke(0, 255 * distToGain, 0);
		PG.setDrawCenter(pg);
		PG.setCenterScreen(pg);
		pg.line(position.x, position.y, speakerPos.x, speakerPos.y);
		float midX = (position.x + speakerPos.x) / 2f;
		float midY = (position.y + speakerPos.y) / 2f;
		pg.text(distToGain, midX, midY);
		pg.pop();
	}
}
 
Example 9
Source File: BaseSavedQuadUI.java    From haxademic with MIT License 5 votes vote down vote up
protected void showMappedRect(PGraphics pg) {
	pg.noFill();
	pg.stroke(0, 255, 0);
	pg.strokeWeight(1);
	pg.line(topLeft.x, topLeft.y, topRight.x, topRight.y);
	pg.line(topRight.x, topRight.y, bottomRight.x, bottomRight.y);
	pg.line(bottomRight.x, bottomRight.y, bottomLeft.x, bottomLeft.y);
	pg.line(bottomLeft.x, bottomLeft.y, topLeft.x, topLeft.y);
	pg.ellipse(center.x - 4, center.y - 4, 8, 8);
}
 
Example 10
Source File: VectorFlyer.java    From haxademic with MIT License 5 votes vote down vote up
public void update( PGraphics pg, boolean draws, boolean debugTarget ) {
	// color - if closer than threshold, ease towards saturated color
	pg.noStroke();
	if( distToDest < 200 ) {
		pg.fill(color.colorIntMixedWith(color2, 1f - distToDest/200f));
		// if( target != null ) BoxBetween.draw( p, new PVector(position.x, position.y, position.z), new PVector(target.x, target.y, target.z), 10 );
	} else {
		pg.fill(color.colorInt());
	}
	
	// store last position for rotation towards heading
	positionLast.set(position);
	
	//		accel = baseAccel * ( 0.5f + 0.6f * (float)Math.sin(p.frameCount * 0.01f) ); // was an effect to get particles to slow on following attractors 

	// always accelerate towards destination using basic xyz comparison & cap speed
	vector.x += ( position.x < target.x ) ? accel : -accel;
	vector.x = P.constrain(vector.x, -maxSpeed, maxSpeed);
	vector.y += ( position.y < target.y ) ? accel : -accel;
	vector.y = P.constrain(vector.y, -maxSpeed, maxSpeed);
	vector.z += ( position.z < target.z ) ? accel : -accel;
	vector.z = P.constrain(vector.z, -maxSpeed, maxSpeed);
	position.add(vector);
	
				
	if( draws == true ) { 
		// point and position
		pg.pushMatrix();
		pg.translate(position.x, position.y, position.z);
		OrientationUtil.setRotationTowards( pg, new PVector(position.x, position.y, position.z), new PVector(positionLast.x, positionLast.y, positionLast.z) );
		pg.box(10, 30, 10);
		pg.popMatrix();
		
		// line to target
		if(debugTarget) {
			pg.stroke(255);
			pg.line(position.x, position.y, position.z, target.x, target.y, target.z);
		}
	}
}
 
Example 11
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();
    }
}
 
Example 12
Source File: BezierSurface.java    From sketch-mapper with MIT License 4 votes vote down vote up
/**
 * Renders the grid in the surface. (useful in calibration mode)
 *
 * @param g
 */
private void renderGrid(PGraphics g) {
    g.beginDraw();


    g.fill(ccolor);

    g.noStroke();
    for (int i = 0; i < GRID_RESOLUTION; i++) {
        for (int j = 0; j < GRID_RESOLUTION; j++) {

            g.beginShape();
            g.vertex(vertexPoints[i][j].x, vertexPoints[i][j].y);
            g.vertex(vertexPoints[i + 1][j].x, vertexPoints[i + 1][j].y);
            g.vertex(vertexPoints[i + 1][j + 1].x, vertexPoints[i + 1][j + 1].y);
            g.vertex(vertexPoints[i][j + 1].x, vertexPoints[i][j + 1].y);
            g.endShape();

        }
    }

    g.textFont(sm.getIdFont());
    g.fill(255);
    g.textAlign(PApplet.CENTER, PApplet.CENTER);
    g.textSize(20);
    g.text("" + this.getSurfaceName(), (float) (this.getCenter().x), (float) this.getCenter().y);
    if (isLocked) {
        g.textSize(12);
        g.text("Surface locked", (float) this.getCenter().x, (float) this.getCenter().y + 26);
    }
    if (sketch != null) {
        g.textSize(10);
        g.text(sketch.getName(), (float) this.getCenter().x, (float) this.getCenter().y + 40);
    }


    g.noFill();
    g.stroke(BezierSurface.GRID_LINE_COLOR);
    g.strokeWeight(2);
    if (isSelected)
        g.stroke(BezierSurface.GRID_LINE_SELECTED_COLOR);

    if (!isLocked) {
        for (int i = 0; i <= GRID_RESOLUTION; i++) {
            for (int j = 0; j <= GRID_RESOLUTION; j++) {
                g.point(vertexPoints[i][j].x, vertexPoints[i][j].y, vertexPoints[i][j].z);
            }
        }
    }

    if (isSelected) {
        g.strokeWeight(4);
        g.stroke(BezierSurface.GRID_LINE_SELECTED_COLOR);

        //draw the outline here
        for (int i = 0; i < poly.npoints - 1; i++) {
            g.line(poly.xpoints[i], poly.ypoints[i], poly.xpoints[i + 1], poly.ypoints[i + 1]);
            if (i == poly.npoints - 2)
                g.line(poly.xpoints[i + 1], poly.ypoints[i + 1], poly.xpoints[0], poly.ypoints[0]);
        }
    }

    g.strokeWeight(1);
    g.stroke(SELECTED_OUTLINE_INNER_COLOR);
    //draw the outline here
    for (int i = 0; i < poly.npoints - 1; i++) {
        g.line(poly.xpoints[i], poly.ypoints[i], poly.xpoints[i + 1], poly.ypoints[i + 1]);
        if (i == poly.npoints - 2)
            g.line(poly.xpoints[i + 1], poly.ypoints[i + 1], poly.xpoints[0], poly.ypoints[0]);
    }


    if (!isLocked) {
        // Draw the control points.
        for (int i = 0; i < this.cornerPoints.length; i++) {
            this.renderCornerPoint(g, this.cornerPoints[i].x, this.cornerPoints[i].y, (this.activePoint == i), i);

        }

        for (int i = 0; i < this.bezierPoints.length; i++) {
            this.renderBezierPoint(g, this.bezierPoints[i].x, this.bezierPoints[i].y, (this.selectedBezierControl == i), i);
            g.strokeWeight(1);
            g.stroke(255);
            g.line(this.bezierPoints[i].x, this.bezierPoints[i].y, this.cornerPoints[(int) (i / 2)].x, this.cornerPoints[(int) (i / 2)].y);
        }

    }

    g.endDraw();
}
 
Example 13
Source File: MeshLineSegment.java    From haxademic with MIT License 4 votes vote down vote up
public void update( PGraphics pg, MODE mode, int color, float ampTotal, float amp ) {
//		if( mode == MODE.MODE_EQ_TOTAL ) {
//			pg.strokeWeight( P.constrain( ampTotal * .5f, 0, 1 ) );
//			pg.stroke(color);
//			pg.line( _point1.x, _point1.y, _point2.x, _point2.y );
//		} else 
		if( mode == MODE.MODE_EQ_BARS_BLACK ) {
			pg.strokeWeight( P.constrain( ampTotal * 1.0f, 1, 3 ) );
			pg.stroke(0);
			pg.line( _point1.x, _point1.y, _point2.x, _point2.y );
		} else if( mode == MODE.MODE_DOTS ) {
			pg.noStroke();
			pg.fill(color, P.constrain(amp * 10, 0, 255));
			float ampNormalized = P.constrain( amp * 2.f, 0, 4 );
			pg.ellipse( _point1.x, _point1.y, ampNormalized, ampNormalized );
		} 
//		else if( mode == MODE.MODE_WAVEFORMS ) {
//			PG.setDrawCorner(pg);
//			
//			amp = 5;
//			
//			if(waveformShapeFrameDrew != P.p.frameCount) {
//				for (int i = 0; i < waveformShape.getVertexCount()-2; i+=2) {
//					waveformShape.setVertex( i, waveformShape.getVertexX(i), P.p._waveformData._waveform[i] * amp );
//				}
//				waveformShapeFrameDrew = P.p.frameCount;
//			}
//						
//			waveformShape.disableStyle();
//			pg.noFill();
//			pg.stroke(color);
//			pg.strokeWeight(1);
//			pg.pushMatrix();
//			pg.translate( _point2.x, _point2.y );
//			pg.rotate(_radians);
//			pg.shape(waveformShape, 0, 0, _length, waveformShape.height);
//			
////			pg.translate( (_point1.x + _point2.x)/2f, (_point1.y + _point2.y)/2f );
////			for (int i = 1; i < waveformData._waveform.length; i++ ) {			
////				pg.line( 
////						startX + (i-1) * _spacing,
////						waveformData._waveform[(i-1)] * amp,
////						startX + i * _spacing,
////						waveformData._waveform[i] * amp 
////				);
////			}
//			pg.popMatrix();
//		} 
//		else if( mode == MODE.MODE_EQ_BARS ) {
//			pg.strokeWeight( P.constrain( amp * 0.3f, 0, 1 ) );
//			pg.stroke(color);
//			pg.line( _point1.x, _point1.y, _point2.x, _point2.y );
//		} 
		else if( mode == MODE.MODE_LINE_EXTEND ) {
			pg.strokeWeight( 1f );
			pg.stroke(color, 147);

			_utilVec.set( _point2 );
			_utilVec.lerp( _point1, P.constrain(amp/10f, 0f, 1f) );
			pg.line( _utilVec.x, _utilVec.y, _point2.x, _point2.y );

			_utilVec.set( _point1 );
			_utilVec.lerp( _point2, P.constrain(amp/10f, 0f, 1f) );
			pg.line( _utilVec.x, _utilVec.y, _point1.x, _point1.y );
		} else if( mode == MODE.MODE_NONE ) {
			// do nothing
		} else if( mode == MODE.MODE_PARTICLES ) {
			// do nothing
		} else if( mode == MODE.MODE_PERLIN) {
			float noise = P.p.noise(
					_point1.x/5f + P.p.noise(P.p.frameCount/100f), 
					_point1.y/10f + P.p.noise(P.p.frameCount/50f) 
			);
			pg.strokeWeight( 1f );
			pg.stroke(color, noise * 255f);
			pg.line( _point1.x, _point1.y, _point2.x, _point2.y );
//		} else if( mode == MODE.MODE_PROGRESS_BAR ) {
//			_progress += _progressDir * ( amp/100f );
//			if(_progressDir == 1 && _progress > 1) {
//				_progressDir = -1;
//				_progress = 1;
//			} else if(_progressDir == -1 && _progress < 0) {
//				_progressDir = 1;
//				_progress = 0;
//			} 
//			_utilLastVec.set(_utilVec);
//			
////			pg.noStroke();
////			pg.fill(color);
//			pg.noFill();
//			pg.stroke(color, 210);
//			pg.strokeWeight(1.3f);
//			_utilVec.set( _point2 );
//			_utilVec.lerp( _point1, _progress );
//			// pg.ellipse( _utilVec.x, _utilVec.y, 2, 2 );
//			pg.line( _utilVec.x, _utilVec.y, _utilLastVec.x, _utilLastVec.y );
//
		}
	}
 
Example 14
Source File: Edge.java    From haxademic with MIT License 4 votes vote down vote up
public void drawDebug(PGraphics pg) {
	pg.stroke(0, 255, 0);
	pg.line(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z);
}
 
Example 15
Source File: AbstractPathsLayer.java    From constellation with Apache License 2.0 3 votes vote down vote up
/**
 * Draw a multi-colored line from (0,0) to (0,d).
 * <p>
 * Arrowheads clutter things up when a lot of them meet at the same place.
 * Instead, we'll draw a multi-colored line to indicate head and tail.
 * <p>
 * Since only vertical lines are drawn, it is assumed that the relevant
 * graphics transformations have been done before this.
 *
 * @param image
 * @param d
 * @param width
 * @param palette
 */
private static void drawColoredLine(final PGraphics image, final float d, final float width, final int[] palette) {
    image.strokeWeight(width);
    image.strokeCap(PGraphics.SQUARE);
    for (int i = 0; i < N_COLORS; i++) {
        final float x0 = i * d / N_COLORS;
        final float y0 = width / 2;
        final float x1 = (i + 1) * d / N_COLORS;
        final float y1 = width / 2;
        image.stroke(palette[i]);
        image.fill(palette[i]);
        image.line(x0, y0, x1, y1);
    }
}