kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
9221722339
commit
d79229fbb6
BIN
s338/2702.png
BIN
s338/2702.png
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 14 KiB |
BIN
s338/2832.png
BIN
s338/2832.png
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 20 KiB |
BIN
s338/337a.png
BIN
s338/337a.png
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 13 KiB |
BIN
s338/337b.png
BIN
s338/337b.png
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 19 KiB |
43
s338/cell.py
43
s338/cell.py
|
@ -4,14 +4,14 @@ class Cell():
|
|||
NL = ((-1, -1), (+0, -1), (+1, -1),
|
||||
(-1, +0), (+0, +0), (+1, +0),
|
||||
(-1, +1), (+0, +1), (+1, +1))
|
||||
ONL = ((+0, -1),
|
||||
ONL = ( (+0, -1),
|
||||
(-1, +0), (+0, +0), (+1, +0),
|
||||
(+0, +1))
|
||||
(+0, +1))
|
||||
DNL = ((-1, -1) , (+1, -1),
|
||||
(+0, +0),
|
||||
(-1, +1), (+1, +1))
|
||||
|
||||
def __init__(self, index, cell_size, state=False):
|
||||
# Cell.NL = ((-1, -1), (+0, -1), (+1, -1),
|
||||
# (-1, +0), (+0, +0), (+1, +0),
|
||||
# (-1, +1), (+0, +1), (+1, +1))
|
||||
self.index = index
|
||||
self.state = state
|
||||
self.size_ = cell_size
|
||||
|
@ -19,12 +19,9 @@ class Cell():
|
|||
i, j = index[0], index[1]
|
||||
self.pos = PVector(self.size_ / 2 + i * self.size_,
|
||||
self.size_ / 2 + j * self.size_)
|
||||
# self.ngbs = []
|
||||
# for ni, nj in Cell.NL:
|
||||
# self.ngbs.append(
|
||||
# Cell.grid.get((i-ni, j-nj), None))
|
||||
|
||||
def play(self):
|
||||
def play(self, mode):
|
||||
# mouse selection treatment
|
||||
hs = self.size_ / 2
|
||||
px, py = self.pos.x, self.pos.y
|
||||
self.mouse_on = (px - hs < mouseX < px + hs and
|
||||
|
@ -34,26 +31,34 @@ class Cell():
|
|||
if self.mouse_down and not mousePressed:
|
||||
self.state = not self.state
|
||||
self.mouse_down = False
|
||||
self.plot()
|
||||
# go draw yourself!
|
||||
self.plot(mode)
|
||||
|
||||
def plot(self):
|
||||
fill(255)
|
||||
strokeWeight(1)
|
||||
rect(self.pos.x, self.pos.y, self.size_, self.size_)
|
||||
def plot(self, mode):
|
||||
stroke(0)
|
||||
if self.state:
|
||||
third = self.size_ / 3
|
||||
if key == CODED:
|
||||
if mode == 0:
|
||||
nbs = Cell.NL
|
||||
else:
|
||||
elif mode == 1:
|
||||
nbs = Cell.ONL
|
||||
stroke(0, 150, 0)
|
||||
elif mode == 2:
|
||||
stroke(0, 0, 150)
|
||||
nbs = Cell.DNL
|
||||
|
||||
i, j = self.index[0], self.index[1]
|
||||
strokeWeight(third)
|
||||
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,
|
||||
self.pos.y + nj * third,
|
||||
line(self.pos.x + ni * third * 1.5,
|
||||
self.pos.y + nj * third * 1.5,
|
||||
self.pos.x, self.pos.y)
|
||||
strokeWeight(1)
|
||||
noFill()
|
||||
stroke(100)
|
||||
rect(self.pos.x, self.pos.y, self.size_, self.size_)
|
||||
|
||||
if self.mouse_on:
|
||||
with pushStyle():
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
SKETCH_NAME = "s338" # 20181202
|
||||
OUTPUT = ".png"
|
||||
mode = 0
|
||||
|
||||
from cell import Cell
|
||||
from random import choice
|
||||
|
@ -18,13 +19,21 @@ def init_grid(w, h):
|
|||
for j in range(h):
|
||||
Cell.grid[(i, j)] = Cell((i,j), CELL_SIZE, choice((True, False)))
|
||||
|
||||
def draw():
|
||||
def draw():
|
||||
background(220)
|
||||
for c in Cell.grid.values():
|
||||
c.play()
|
||||
c.play(mode)
|
||||
|
||||
def keyPressed():
|
||||
global mode
|
||||
if key == "s":
|
||||
saveFrame("###.png")
|
||||
if key == "2":
|
||||
mode = 2
|
||||
if key == "1":
|
||||
mode = 1
|
||||
if key == "0":
|
||||
mode = 0
|
||||
|
||||
# print text to add to the project's README.md
|
||||
def settings():
|
||||
|
|
Ładowanie…
Reference in New Issue