Skip to content

Commit

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

from py5 import Py5Vector as Vector

SQRT2 = py5.sqrt(2)

shapes = []

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
star_side = 20.2
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:
shapes.append(triangle_pts(octagon_side / SQRT2))
turn(90)
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((255 - 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):
pts = []
pts.append(current_pos)
forward(d)
pts.append(current_pos)
turn(-90-45)
forward(d * SQRT2)
pts.append(current_pos)
turn(-90-45)
forward(d)
turn(-90)
return pts

# def kite_pts(d):
# pts = []
# turn(90)
# pts.append(current_pos)
# forward(d/2)
# turn(-45)
# pts.append(current_pos)
# forward(d/2)
# turn(-90)
# pts.append(current_pos)
# forward(d)
# pts.append(current_pos)
# turn(-90-45)
# forward(d)
# turn(-90)
# turn(-90)
# 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)

0 comments on commit 3b45525

Please sign in to comment.