Skip to content

Commit

Permalink
02
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Dec 2, 2024
1 parent 862d459 commit fe72b09
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Binary file added 2024/sketch_2024_12_02/sketch_2024_12_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions 2024/sketch_2024_12_02/sketch_2024_12_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Voronoy play

import py5
from shapely import Polygon
from scipy.spatial import Voronoi

num_points = 20

def setup():
global seed_points, shapely_regions
py5.size(600, 600)
py5.color_mode(py5.HSB)
seed_points = [(py5.random_int(py5.width), py5.random_int(py5.height))
for i in range(num_points)]
shapely_regions = generate_regions(seed_points, py5.width, py5.height)
py5.no_loop()

def generate_regions(seed_points, w, h):
# add 4 points far from the visible region
extended_points = seed_points.copy()
extended_points.extend([
(-w * 4, -h * 4),
(-w * 4, h * 4),
( w * 4, -h * 4),
( w * 4, h * 4)
])
voronoi = Voronoi(extended_points)
shapely_regions = []
for vs in voronoi.regions:
shapely_regions.append(
Polygon(voronoi.vertices[index] for index in vs if -1 not in vs)
)
return shapely_regions

def draw():
for p in shapely_regions:
py5.fill(p.area / 500 % 255, 200, 200)
py5.shape(py5.convert_cached_shape(p))
py5.fill(0)
for x, y in seed_points:
py5.circle(x, y, 5)

def key_pressed():
py5.save('out.png')


py5.run_sketch()
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_02

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

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

#scipy #Voronoi #shapely

---

### sketch_2024_12_01
Expand Down

0 comments on commit fe72b09

Please sign in to comment.