readme
10
README.md
|
@ -8,6 +8,12 @@ If you enjoy this, be a [patreon](https://patreon.com/arteprog) or make a donati
|
|||
|
||||
Feel free to [contact me](http://contato.lugaralgum.com) regarding licenses to use my work, teaching opportunities, consulting or other projects.
|
||||
|
||||
---
|
||||

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

|
||||
|
||||
|
@ -15,13 +21,13 @@ Feel free to [contact me](http://contato.lugaralgum.com) regarding licenses to u
|
|||
|
||||
|
||||
---
|
||||

|
||||

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

|
||||

|
||||
|
||||
340: [code](https://github.com/villares/sketch-a-day/tree/master/s340) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
|
|
Po Szerokość: | Wysokość: | Rozmiar: 36 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 70 KiB |
|
@ -0,0 +1,94 @@
|
|||
|
||||
class Cell():
|
||||
# neighbours list
|
||||
NL = ((-1, -1), (+0, -1), (+1, -1),
|
||||
(-1, +0), (+0, +0), (+1, +0),
|
||||
(-1, +1), (+0, +1), (+1, +1))
|
||||
ONL = ((+0, -1),
|
||||
(-1, +0), (+0, +0), (+1, +0),
|
||||
(+0, +1))
|
||||
DNL = ((-1, -1), (+1, -1),
|
||||
(+0, +0),
|
||||
(-1, +1), (+1, +1))
|
||||
|
||||
def __init__(self, index, cell_size, state=False):
|
||||
self.index = index
|
||||
self.state = state
|
||||
self.size_ = cell_size
|
||||
self.mouse_down = False
|
||||
i, j = index[0], index[1]
|
||||
self.pos = PVector(self.size_ / 2 + i * self.size_,
|
||||
self.size_ / 2 + j * self.size_)
|
||||
|
||||
def update(self):
|
||||
# mouse over & selection treatment
|
||||
hs = self.size_ / 2
|
||||
px, py = self.pos.x, self.pos.y
|
||||
self.mouse_on = (px - hs < mouseX < px + hs and
|
||||
py - hs < mouseY < py + hs)
|
||||
if self.mouse_on and mousePressed:
|
||||
self.mouse_down = True
|
||||
if self.mouse_down and not mousePressed:
|
||||
self.state = not self.state
|
||||
self.mouse_down = False
|
||||
if self.mouse_on:
|
||||
fill(128, 128)
|
||||
else:
|
||||
noFill()
|
||||
strokeWeight(1)
|
||||
stroke(200)
|
||||
rect(self.pos.x, self.pos.y, self.size_, self.size_)
|
||||
|
||||
def plot(self, mode):
|
||||
if self.state:
|
||||
strokeWeight(self.size_ / 5.)
|
||||
if mode == -1:
|
||||
fill(0)
|
||||
noStroke()
|
||||
rect(self.pos.x, self.pos.y, self.size_, self.size_)
|
||||
if mode == 0:
|
||||
stroke(0)
|
||||
self.draw_lines2(Cell.NL)
|
||||
elif mode == 1:
|
||||
stroke(0, 150, 0)
|
||||
self.draw_lines2(Cell.ONL)
|
||||
elif mode == 2:
|
||||
stroke(0, 0, 150)
|
||||
self.draw_lines2(Cell.DNL)
|
||||
elif mode == 3:
|
||||
stroke(0, 150, 0)
|
||||
self.draw_lines2(Cell.ONL)
|
||||
stroke(0, 0, 150)
|
||||
self.draw_lines(Cell.DNL)
|
||||
elif mode == 4:
|
||||
stroke(0, 150, 0)
|
||||
self.draw_lines(Cell.DNL)
|
||||
stroke(0, 0, 150)
|
||||
self.draw_lines2(Cell.ONL)
|
||||
|
||||
def draw_lines(self, nbs):
|
||||
third = self.size_ / 3
|
||||
i, j = self.index[0], self.index[1]
|
||||
for (ni, nj) in nbs:
|
||||
nb = Cell.grid.get((i + ni, j + nj), None)
|
||||
if nb and nb.state:
|
||||
line(self.pos.x + ni * third * 1.5,
|
||||
self.pos.y + nj * third * 1.5,
|
||||
self.pos.x, self.pos.y)
|
||||
|
||||
def draw_lines2(self, nbs):
|
||||
third = self.size_ / 3
|
||||
i, j = self.index[0], self.index[1]
|
||||
for (ni, nj) in nbs:
|
||||
nb = Cell.grid.get((i + ni, j + nj), None)
|
||||
if nb and nb.state:
|
||||
with pushMatrix():
|
||||
translate(self.pos.x, self.pos.y)
|
||||
if ni == 0 and nj != 0:
|
||||
line(-third, nj * third * 1.5, -third, 0)
|
||||
line(+third, nj * third * 1.5, +third, 0)
|
||||
elif nj == 0 and ni !=0 :
|
||||
line(ni * third * 1.5, -third, 0, -third)
|
||||
line(ni * third * 1.5, +third, 0, +third)
|
||||
else:
|
||||
ellipse(0, 0, third*2, third*2)
|
Po Szerokość: | Wysokość: | Rozmiar: 838 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 106 KiB |
|
@ -0,0 +1,97 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
SKETCH_NAME = "s343" # 20181207
|
||||
OUTPUT = ".png"
|
||||
mode = 0
|
||||
|
||||
from cell import Cell
|
||||
from random import choice
|
||||
from java.awt import Toolkit
|
||||
|
||||
CELL_SIZE = 12
|
||||
Cell.grid = dict()
|
||||
|
||||
xo, yo = 100, 100
|
||||
xio, yio = 0, 0
|
||||
s = 10
|
||||
|
||||
def setup():
|
||||
size(600, 600)
|
||||
global img, grid_size
|
||||
img = loadImage("unifont-11.0.02.png")
|
||||
grid_size = width / CELL_SIZE
|
||||
|
||||
def init_grid(f=None):
|
||||
w, h = width // CELL_SIZE, height // CELL_SIZE
|
||||
for i in range(w):
|
||||
for j in range(h):
|
||||
if f == None:
|
||||
state = lambda i, j: choice((True, False))
|
||||
else:
|
||||
state = p_ou_b(i, j)
|
||||
Cell.grid[(i, j)] = Cell((i, j), CELL_SIZE, state)
|
||||
|
||||
def p_ou_b(i, j):
|
||||
c = img.get(xo + i, yo + j)
|
||||
if c == color(0): return True
|
||||
else: return False
|
||||
|
||||
|
||||
def draw():
|
||||
background(220)
|
||||
strokeWeight(1)
|
||||
# KeyEvent.VK_CAPS_LOCK is 20
|
||||
capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(20)
|
||||
if capsLocked:
|
||||
rectMode(CORNER)
|
||||
image(img, xio, yio)
|
||||
noFill()
|
||||
rect(xio + xo, yio + yo, grid_size, grid_size)
|
||||
else:
|
||||
rectMode(CENTER)
|
||||
init_grid(1)
|
||||
for c in Cell.grid.values():
|
||||
c.update()
|
||||
for c in Cell.grid.values():
|
||||
c.plot(mode)
|
||||
|
||||
def keyPressed():
|
||||
global mode
|
||||
global xo, yo, xio, yio
|
||||
if key == CODED:
|
||||
|
||||
if keyCode == RIGHT and xo < img.width - 11:
|
||||
xo += 16
|
||||
if keyCode == LEFT and xo > 10:
|
||||
xo -= 16
|
||||
if keyCode == DOWN and yo < img.height - 11:
|
||||
yo += 16
|
||||
if keyCode == UP and yo > 10:
|
||||
yo -= 16
|
||||
else:
|
||||
if key == "s" or key == "S":
|
||||
saveFrame(SKETCH_NAME + "_###.png")
|
||||
if key in "01234567789":
|
||||
mode = int(key)
|
||||
if key == "-":
|
||||
mode = -1
|
||||
if key == " ":
|
||||
init_grid(lambda i, j: False)
|
||||
if key == "x":
|
||||
init_grid(lambda i, j: (i + j) % 2 == 0)
|
||||
if key == "r":
|
||||
init_grid()
|
||||
if xo > width - grid_size:
|
||||
xio = width - grid_size - xo
|
||||
if yo > height - grid_size:
|
||||
yio = height - grid_size - yo
|
||||
|
||||
|
||||
# print text to add to the project's README.md
|
||||
def settings():
|
||||
println(
|
||||
"""
|
||||

|
||||
|
||||
{1}: [code](https://github.com/villares/sketch-a-day/tree/master/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
""".format(SKETCH_NAME, SKETCH_NAME[1:], OUTPUT)
|
||||
)
|
Po Szerokość: | Wysokość: | Rozmiar: 13 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 14 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 22 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 22 KiB |