kopia lustrzana https://github.com/villares/sketch-a-day
13 & 14
rodzic
c9266bc72a
commit
1889023d7f
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 268 KiB |
|
|
@ -0,0 +1,21 @@
|
|||
from collections import deque
|
||||
from random import randint
|
||||
|
||||
d = deque([0], maxlen=10)
|
||||
new_n = 0
|
||||
|
||||
def setup():
|
||||
size(400, 400)
|
||||
frameRate(20)
|
||||
|
||||
def draw():
|
||||
global new_n
|
||||
background(0)
|
||||
for i, n in enumerate(d):
|
||||
x = i * 40
|
||||
rect(x, n * 20, 40, 20)
|
||||
|
||||
while new_n in d:
|
||||
new_n = randint(0, 19)
|
||||
d.append(new_n)
|
||||
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 2.1 MiB |
|
|
@ -0,0 +1,91 @@
|
|||
from __future__ import division
|
||||
|
||||
# add_library('gifAnimation')
|
||||
# from villares.gif_export import gif_export
|
||||
|
||||
def setup():
|
||||
global grid
|
||||
size(1024, 512)
|
||||
rectMode(CENTER)
|
||||
colorMode(HSB)
|
||||
# noSmooth()
|
||||
grid = Cell(0, 0, width, height, 8, 4, deep=True)
|
||||
|
||||
def draw():
|
||||
global f
|
||||
f = frameCount / 40.0
|
||||
background(240)
|
||||
translate(width / 2, height / 2)
|
||||
grid.plot()
|
||||
|
||||
# if f <= TWO_PI:
|
||||
# if frameCount % 2:
|
||||
# gif_export(GifMaker, "output")
|
||||
# else:
|
||||
# gif_export(GifMaker)
|
||||
# gif_export(GifMaker)
|
||||
# gif_export(GifMaker)
|
||||
# gif_export(GifMaker, finish=True)
|
||||
|
||||
class Cell():
|
||||
|
||||
def __init__(self, x, y, cw, ch, cols=0, rows=0, deep=False):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.cw = cw
|
||||
self.ch = ch
|
||||
self.parent = self # for root Cell
|
||||
self.children = Cell.rec_grid(x, y, cw, ch, cols, rows, deep) if cols else None
|
||||
if self.children:
|
||||
for c in self.children:
|
||||
c.parent = self
|
||||
|
||||
def plot(self):
|
||||
if not self.children:
|
||||
noFill()
|
||||
t = 0.5 + cos(PI - f + self.x / 320.0) / 2.0
|
||||
self.lerp_cell(t)
|
||||
else:
|
||||
for c in self.children:
|
||||
c.plot()
|
||||
|
||||
def lerp_cell(self, t):
|
||||
xa, ya = self.x, self.y
|
||||
xb, yb = self.parent.x, self.parent.y
|
||||
cwa, cha = self.cw, self.ch
|
||||
cwb, chb = self.parent.cw, self.parent.ch
|
||||
rb, ra = self.parent.cw / 4, 0
|
||||
# t = map(mouseX, 0, width, 0, 2)
|
||||
xc, yc, cwc, chc, rc = [lerp(a, b, t) for a, b in ((xa, xb),
|
||||
(ya, yb),
|
||||
(cwa, cwb),
|
||||
(cha, chb),
|
||||
(ra, rb))]
|
||||
# stroke(8 + 2 * (cwc + 2) - rc, 255, 255)
|
||||
stroke(0)
|
||||
strokeWeight(0.5 + rc)
|
||||
rect(xc, yc, cwc, cwc, rc)
|
||||
|
||||
@classmethod
|
||||
def rec_grid(cls, x, y, tw, th, cols, rows, deep=False):
|
||||
cw = tw / cols
|
||||
ch = th / rows
|
||||
xoffset = (cw - tw) / 2.0
|
||||
yoffset = (ch - th) / 2.0
|
||||
cells = []
|
||||
for i in range(cols):
|
||||
nx = x + cw * i + xoffset
|
||||
for j in range(rows):
|
||||
ny = y + ch * j + yoffset
|
||||
if (cw > 8 and random(10) < 5) or deep:
|
||||
cs = Cell(nx, ny, cw, ch, 2, 2)
|
||||
cells.append(cs)
|
||||
else:
|
||||
cells.append(Cell(nx, ny,
|
||||
cw - 2, ch - 2,
|
||||
0))
|
||||
return cells
|
||||
|
||||
def keyPressed():
|
||||
from villares.helpers import sketch_name
|
||||
saveFrame(sketch_name() + ".png")
|
||||
12
README.md
12
README.md
|
|
@ -26,6 +26,18 @@ Here are listed some of the tools I have been using:
|
|||
|
||||
---
|
||||
|
||||

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

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

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