diff --git a/s338/2702.png b/s338/2702.png deleted file mode 100644 index 55693552..00000000 Binary files a/s338/2702.png and /dev/null differ diff --git a/s338/2832.png b/s338/2832.png deleted file mode 100644 index 7b6c6cff..00000000 Binary files a/s338/2832.png and /dev/null differ diff --git a/s338/337a.png b/s338/337a.png deleted file mode 100644 index f24f0f72..00000000 Binary files a/s338/337a.png and /dev/null differ diff --git a/s338/337b.png b/s338/337b.png deleted file mode 100644 index ba39ec9c..00000000 Binary files a/s338/337b.png and /dev/null differ diff --git a/s338/cell.py b/s338/cell.py index 6e64d810..8144c4fa 100644 --- a/s338/cell.py +++ b/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(): diff --git a/s338/s338.pyde b/s338/s338.pyde index a974ed96..8e2f7dce 100644 --- a/s338/s338.pyde +++ b/s338/s338.pyde @@ -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():