kopia lustrzana https://github.com/villares/sketch-a-day
0130, 0131, 0201
rodzic
45e9197198
commit
25fa2231de
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 4.7 MiB |
|
|
@ -0,0 +1,64 @@
|
|||
|
||||
NBS = ((-1, -1), (0, -1), (1, -1),
|
||||
(-1, 0), (1, 0),
|
||||
(-1, 1), (0, 1), (1, 1))
|
||||
ONBS = ((0, -1), (-1, 0), (1, 0), (0, 1))
|
||||
DNBS = ((-1, -1), (-1, 1), (1, -1), (1, 1))
|
||||
|
||||
SIZE = 10
|
||||
sf = 1
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
noStroke()
|
||||
Cell(0, 0)
|
||||
noLoop()
|
||||
|
||||
def draw():
|
||||
background(100, 100, 200)
|
||||
translate(width / 2, height / 2)
|
||||
scale(sf)
|
||||
for c in Cell.grid.values():
|
||||
c.grow()
|
||||
for c in Cell.grid.values():
|
||||
c.display()
|
||||
|
||||
|
||||
def keyPressed():
|
||||
global sf
|
||||
sf *= .99
|
||||
# for c in Cell.grid.values():
|
||||
# c.grow()
|
||||
# c.display()
|
||||
print Cell.grid.keys()
|
||||
redraw()
|
||||
|
||||
|
||||
class Cell:
|
||||
grid = {}
|
||||
|
||||
def __init__(self, i, j):
|
||||
self.pos = (i, j)
|
||||
self.grid[self.pos] = self
|
||||
|
||||
def display(self):
|
||||
i, j = self.pos
|
||||
fill(0, 100, 0, 100)
|
||||
circle(i * SIZE, j * SIZE, SIZE * 1.5 )
|
||||
|
||||
|
||||
def grow(self):
|
||||
i, j = self.pos
|
||||
for noi, noj in NBS:
|
||||
ni, nj = i + noi, j + noj
|
||||
# fill(255, 100)
|
||||
# circle(ni * SIZE, nj * SIZE, SIZE * .5 )
|
||||
if not any(self.grid.get((ni + oi, nj + oj))
|
||||
for oi, oj in DNBS
|
||||
if (ni + oi, nj + oj) != self.pos):
|
||||
if random(100) < 50 and ((ni, nj) not in self.grid):
|
||||
Cell(ni, nj)
|
||||
|
||||
|
||||
|
||||
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 2.0 MiB |
|
|
@ -0,0 +1,40 @@
|
|||
SIZE, scale_factor = 10, 1
|
||||
NBS = ((-1, -1), (0, -1), (1, -1), #
|
||||
(-1, 0), (1, 0),
|
||||
(-1, 1), (0, 1), (1, 1))
|
||||
grid = {(0, 0)} # a set of tuples
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
noStroke()
|
||||
noLoop() # redraw on keyPressed()
|
||||
|
||||
def draw():
|
||||
background(100, 100, 200)
|
||||
translate(width / 2, height / 2)
|
||||
scale(scale_factor)
|
||||
for c in grid:
|
||||
grow(c)
|
||||
for i, j in grid:
|
||||
fill(100, 50, 0)
|
||||
circle(i * SIZE, j * SIZE, SIZE * 1.5 )
|
||||
|
||||
def grow(c):
|
||||
i, j = c
|
||||
for noi, noj in NBS:
|
||||
ni, nj = i + noi, j + noj
|
||||
if not any(((ni + oi, nj + oj) in grid)
|
||||
for oi, oj in NBS
|
||||
if (ni + oi, nj + oj) != c):
|
||||
if random(100) < 10:
|
||||
grid.add((ni, nj))
|
||||
|
||||
def keyPressed():
|
||||
global scale_factor
|
||||
scale_factor *= .997
|
||||
print grid
|
||||
redraw()
|
||||
|
||||
|
||||
ONBS = ((0, -1), (-1, 0), (1, 0), (0, 1))
|
||||
DNBS = ((-1, -1), (-1, 1), (1, -1), (1, 1))
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 518 KiB |
|
|
@ -0,0 +1,40 @@
|
|||
SIZE, scale_factor = 10, 1
|
||||
NBS = ((-1, -1), (0, -1), (1, -1), #
|
||||
(-1, 0), (1, 0),
|
||||
(-1, 1), (0, 1), (1, 1))
|
||||
grid = {(0, 0):(0, 0)} # a dict, the value is the parent node
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
strokeWeight(5)
|
||||
noLoop() # redraw on keyPressed()
|
||||
|
||||
def draw():
|
||||
background(100, 200, 100)
|
||||
translate(width / 2, height / 2)
|
||||
scale(scale_factor)
|
||||
for c in grid:
|
||||
grow(c)
|
||||
for (xa, ya), (xb, yb) in grid.items():
|
||||
stroke(100, 50, 0)
|
||||
line(xa * SIZE, ya * SIZE, xb * SIZE, yb * SIZE)
|
||||
|
||||
def grow(c):
|
||||
i, j = c
|
||||
for noi, noj in NBS:
|
||||
ni, nj = i + noi, j + noj
|
||||
if not any(((ni + oi, nj + oj) in grid)
|
||||
for oi, oj in NBS
|
||||
if (ni + oi, nj + oj) != c):
|
||||
if random(100) < 10:
|
||||
grid[(ni, nj)] = (i, j)
|
||||
|
||||
def keyPressed():
|
||||
global scale_factor
|
||||
scale_factor *= .997
|
||||
print grid
|
||||
redraw()
|
||||
|
||||
|
||||
ONBS = ((0, -1), (-1, 0), (1, 0), (0, 1))
|
||||
DNBS = ((-1, -1), (-1, 1), (1, -1), (1, 1))
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 1.7 MiB |
|
|
@ -0,0 +1,75 @@
|
|||
from villares.line_geometry import draw_poly, rotate_point
|
||||
from random import choice
|
||||
|
||||
cores = (color(200, 0, 0), color(255), color(0) )
|
||||
f = 0
|
||||
|
||||
def setup():
|
||||
size(600, 600)
|
||||
colorMode(HSB)
|
||||
strokeWeight(5)
|
||||
noFill()
|
||||
global lista_baloes, lista_proximos
|
||||
lista_baloes = cria_baloes()
|
||||
lista_proximos = cria_baloes()
|
||||
|
||||
|
||||
def cria_baloes(n=4):
|
||||
lista_baloes = []
|
||||
for _ in range(n):
|
||||
cor = choice(cores)
|
||||
x = choice(range(175, width - 175, 25))
|
||||
y = choice(range(175, width - 175, 25))
|
||||
w = choice((-300, -200, 150, 200, 300))
|
||||
h = choice((200, 150, 100, 75))
|
||||
a = choice((0, 0, 0, HALF_PI, -HALF_PI))
|
||||
lista_baloes.append((cor, x, y, w, h, a))
|
||||
return lista_baloes
|
||||
|
||||
def draw():
|
||||
global f
|
||||
background(128)
|
||||
t = 1 - abs(sin(radians(f)))
|
||||
for i, (a, b) in enumerate(zip(lista_baloes, lista_proximos)) :
|
||||
# lista_baloes[i] = lerp_balao(a, b, float(mouseX) / width)
|
||||
cor, x, y, w, h, ang = lerp_balao(a, b, t)
|
||||
# cor, x, y, w, h, ang = lerp_balao(a, b, map(mouseX, 0, width, 0, 1))
|
||||
stroke(cor)
|
||||
draw_poly(balao(x, y, w, h, angle=ang))
|
||||
|
||||
global lista_baloes, lista_proximos
|
||||
if f % 180 == 0:
|
||||
lista_baloes = cria_baloes()
|
||||
f += 0.5
|
||||
|
||||
|
||||
def lerp_balao(a, b, t):
|
||||
cor = [lerpColor(a[0], b[0], t)]
|
||||
other = [lerp(aa, bb, t) for aa, bb in zip(a[1:], b[1:])]
|
||||
return tuple(cor + other)
|
||||
|
||||
def balao(ox, oy, w, h, ponta=None, mode=CENTER, angle=None):
|
||||
wbase = w / 4
|
||||
offset = w / 4
|
||||
if mode == CENTER:
|
||||
x, y = ox - w / 2.0, oy - h / 2.0
|
||||
else:
|
||||
x, y = ox, oy
|
||||
px, py = ponta or x + w, y + h * 1.5
|
||||
|
||||
points = [(x, y), (x + w, y),
|
||||
(x + w, y + h),
|
||||
(offset + x + w / 2 + wbase / 2, y + h),
|
||||
(px, py), # (x + w / 2, y + h),
|
||||
(offset + x + w / 2 - wbase / 2, y + h),
|
||||
(x, y + h)]
|
||||
if angle is None:
|
||||
return points
|
||||
else:
|
||||
return [rotate_point((x, y), angle, (ox, oy))
|
||||
for x, y in points]
|
||||
|
||||
def keyPressed():
|
||||
if key == ' ':
|
||||
global lista_baloes, lista_proximos
|
||||
lista_baloes = cria_baloes()
|
||||
18
README.md
18
README.md
|
|
@ -26,6 +26,24 @@ Here are listed some of the tools I have been using:
|
|||
|
||||
---
|
||||
|
||||

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

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

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

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