kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
197a8b4090
commit
d03ebf413c
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 8.3 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 8.5 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 8.0 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 191 KiB |
|
@ -0,0 +1,89 @@
|
|||
from random import choice, shuffle
|
||||
|
||||
NODE_SIZE = 5
|
||||
|
||||
nodes, edges = [], set()
|
||||
|
||||
# NGBS = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
|
||||
ONGBS = [(0, 1), (1, 0), (0, -1), (-1, 0), (-1, -1)]
|
||||
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
global grid
|
||||
strokeWeight(2)
|
||||
|
||||
imagem = draw_text('PCD', 250, 240, text_size=180)
|
||||
grid = make_grid(imagem, width, height, 10, margin=20)
|
||||
|
||||
def draw():
|
||||
background(170, 170, 200)
|
||||
|
||||
for a, b in edges:
|
||||
noFill()
|
||||
x0, y0, c1 = grid[a]
|
||||
x1, y1, c2 = grid[b]
|
||||
stroke(lerpColor(c1, c2, 0.5))
|
||||
line(x0, y0, x1, y1)
|
||||
|
||||
add_connected(ONGBS)
|
||||
|
||||
|
||||
def keyPressed():
|
||||
if key == ' ':
|
||||
nodes[:] = []
|
||||
edges.clear()
|
||||
if key == 'n':
|
||||
add_random_node()
|
||||
if key == 's':
|
||||
saveFrame("s####.png")
|
||||
|
||||
|
||||
def add_connected(nbs):
|
||||
if nodes:
|
||||
i, j = nodes[-1]
|
||||
shuffle(nbs)
|
||||
for ni, nj in nbs:
|
||||
other = i + ni, j + nj
|
||||
if grid.get(other, None) and other not in nodes:
|
||||
nodes.append(other)
|
||||
edges.add(((i, j), other))
|
||||
break
|
||||
else:
|
||||
if len(nodes) < len(grid):
|
||||
# add_random_node()
|
||||
shuffle(nodes)
|
||||
# nodes[:] = [nodes[-1]] + nodes[:-1]
|
||||
println("ops!")
|
||||
|
||||
def add_random_node():
|
||||
if len(nodes) < len(grid):
|
||||
k = choice(grid.keys())
|
||||
while k in nodes:
|
||||
k = choice(grid.keys())
|
||||
nodes.append(k)
|
||||
|
||||
def draw_text(txt, x, y, text_size=120):
|
||||
img = createGraphics(width, height)
|
||||
img.beginDraw()
|
||||
img.textAlign(CENTER, CENTER)
|
||||
img.textSize(text_size)
|
||||
# img.textFont(f)
|
||||
img.text(txt, x, y)
|
||||
img.endDraw()
|
||||
return img
|
||||
|
||||
|
||||
def make_grid(p_graphics, w, h, s, margin=None):
|
||||
off = s / 2
|
||||
margin = off if margin is None else margin
|
||||
cols, rows = (w - margin * 2) // s, (h - margin * 2) // s
|
||||
points = dict()
|
||||
for i in range(cols):
|
||||
x = off + i * s + margin
|
||||
for j in range(rows):
|
||||
y = off + j * s + margin
|
||||
bc = p_graphics.get(x, y)
|
||||
points[(i, j)] = (x, y, bc)
|
||||
|
||||
return points
|
12
README.md
12
README.md
|
@ -14,9 +14,19 @@ You may also support my artistic work, open teaching resources and research usin
|
|||
|
||||
## [2019](2019.md)
|
||||
|
||||
## 2020
|
||||
|
||||
---
|
||||
|
||||
## 2020
|
||||

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

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