Processing Geometry Suite

@micycle looks to be an excellent library.
As an exercise I managed to translate the contour map example to JRubyArt with the use of this VectorList shim:-

java_import 'java.util.ArrayList'
java_import 'processing.core.PVector'

class VectorList
  attr_reader :array_list
  def initialize
    @array_list =

  def <<(val)
    array_list.add(, val.y, val.z))

Here’s the sketch in JRubyArt

require_relative './vector_list'
load_library :pgs
java_import 'micycle.pgs.PGS_Contour'

attr_reader  :heights, :max, :min
MAX = -1
MIN = 9999

def setup
  sketch_title 'Contour Map'
  @max = MAX
  @min = MIN

def draw
  background(0, 0, 40)
  isolines = PGS_Contour.isolines(heights.array_list, 0.08, min, max)
  isolines.to_hash.each do |isoline, value|
        map1d(value, min..max, 50..255),
        map1d(isoline.get_vertex(0).x, 0..width, 50..255),
        map1d(isoline.get_vertex(0).y, 0..height, 50..255)

def populate_height_map
  @heights =

  res = 16
  anim_speed = 0.005

  grid(width + res, height + res, res, res) do |x, y|
    z = norm(noise(x*0.01 + frame_count*anim_speed, y*0.01 + frame_count*anim_speed), -1.0, 1.0)
    h =, y, 0)
    z += h.dist(, mouse_y, 0))*0.005
    h.z = z
    heights << h
    @max = [max, z].max
    @min = [min, z].min

def settings
  size(800, 800)

The norm is used because JRubyArt now uses OpenSimplex2 noise (values -1.0…1.0)


Nice. I’m surprised Ruby has such interoperability with Java to the point where you can simply import Java libraries…

@micycle That’s down to the magic of JRuby, which is actively maintained cf Jython. The bit that is down to me is the load_library feature which can be used to load pure java libraries, pure ruby libraries and hybrid libraries.
PS: I tried using library on 64 bit arm (linux), and got unsupported architecture message any idea why that might be?

1 Like

Does it say which library?

My bad, it turns out there was an issue with the PiCrate library loader (should have recognised my own error message!!!). I tested library with vanilla processing-4.0 on Manjaro Arm64 and it worked. Here’s a snapshot of the sketch running using a patched PiCrate:-


Thanks very much @micycle - My post 2D lineart - culling hidden lines for SVG output / Plotting explains the problem I was facing.

I needed hidden line removal when overlaying shapes for plotter output (can’t use fills, limited to lines). I would have had no idea when it comes to geometry :slight_smile:

Time to dump my own solutions in favour of your library. Thank-you very much for packaging it so beautifully.

1 Like

Wow! How the hell did I not know this project existed? Wonderful project @micycle

1 Like

1.3.0 Update

I have recently released PGS 1.3.0, which has been in the making for 10 months. Since I originally shared the library here, its functionality has grown considerably so I thought it fitting to share the library again with this update.

New classes (since 1.0):

  • PGS_CirclePacking — a class for circle packings of shapes, subject to varying constraints and patterns of tangencies.
  • PGS_PointSet — a class that generates sets of 2D points having a variety of different distributions and constraints.
  • PGS_Coloring — a class for intelligent coloring of meshes (or mesh-like shapes) such that no two adjacent faces have the same color, while minimising the number of colors used.
  • PGS_Tiling — a class for tiling, tessellation and subdivision of the plane using periodic or non-periodic geometric shapes.
  • PGS_Meshing - a class to host mesh generation methods (excluding triangulation).
  • PGS_Hull — a dedicated class for convex and concave hulls of polygons and point sets.
  • PGS_SegmentSet — a class that generates random sets of non-intersecting line segments.

Just a few examples:



Thank you. It’s a good resource.

OMG! I can’t go near this library… It’s exactly what I find myself painstackingly coding every time… on P5 :confused:

Congrats, though, awesome addition. I’ll probably go through your code trying to understand your solutions and maybe reuse on P5. It looks tidy, fresh, thanks a lot!


Hello micycle and THANK YOU for your amazing work !

Like wageDu said, there are a numbers of things I’m trying to code myself and I feel almost like cheating to use your library :wink:
It’s a shame that processing doesn’t include it in the tools menu …

1 Like

The type string is ambiguous, what am I doing wrong?


1 Like

I’m having this error too and I’m wondering if anyone has solutions.

Ok, can you post your code?

This is from the examples directory, and PGS.jar is in the sketch’s code folder.

// This example shows concave hull, constrained voronoi, shape subtract & intersection, slicing, pointsOnExterior, shape intersection points
import processing.javafx.*;
import micycle.pgs.*;
import java.util.List;

PShape polygon;
List<PShape> subPartitions;
PVector center;

void setup() {
  size(800, 800, FX2D);
  colorMode(HSB, 1);
  stroke(color(324f/360f, 0.79, 0.93));
  center = new PVector(width/2, height/2);

  List<PVector> randomPoints = PGS_PointSet.poisson(30, 30, width - 30, height - 30, 15,1337);
  polygon = PGS_Hull.concaveHullBFS2(randomPoints, 0);


  PShape partitions = PGS_Processing.convexPartition(polygon);
  subPartitions = new ArrayList<PShape>();
  for (PShape p : partitions.getChildren()) {
    PShape split = PGS_Processing.split(p);

void draw() {
  background(0, 0, 0.075);

  PShape star = PGS_Construction.createStar(width/2, height/2, 11, mouseX*0.4, mouseX*0.4+100, 1);
  star = PGS_Transformation.rotateAroundCenter(star, frameCount*0.01f);
  star = PGS_Morphology.simplify(star, 1);
  PShape smallStar = PGS_Transformation.scale(star, 0.5);

  PShape outer =  PGS_ShapeBoolean.subtract(polygon, star);
  PShape inner = PGS_ShapeBoolean.subtract(star, polygon);
  inner = PGS_ShapeBoolean.subtract(inner, smallStar);
  PGS_Conversion.setAllFillColor(inner, color(.45, .5, .9));

  for (int i = 0; i < outer.getChildCount(); i++) {
    try {
      PShape p = PGS_Voronoi.innerVoronoi(outer.getChild(i), true);
      PGS_Conversion.setAllStrokeColor(p, color(i / ((float) outer.getChildCount() - 1), 1, 1), 2);
    catch (Exception e) {

  PShape polygon2 = PGS_ShapeBoolean.subtract(polygon, smallStar);

  PGS_Conversion.setAllStrokeColor(polygon2, color(1), 3);

  PShape innerInner = PGS_ShapeBoolean.intersect(polygon, smallStar);
  List<PVector> ps = PGS_Processing.pointsOnExterior(star, 2, 0);
  innerInner = PGS_Processing.slice(innerInner, ps.get(0), ps.get(1)).getChild(0);

  List<PVector> intersections = PGS_Processing.shapeIntersection(polygon, inner);
  for (PVector x : intersections) {
    point(x.x, x.y);

PGS.jar is in the sketch’s code folder

There seems to be a problem using the library when it’s hosted with the sketch (potentially a bug with Processing itself).

Install it as a permanent Processing library (in the Processing libraries folder) and things work fine.
Probably at: Documents\Processing\libraries\PGS\library\PGS.jar

@paulgoux ^^

1.4.0 Update

I have just released v1.4.0 of PGS and I’m once again presenting some of the new functionality here:



This library is incredible, thank you! Previous releases included a javadoc jar which I used to create a PGS docset for Dash via their javadocset tool. Would it be possible to get the updated javadocs as well?

Thanks again!

1 Like

I’ve now added the javadoc jar to the release on Github.