diff --git a/2025/sketch_2025_01_26/sketch_2025_01_26.gif b/2025/sketch_2025_01_26/sketch_2025_01_26.gif new file mode 100644 index 00000000..43748fb3 Binary files /dev/null and b/2025/sketch_2025_01_26/sketch_2025_01_26.gif differ diff --git a/2025/sketch_2025_01_26/sketch_2025_01_26.py b/2025/sketch_2025_01_26/sketch_2025_01_26.py new file mode 100644 index 00000000..96b06521 --- /dev/null +++ b/2025/sketch_2025_01_26/sketch_2025_01_26.py @@ -0,0 +1,57 @@ +from shapely import Polygon +import py5 + +def setup(): + py5.size(600, 600) + start() + +def start(): + global ps + crossing = True + while crossing: + pts_a = [(py5.random_int(1, 20) * 10, + py5.random_int(1, 20) * 10) + for _ in range(5)] + pts_b = [(y, -x) for x, y in pts_a] + pts = pts_a + pts_b + p = Polygon(pts) + p_mirror = Polygon([(-x, y) for x, y in pts]) + p_mirror = p_mirror.union(p) + crossing = not p_mirror.is_simple + ps = [p_mirror] + +def draw(): + py5.background(230, 240, 240) + py5.translate(py5.width / 2, py5.height / 2) + py5.no_fill() + for p in ps: + py5.shape(py5.convert_cached_shape(p)) + +def shrink(): + p = ps[-1] + new_p = p.buffer(-10, cap_style='round') + print(new_p.area) + while new_p.area > 0: + ps.append(new_p) + new_p = ps[-1].buffer(-10, cap_style='round') + +def grow(): + p = ps[-1] + new_p = p.buffer(10, cap_style='round') + print(new_p.area) + while new_p.area < 1000000: + ps.append(new_p) + new_p = ps[-1].buffer(10, cap_style='round') + + +def key_pressed(): + if py5.key == 's': + py5.save_frame('out###.png') + elif py5.key == ' ': + start() + elif py5.key == 'a': + shrink() + elif py5.key == 'z': + grow() + +py5.run_sketch(block=False) \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 6fa4b348..d0dd2681 100644 --- a/docs/README.md +++ b/docs/README.md @@ -21,6 +21,16 @@ If you appreciate what I have been doing, you may also support my artistic work, 2025 \| [2024](2024.md) \| [2023](2023.md) \| [2022](2022.md) \| [2021](2021.md) \| [2020](2020.md) \| [2019](2019.md) \| [2018](2018.md) +--- + +### sketch_2025_01_26 + +![sketch_2025_01_26](https://raw.githubusercontent.com/villares/sketch-a-day/main/2025/sketch_2025_01_26/sketch_2025_01_26.gif) + +[sketch_2025_01_26](https://github.com/villares/sketch-a-day/tree/main/2025/sketch_2025_01_26) [[py5](https://py5coding.org/)] + + + --- ### sketch_2025_01_25