Alexandre B A Villares 2022-02-28 11:28:35 -03:00
rodzic eafda22065
commit fde7cbb2d1
5 zmienionych plików z 145 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,84 @@
from itertools import product
from random import shuffle
patterns = [ # TL, BL, TR, BR (1, 2, 3, 4),
(1, 1, 1, 1), (1, 1, 0, 0), (0, 0, 1, 1), (1, 0, 0, 0),
(0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1), (0, 0, 0, 0),
]
SPACING, MARGIN = 0.90, 50
M_SIZE = 22
modules = {}
def setup():
size(500, 500)
rect_mode(CENTER)
text_align(CENTER, CENTER)
positions = product(range(10), repeat=2)
for pos in positions:
ptts = patterns[:]#; shuffle(ptts)
m = Module(pos, ptts)
modules[pos] = m
def draw():
background(200)
for k, v in modules.items():
v.plot()
v.check_nbs()
class Module:
def __init__(self, p, vals):
self.p = p
self.vals = vals
def plot(self):
stroke(128)
ms = M_SIZE
corners = product((ms / 2, -ms / 2), repeat=2)
x = ms + self.p[0] * ms * 2 * SPACING + MARGIN
y = ms + self.p[1] * ms * 2 * SPACING + MARGIN
if self.vals:
vals = list(self.vals[0])
for i, j in corners:
v = vals.pop()
fill(v * 255, 150)
square(x + i, y + j, ms)
fill(255, 0, 0)
#text(v, x + i, y + j)
def check_nbs(self):
for (ni, nj), check in NBS_CHECK.items():
si, sj = self.p
nb = modules.get((si + ni, sj + nj))
if nb and nb.vals:
match = False
nv = nb.vals[0]
for sv in self.vals:
if check(sv, nv):
match = True
if nb.vals and not match:
nb.vals.pop(0)
TL, BL, TR, BR = 0, 1, 2, 3 # (-1,-1),(1,-1),(1,-1),(1,1)
NBS = (
(-1, -1), (-1, 0), (-1, 1),
( 0, -1), ( 0, 1),
( 1, -1), ( 1, 0), ( 1, 1)
)
NBS_CHECK = {
#(-1, -1): (lambda s, o: s[TL] == o[BL] ),
(0, -1): (lambda s, o: s[TL] == o[BL] and s[TR] == o[BR]),
(0, 1): (lambda s, o: s[BL] == o[TL] and s[BR] == o[TR]),
(-1, 0): (lambda s, o: s[TL] == o[TR] and s[BL] == o[BR]),
(1, 0): (lambda s, o: s[TR] == o[TL] and s[BR] == o[BL]),
}
def key_pressed():
if key == 'q':
modules[(5, 5)].vals[:] = [(0, 0, 0, 0)]

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.4 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 53 KiB

Wyświetl plik

@ -0,0 +1,49 @@
from random import choice
add_library('geomerative')
def setup():
size(500, 500)
RG.init(this)
noLoop()
def draw():
background(200)
gp = list(range(50, width, 100))
polys = [rg_bar(choice(gp), choice(gp),
choice(gp), choice(gp), 10, 10, sqrt(10))
for _ in range(20)]
union_poly = polys.pop()
for p in polys:
union_poly = union_poly.union(p)
RG.shape(union_poly.toShape())
def keyPressed(): redraw(),
def rg_bar(p1x, p1y, p2x, p2y, w1, w2=None, o=0):
"""
trapezoid, draws a rotated quad with axis
starting at (p1x, p1y) ending at (p2x, p2y) where
w1 and w2 are the starting and ending side widths.
"""
if w2 is None:
w2 = w1
d = dist(p1x, p1y, p2x, p2y)
angle = atan2(p1x - p2x, p2y - p1y) + HALF_PI
unrotated_points = (
(p1x - o, p1y - w1 / 2),
(p1x - o, p1y + w1 / 2),
(p1x + d + o, p1y + w2 / 2),
(p1x + d + o, p1y - w2 / 2)
)
points = [rot(pt, angle, center=(p1x, p1y))
for pt in unrotated_points]
rg_points = [RPoint(x, y) for x, y in points]
return RPolygon(rg_points)
def rot(pt, angle, center=None):
xp, yp = pt
x0, y0 = center or (0, 0)
x, y = xp - x0, yp - y0 # translate to origin
xr = x * cos(angle) - y * sin(angle)
yr = y * cos(angle) + x * sin(angle)
return (xr + x0, yr + y0),

Wyświetl plik

@ -27,6 +27,18 @@ Here are listed some of the tools I have been using:
---
![sketch_2022_02_27a_geomerative](2022/sketch_2022_02_27a_geomerative/sketch_2022_02_27a_geomerative.png)
[sketch_2022_02_27a_geomerative](https://github.com/villares/sketch-a-day/tree/master/2022/sketch_2022_02_27a_geomerative) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
---
![sketch_2022_02_26a](2022/sketch_2022_02_26a/sketch_2022_02_26a.png)
[sketch_2022_02_26a](https://github.com/villares/sketch-a-day/tree/master/2022/sketch_2022_02_26a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
---
![sketch_2022_02_25a](2022/sketch_2022_02_25a/sketch_2022_02_25a.png)
[sketch_2022_02_25a](https://github.com/villares/sketch-a-day/tree/master/2022/sketch_2022_02_25a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]