Skip to content

Commit

Permalink
16
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Dec 17, 2024
1 parent f561071 commit 903e2bc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Binary file added 2024/sketch_2024_12_16/sketch_2024_12_16.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions 2024/sketch_2024_12_16/sketch_2024_12_16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Delaunay play
from itertools import product

import py5
from shapely import Polygon
from scipy.spatial import Delaunay
import numpy as np

num_points = 200

def setup():
py5.size(600, 600)
py5.color_mode(py5.HSB)
new_points()

def new_points():
global seed_points, shapely_regions
W = 60
R = 20
seed_points = []
for i in range(2):
seed_points.extend((x + (i - 1) * py5.random(-R, R),
y + i * py5.random(-R, R)) for x, y
in product(range(0, py5.width + W, W),
range(0, py5.height+ W, W)))
pts = np.array(seed_points)
tri = Delaunay(seed_points)
shapely_regions = [Polygon(vs) for vs in pts[tri.simplices]]

def draw():
py5.background(0)
py5.translate(50, 50)
py5.scale(500 / 600)
py5.stroke(0)
for p in shapely_regions:
#py5.no_stroke()
#print(p.area)
py5.fill(py5.remap(p.area, 250, 2500, 0, 255), 200, 200)
#py5.fill(16 * len(p.exterior.coords), 200, 200)
py5.shape(py5.convert_cached_shape(p))
if py5.is_key_pressed:
py5.fill(255)
py5.no_stroke()
for x, y in seed_points:
py5.circle(x, y, 5)

def key_pressed():
if py5.key == ' ':
new_points()
elif str(py5.key).lower() == 's':
py5.save_frame('out###.png')


py5.run_sketch(block=False)
10 changes: 10 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ Here are listed some of the tools I have been using more recently:
2024 \| [<b>2023</b>](2023.md) \| [<b>2022</b>](2022.md) \| [<b>2021</b>](2021.md) \| [<b>2020</b>](2020.md) \| [<b>2019</b>](2019.md) \| [<b>2018</b>](2018.md)


---

### sketch_2024_12_16

![sketch_2024_12_16](https://raw.githubusercontent.com/villares/sketch-a-day/main/2024/sketch_2024_12_16/sketch_2024_12_16.gif)

[sketch_2024_12_16](https://github.com/villares/sketch-a-day/tree/main/2024/sketch_2024_12_16) [[py5](https://py5coding.org/)]



---

### sketch_2024_12_15
Expand Down

0 comments on commit 903e2bc

Please sign in to comment.