Skip to content

Commit

Permalink
15
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Dec 15, 2024
1 parent 5adc9a7 commit 26bbc71
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
Binary file added 2024/sketch_2024_12_15/out1274.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/sketch_2024_12_15/sketch_2024_12_15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions 2024/sketch_2024_12_15/sketch_2024_12_15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Voronoy play
from itertools import product

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

num_points = 200

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

def new_points():
global seed_points, shapely_regions

seed_points = []
for i in range(2):
seed_points.extend((x + (i - 1) * py5.random(-10, 10),
y + i * py5.random(-10, 10)) for x, y
in product(range(0, py5.width + 60, 60),
range(0, py5.height+ 60, 60)))
shapely_regions = generate_regions(seed_points, py5.width, py5.height)
py5.stroke(255)

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

def draw():
#py5.translate(100, 100)
#py5.scale(400 / 600)
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, 4)

def key_pressed():
if py5.key == ' ':
new_points()
elif py5.key == '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_15

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

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



---

### sketch_2024_12_14
Expand Down

0 comments on commit 26bbc71

Please sign in to comment.