Skip to content

Commit

Permalink
20
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Nov 20, 2024
1 parent 16385d7 commit f8004c2
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
Binary file added 2024/sketch_2024_11_20/sketch_2024_11_20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions 2024/sketch_2024_11_20/sketch_2024_11_20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import py5

from py5 import Py5Vector as Vector

SQRT2 = py5.sqrt(2)

shapes = []

star_side = 20.2


def setup():
global current_pos, heading
py5.size(500, 500)
py5.background(0)
py5.no_stroke()
py5.color_mode(py5.HSB)

current_pos = Vector(0, 0)
heading = 0
octagon_side = star_side * 2 + star_side * SQRT2

forward(-star_side * SQRT2 / 2)
turn(-90)
forward(octagon_side / 2)
set_heading(0)
#star = []
for i in range(16):
#star.append(current_pos)
if i % 2 == 0:
turn(-45)
shapes.append(square_pts(star_side))
else:
turn(90)
shapes.append(triangle_pts(octagon_side / SQRT2))
forward(star_side)
#shapes.insert(0, star)
forward(-star_side)
turn(-90)
forward(octagon_side / SQRT2)

ow = octagon_side + 2 * octagon_side / SQRT2
for i in range(4):
x = i * ow
for j in range(4):
y = j * ow
with py5.push_matrix():
py5.translate(x, y)
for i, shp in enumerate(shapes):
#py5.fill((255 - i * 32) % 255, 200, 200)
py5.fill((i * 8) % 255, 200, 200)
draw_poly(shp)

py5.save(__file__[:-3] + '.png')

def forward(d):
global current_pos
current_pos = current_pos.copy + (Vector.from_heading(heading) * d)

def set_heading(deg):
global heading
heading = py5.radians(deg)

def turn(deg):
global heading
heading += py5.radians(deg)

def draw_poly(pts):
with py5.begin_closed_shape():
py5.vertices(pts)

def triangle_pts(d):
s = (d * SQRT2) / (2 + SQRT2)
pts = []
pts.append(current_pos)
turn(-90)
forward(d)
pts.append(current_pos)
turn(-90-45)
forward(s)
pts.append(current_pos)
turn(-45)
forward(s)
pts.append(current_pos)
turn(90)
forward(s)
pts.append(current_pos)
turn(-45)
forward(s)
pts.append(current_pos)
turn(-90-45)
forward(d)
return pts

def square_pts(d):
pts = []
for _ in range(4):
pts.append(current_pos)
forward(d)
turn(90)
return pts

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_11_20

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

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



---

### sketch_2024_11_19
Expand Down

0 comments on commit f8004c2

Please sign in to comment.