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

The following examples show how to use processing.core.PGraphics#stroke() . 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: 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 2
Source File: ConstellationLineMarker.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.noFill();
    graphics.strokeWeight(size == MarkerUtilities.DEFAULT_SIZE ? strokeWeight : size);
    graphics.stroke(getFillColor());
    graphics.smooth();

    graphics.beginShape(PConstants.LINES);
    for (int i = 0; i < positions.size() - 1; ++i) {
        final MapPosition lastPosition = positions.get(i);
        final MapPosition currentPosition = positions.get(i + 1);
        graphics.vertex(lastPosition.x, lastPosition.y);
        graphics.vertex(currentPosition.x, currentPosition.y);
    }
    graphics.endShape();
    graphics.popStyle();

    return true;
}
 
Example 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: RotateRectVertices.java    From haxademic with MIT License 5 votes vote down vote up
public void drawRect(PGraphics pg, float drawW, float drawH, float size, float rotation) {
	float halfDrawW = drawW / 2f;
	float halfDrawH = drawH / 2f;
	float halfSizeX = halfDrawW * size;
	float halfSizeY = halfDrawH * size;
			
	
	pg.noFill();
	pg.stroke(255,0,0);
	pg.beginShape();
	if(rotation == 0) {
		pg.vertex(-halfSizeX, -halfSizeY);
		pg.vertex(halfSizeX, -halfSizeY);
		pg.vertex(halfSizeX, halfSizeY);
		pg.vertex(-halfSizeX, halfSizeY);
		pg.vertex(-halfSizeX, -halfSizeY);
	} else {
		float curRot = rotation;
		float radius = MathUtil.getDistance(0, 0, halfSizeX, halfSizeY);
		float tlRads = -MathUtil.getRadiansToTarget(-halfSizeX, -halfSizeY, 0, 0) + curRot;
		float trRads = -MathUtil.getRadiansToTarget(halfSizeX, -halfSizeY, 0, 0) + curRot;
		float brRads = -MathUtil.getRadiansToTarget(halfSizeX, halfSizeY, 0, 0) + curRot;
		float blRads = -MathUtil.getRadiansToTarget(-halfSizeX, halfSizeY, 0, 0) + curRot;
		pg.vertex(radius * P.cos(tlRads), -radius * P.sin(tlRads));
		pg.vertex(radius * P.cos(trRads), -radius * P.sin(trRads));
		pg.vertex(radius * P.cos(brRads), -radius * P.sin(brRads));
		pg.vertex(radius * P.cos(blRads), -radius * P.sin(blRads));
		pg.vertex(radius * P.cos(tlRads), -radius * P.sin(tlRads));
	}
	pg.endShape();
}
 
Example 10
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 11
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 12
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 13
Source File: LeapRegion.java    From haxademic with MIT License 5 votes vote down vote up
public void drawDebug(PGraphics debugGraphics) {
	if( _blockColor == -1 ) return;
	
	// set box color for (in)active states
	debugGraphics.strokeWeight(5f);
	if(_isActive == true) {
		debugGraphics.stroke(_blockColor, 255);
		debugGraphics.noFill();
	} else {
		debugGraphics.stroke(255, 127);
		debugGraphics.noFill();
	}
	debugGraphics.pushMatrix();
	
	// move to center of box location & draw box
	debugGraphics.translate(P.lerp(_right, _left, 0.5f), P.lerp(_top, _bottom, 0.5f), -1f * P.lerp(_far, _near, 0.5f));
	debugGraphics.box(_right - _left, _top - _bottom, _far - _near);
	
	// draw text control values
	if(_isActive == true) {
		debugGraphics.noStroke();
		debugGraphics.fill(255);
		debugGraphics.textSize(24);
		debugGraphics.text(MathUtil.roundToPrecision(_controlX, 2)+", "+MathUtil.roundToPrecision(_controlY, 2)+", "+MathUtil.roundToPrecision(_controlZ, 2), -50, 0);
	}
	
	debugGraphics.popMatrix();
}
 
Example 14
Source File: Polygon.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawShapeOutline(PGraphics pg) {
	pg.noFill();
	pg.stroke(255, 255, 255, 100);
	pg.beginShape();
	for (int i = 0; i < vertices.size(); i++) {
		PVector v = vertices.get(i);
		pg.vertex(v.x, v.y, v.z);
	}
	pg.endShape(P.CLOSE);
}
 
Example 15
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 16
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 17
Source File: KinectRegion.java    From haxademic with MIT License 4 votes vote down vote up
public void update(PGraphics debugGraphics) {
	IDepthCamera depthCamera = DepthCamera.instance().camera;
	
	float depthDivider = 0.3f;
       if(debugGraphics != null) {
       	debugGraphics.beginShape(PShapeTypes.QUADS);
   		debugGraphics.stroke(debugColor);
   		debugGraphics.fill( 255, pixelCount / minPixels * 10f );
       	debugGraphics.vertex(left, bottom, -near * depthDivider);
       	debugGraphics.vertex(right, bottom, -near * depthDivider);
       	debugGraphics.vertex(right, bottom, -far * depthDivider);
       	debugGraphics.vertex(left, bottom, -far * depthDivider);
       	debugGraphics.endShape();
       	debugGraphics.noStroke();
       }
       // find kinect readings in the region
	_isActive = false;
	if( depthCamera != null ) {
		pixelCount = 0;
		float controlXTotal = 0;
		float controlZTotal = 0;
		float pixelDepth = 0;
		for ( int x = left; x < right; x += pixelSkip ) {
			for ( int y = top; y < bottom; y += pixelSkip ) {
				pixelDepth = depthCamera.getDepthAt( x, y );
				if( pixelDepth != 0 && pixelDepth > near && pixelDepth < far ) {
			        if(debugGraphics != null) {
			        	debugGraphics.fill( debugColor, 127 );
			        	debugGraphics.pushMatrix();
			        	debugGraphics.translate(x, y, -pixelDepth * depthDivider);
			        	debugGraphics.box(pixelSkip, pixelSkip, pixelSkip);
			        	debugGraphics.popMatrix();
					}
					// add up for calculations
					pixelCount++;
					controlXTotal += x;
					controlZTotal += pixelDepth;
				}
			}
		}

		// if we have enough blocks in a region, update the player's joystick position
		if( pixelCount > minPixels ) {
			_isActive = true;
			// compute averages
			if( controlXTotal > 0 && controlZTotal > 0 ) {
				float avgX = controlXTotal / pixelCount;
				_controlX = (MathUtil.getPercentWithinRange(left, right, avgX) - 0.5f) * 2f;
				float avgZ = controlZTotal / pixelCount;
				_controlZ = (MathUtil.getPercentWithinRange(near, far, avgZ) - 0.5f) * 2f;

				// show debug
		        if(debugGraphics != null) {
					debugGraphics.fill( 255, 127 );
					debugGraphics.pushMatrix();
					debugGraphics.translate(avgX, bottom - 250, -avgZ * depthDivider);
					debugGraphics.box(20, 500, 20);
					debugGraphics.popMatrix();
				}
			}
		}
	}
}
 
Example 18
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 19
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 20
Source File: ConstellationClusterMarker.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean draw(final PGraphics graphics, final List<MapPosition> positions, final UnfoldingMap map) {
    if (positions.isEmpty() || isHidden()) {
        return false;
    }

    clusterCenter = new MapPosition();
    positions.forEach(position -> {
        clusterCenter.add(position);
    });
    clusterCenter.div(positions.size());

    double diameter = 0;
    if (positions.size() > 1) {
        final MapPosition minPosition = new MapPosition(
                new float[]{Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE});
        final MapPosition maxPosition = new MapPosition(
                new float[]{Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE});
        positions.forEach(position -> {
            minPosition.x = Math.min(position.x, minPosition.x);
            minPosition.y = Math.min(position.y, minPosition.y);
            maxPosition.x = Math.max(position.x, maxPosition.x);
            maxPosition.y = Math.max(position.y, maxPosition.y);
        });
        diameter = Math.sqrt(Math.pow((maxPosition.x - minPosition.x), 2)
                + Math.pow((maxPosition.y - minPosition.y), 2));
    }
    clusterRadius = Math.max((float) diameter / 2, MIN_RADIUS);

    graphics.strokeWeight(size == MarkerUtilities.DEFAULT_SIZE ? strokeWeight : size);
    graphics.stroke(strokeColor);
    graphics.fill(getFillColor());
    graphics.ellipseMode(PConstants.RADIUS);
    graphics.ellipse(clusterCenter.x, clusterCenter.y, clusterRadius, clusterRadius);

    final String clusterLabel = String.valueOf(clusterSize);
    graphics.fill(FONT_COLOR);
    graphics.textSize(FONT_SIZE);
    graphics.text(clusterLabel,
            clusterCenter.x - (CHAR_WIDTH * clusterLabel.length() * 0.6f),
            clusterCenter.y + (FONT_SIZE * 0.35f));

    return true;
}