Skip to content

Commit

Permalink
day 50
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Feb 19, 2018
1 parent 081b2a2 commit c80fa09
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 3 deletions.
100 changes: 100 additions & 0 deletions s045b/s045b.pyde
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""
sketch 45b 180214 - Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
"""

LIST = []
SRINK = .50
OFFSET = .25
SIZE = 512 # base size
SAVE_FRAME = False
DRAW_MODE = rect

def setup():
size(512 + 200, 512 + 200)
rectMode(CENTER)
colorMode(HSB)
strokeWeight(2)
LIST.append(Cell())

def draw():
translate(width / 2, height / 2)
background(200)
for cell in LIST:
cell.update()
save_frame() # saves frame if SAVE_FRAME is set True

def keyPressed():
global SAVE_FRAME, DRAW_MODE
if key == " ":
LIST[:] = [Cell()]
if key == "r":
if DRAW_MODE == rect:
DRAW_MODE = ellipse
else: DRAW_MODE = rect
SAVE_FRAME = True


class Cell():

def __init__(self, x=0, y=0, gen=0, gen_offset=0,
xo=0, yo=0, mother=None):
self.LIST = []
self.x, self.y, self.xo, self.yo = x, y, xo, yo
self.gen = gen
self.mother = mother
self.color = color(random(0, 200), 200, 200, 200)

def s(self): # size
return SIZE * (SRINK ** self.gen)

def update(self):
self.draw() # draws itself
if not self.LIST:
# if no sub-cells, its a lead (para células sem sub-células)
# and if mouse is pressed inside it
if mousePressed and self.on_mouse():
self.divide() # will create new sub-cells
# otherwise will recursively update sub-cells and draw a line to them
else:
for sub_cell in self.LIST:
sub_cell.update()
stroke(0)
line(self.x, self.y, sub_cell.x, sub_cell.y)

def draw(self):
draw_function = DRAW_MODE
x =self.x + self.xo * self.s() * OFFSET
y =self.y + self.yo * self.s() * OFFSET
noStroke()
fill(self.color)
draw_function(x, y, self.s(), self.s())
fill(0)
draw_function(x, y, 4, 4)
#text(str(self.gen), self.x, self.y)

def divide(self):
if self.gen < 6:
global SAVE_FRAME
SAVE_FRAME = True
new_gen = self.gen + 1
o = self.s() * OFFSET
go = 0 #new_gen * 2
self.LIST.append(Cell(gen=new_gen, xo=+1, yo=+1, mother=self))
self.LIST.append(Cell(gen=new_gen, xo=+1, yo=-1, mother=self))
self.LIST.append(Cell(gen=new_gen, xo=-1, yo=+1, mother=self))
self.LIST.append(Cell(gen=new_gen, xo=-1, yo=-1, mother=self))
#self.gen = 6

def on_mouse(self):
x, y = self.x + width / 2, self.y + height / 2
r = self.s() / 2
if (x - r < mouseX < x + r and
y - r < mouseY < y + r):
return True

def save_frame():
global SAVE_FRAME
if SAVE_FRAME:
SAVE_FRAME = False
# saveFrame("45-######.tga")
6 changes: 3 additions & 3 deletions s049/s049.pyde
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Cell():
# SAVE_FRAME = True
if mousePressed and self.on_mouse():
self.divide() # will create new sub-cells
SAVE_FRAME = True
#SAVE_FRAME = True
# otherwise will recursively update sub-cells and draw a line to them
else:
for sub_cell in self.LIST:
Expand All @@ -72,7 +72,7 @@ class Cell():
noStroke()
fill(self.color)
s = self.gen % len(NODE_DRAW)
NODE_DRAW[s)](self.x, self.y, self.s(), self.s())
NODE_DRAW[s](self.x, self.y, self.s(), self.s())
fill(0)
NODE_DRAW[s](self.x, self.y, 4, 4)
#text(str(self.gen), self.x, self.y)
Expand Down Expand Up @@ -101,4 +101,4 @@ def save_frame():
if SAVE_FRAME:
SAVE_FRAME = False
#if frameCount < 600: #and not frameCount % 3:
saveFrame("48-######.tga")
saveFrame("49-######.tga")
52 changes: 52 additions & 0 deletions s050/s050.pyde
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import random as rnd

LISTA = []
MARGIN = 25

def setup():
size(500, 500)
background(200)
noFill()
smooth(12)

def draw():
for x, y, s, w, arrow, sub_list in LISTA:
strokeWeight(w)
for n in sub_list:
if arrow:
stroke(0)
seta(x, y, n[0], n[1], s, w*5)
else:
stroke(255)
line(x, y, n[0], n[1])
ellipse(x, y, s, s)


def keyPressed():
background(200)
LISTA[:] = []
for _ in range(20):
LISTA.append((
random(MARGIN, width - MARGIN), # x
random(MARGIN, height - MARGIN), # y
rnd.choice([10, 20, 30]), # size
rnd.choice([2, 3, 5]), # strokeW
rnd.choice([True, False]), # arrow
list() # other nodes
))
for node in LISTA:
random_node = rnd.choice(LISTA)
if random_node != node:
node[-1].append(random_node)


def seta(x1, y1, x2, y2, encurta=12, head=12):
d = dist(x1, y1, x2, y2)
with pushMatrix():
translate(x2, y2)
angle = atan2(x1 - x2, y2 - y1)
rotate(angle)
offset = -encurta * .6
line(0, offset, 0, -d - offset)
line(0, offset, -head / 3, -head + offset)
line(0, offset, head / 3, -head + offset)
2 changes: 2 additions & 0 deletions s050/sketch.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mode=Python
mode.id=jycessing.mode.PythonMode

0 comments on commit c80fa09

Please sign in to comment.