#Processing #Python #numpy #shapely #py5 #sketchAday for 24th and 25th May #def draw(): background(200) fill(255, 100) draw_shapely(mp) fill(0, 200, 0, 200) draw_shapely(union) save('out.png') def draw_shapely(shp): if isinstance(shp, (MultiPolygon, MultiLineString)): for p in shp.geoms: draw_shapely(p) elif isinstance(shp, Polygon): begin_shape() for x,y in shp.exterior.coords: vertex(x,y) for hole in shp.interiors: begin_contour() for x,y in hole.coords: vertex(x,y) end_contour() end_shape(CLOSE) elif isinstance(shp, LineString): with push_style(): no_fill() begin_shape() for x,y in shp.coords: vertex(x,y) end_shape()"/> Inumerous fused white bars connecting 16 points on a grid form a mask, the holes show an earlier numpy skerch of concentric colored circles.  from itertools import combinations, product from shapely import Point, LineString, Polygon from shapely import MultiPoint, MultiLineString, MultiPolygon import shapely import numpy as np  grid = [] margin = 0 step = 300  def setup():  global paths, union, mp  size(900, 900)  w, h = width, height  pts = list(product(range(margin, w + 1, step), repeat=2))  combos = combinations(pts, 2)  pairs = [((a, b), (c, d)) for ((a, b), (c, d)) in combos     if dist(a, b, c, d) < step * 3]  3print(pairs)  paths = [LineString(combo).buffer(7) for combo in pairs]  union = shapely.unary_union(paths)    R = np.linspace(0, 255, w).reshape(1, -1)  G = np.linspace(0, 255, h).reshape(-1, 1)  B = np.random.uniform(128, 255, (h, w))  A = np.array([[128 + dist(w /2, h / 2, x, y) % 128        for x in range(w)]        for y in range(h)])  rgba = np.dstack(np.broadcast_arrays(R, G, B, A))  img = create_image_from_numpy(rgba, 'RGBA');   image(img, 0, 0)  fill(255)  stroke_weight(2)  draw_shapely(union)  save('out.png')  def draw_shapely(shp):  if isinstance(shp, MultiPolygon):   for p in shp.geoms:    draw_shp(p)  elif isinstance(shp, Polygon):   begin_shape()   for x, y in shp.exterior.coords:    vertex(x, y)   for hole in shp.interiors:    begin_contour()    for x, y in hole.coords:     vertex(x, y)    end_contour()   end_shape(CLOSE)

⤋ Read More