# Help creating organic looking "blobs"

**URL:** <https://discourse.processing.org/t/help-creating-organic-looking-blobs/8777>\
**Category:** Libraries\
**Created:** [February 27, 2019, 8:02pm UTC](https://discourse.processing.org/t/help-creating-organic-looking-blobs/8777 "2019-02-27T20:02:39Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [December 16, 2022, 12:33am UTC](https://discourse.processing.org/t/help-creating-organic-looking-blobs/8777/11 "2022-12-16T00:33:44Z")

</div>

I’d like to take this opportunity to post another technique that I didn’t know about at the time of this post and that I’ve been meaning to add to the above list for a couple of years now.

Some call it the “shrink-wrap” method, it consists in approximating the _[closing](https://en.wikipedia.org/wiki/Closing_(morphology))_ of a set of polygons by offsetting inward the outward offset of the whole. In more specific words, it’s the “erosion” of the “dilatation” process that precedes it.

 ![closing](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/b/6b2e4ad209cdb192965220e596f6c3145172c874.png)

_5 circles (white) are offsetted outward. The result (dashed line) is offsetted back inward (black outline)_

It’s nothing new but gives great results and is easy to implement with the help of a good library for offsetting polygons. Here’s a quick example in Python mode with a port of the [Clipper](http://www.angusj.com/clipper2/Docs/Overview.htm) library.

```auto
import clipper as cp

W, H = 600, 400 # Dimensions of canvas
N = 60 # Number of vertices for each circle
A = TAU/N # Step angle
D = 37 # Offset distance

RAD = (43, 32, 15, 54, 95) # List of radii
PTS = (PVector(355, 198), # List of points (circles' centers)
       PVector(407, 260), 
       PVector(475, 164), 
       PVector(301, 290), 
       PVector(187, 150))

def setup():
    size(W, H, P2D)
    background('#FFFFFF')
    strokeWeight(2)
    smooth(8)
    noFill()
    
    vertices = [] # List of vertices for each circle
    
    # Create a circle around each point (p) with a specific radius (r)
    for p, r in zip(PTS, RAD):
        
        # Convert circle vertices to Clipper 'Point' format
        v_list = [cp.Point(p.x + cos(A*i) * r, p.y + sin(A*i) * r) for i in xrange(N)]
        vertices.append(v_list)
        
        # Draw circles
        pushStyle()
        strokeWeight(1)
        stroke(180)
        fill(255)
        circle(p.x, p.y, r*2)
        popStyle()
    
    # Compute outward offset + inward offset (dilatation + erosion)  
    ### Args:
    ### points (Clipper Point) - Vertices of the polygon to offset
    ### delta (Float) - Offset distance
    ### jointype (Int) - 0=Square, 1=Round, 2=Miter
    
    out_offset = cp.OffsetPolygons(vertices, D, jointype=0)
    in_offset = cp.OffsetPolygons(out_offset, -D+10, jointype=1) 
    
    # Draw outline
    beginShape()
    for p in in_offset[0]:
        vertex(*p)
    endShape(CLOSE)

```

Edit: I believe @micycle 's [PGS library](https://github.com/micycle1/PGS/tree/master) does that as well (see _Erosion-Dilation_ example gif) but never had the chance to try.

---

_[View the full topic](https://discourse.processing.org/t/help-creating-organic-looking-blobs/8777)._
