kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
c3ad450ea7
commit
2fb5ddd405
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 3.6 MiB |
|
|
@ -0,0 +1,51 @@
|
|||
from itertools import product
|
||||
from random import sample, choice
|
||||
from villares.line_geometry import line_intersect
|
||||
|
||||
MARGIN = 50
|
||||
SIZE = 100
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
prepare()
|
||||
|
||||
def prepare():
|
||||
global triangles
|
||||
n = 12
|
||||
grid = list(product(range(MARGIN, width - MARGIN + 1, SIZE), repeat=2))
|
||||
points = sample(grid, n)
|
||||
triangles = [(pa, points[i - 1], points[i - 2])
|
||||
for i, pa in enumerate(points)]
|
||||
|
||||
def subdivide():
|
||||
global triangles
|
||||
new_triangles = []
|
||||
for i, (pa, pb, pc) in enumerate(triangles):
|
||||
mid_ab = midpoint(pa, pb)
|
||||
mid_bc = midpoint(pc, pb)
|
||||
mid_ac = midpoint(pa, pc)
|
||||
new_triangles.append((pa, mid_ab, mid_ac))
|
||||
new_triangles.append((pb, mid_bc, mid_ab))
|
||||
new_triangles.append((pc, mid_bc, mid_ac))
|
||||
triangles = new_triangles
|
||||
|
||||
def midpoint(a, b):
|
||||
return ((a[0] + b[0]) / 2,
|
||||
(a[1] + b[1]) / 2)
|
||||
|
||||
def draw():
|
||||
clear()
|
||||
for pa, pb, pc in triangles:
|
||||
fill(255, 100)
|
||||
stroke(255, 100)
|
||||
|
||||
triangle(pa[0], pa[1],
|
||||
pb[0], pb[1],
|
||||
pc[0], pc[1])
|
||||
|
||||
|
||||
def keyPressed():
|
||||
if key == "r":
|
||||
prepare()
|
||||
elif key == "d":
|
||||
subdivide()
|
||||
|
|
@ -26,6 +26,12 @@ Here are listed some of the tools I have been using:
|
|||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2021_01_07a](https://github.com/villares/sketch-a-day/tree/master/2021/sketch_2021_01_07a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2021_01_06a](https://github.com/villares/sketch-a-day/tree/master/2021/sketch_2021_01_06a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue