kopia lustrzana https://github.com/villares/sketch-a-day
fix 60
rodzic
88f473fb81
commit
ae9179f57f
145
s060/s060.pyde
145
s060/s060.pyde
|
|
@ -1,15 +1,16 @@
|
||||||
"""
|
"""
|
||||||
sketch 60 180228 - Alexandre B A Villares
|
sketch 60 180301 - Alexandre B A Villares
|
||||||
https://abav.lugaralgum.com/sketch-a-day
|
https://abav.lugaralgum.com/sketch-a-day
|
||||||
"""
|
"""
|
||||||
|
from collections import namedtuple
|
||||||
import random as rnd
|
import random as rnd
|
||||||
import copy as cp
|
import copy as cp
|
||||||
|
|
||||||
from drawing_classes import D_node
|
# from drawing_classes import D_node
|
||||||
|
|
||||||
SPACING, MARGIN = 50, 75
|
SPACING, MARGIN = 50, 75
|
||||||
POSITIONS = [] # listas de posições para elementos
|
POSITIONS = [] # listas de posições para elementos
|
||||||
|
Point = namedtuple('Point', 'x y')
|
||||||
DRAWING = []
|
DRAWING = []
|
||||||
SAVE_FRAMES = False
|
SAVE_FRAMES = False
|
||||||
|
|
||||||
|
|
@ -23,15 +24,13 @@ def setup():
|
||||||
create_drawing(DRAWING)
|
create_drawing(DRAWING)
|
||||||
println("'s' to save, and 'n' for a new drawing")
|
println("'s' to save, and 'n' for a new drawing")
|
||||||
|
|
||||||
# def keyPressed():
|
def keyPressed():
|
||||||
# global SAVE_FRAMES
|
global SAVE_FRAMES
|
||||||
# if key == 's':
|
if key == 's':
|
||||||
# SAVE_FRAMES = not SAVE_FRAMES
|
SAVE_FRAMES = not SAVE_FRAMES
|
||||||
# print "Saving " + repr(SAVE_FRAMES)
|
print "Saving " + repr(SAVE_FRAMES)
|
||||||
# if key == 'r':
|
if key == 'n':
|
||||||
# randomize_points_to(CURRENT_DRW)
|
create_drawing(DRAWING)
|
||||||
# if key == 'n':
|
|
||||||
# create_drawing(CURRENT_DRW)
|
|
||||||
|
|
||||||
def create_drawing(drawing):
|
def create_drawing(drawing):
|
||||||
"""
|
"""
|
||||||
|
|
@ -40,36 +39,27 @@ def create_drawing(drawing):
|
||||||
"""
|
"""
|
||||||
drawing[:] = []
|
drawing[:] = []
|
||||||
for x, y in POSITIONS:
|
for x, y in POSITIONS:
|
||||||
drawing.append(D_node(x, y))
|
drawing.append(D_node(x, y, DRAWING))
|
||||||
randomize_points_to(drawing)
|
|
||||||
|
|
||||||
|
|
||||||
def randomize_points_to(drawing):
|
|
||||||
for node in drawing: # para cada elemento do drawing
|
for node in drawing: # para cada elemento do drawing
|
||||||
node.points_to[0][:] = []
|
node.randomize_target(0) # set of random targets
|
||||||
random_node = rnd.choice(drawing) # sorteia outro elemento
|
node.copy_target(0, -1) # backup of original targets
|
||||||
while dist(node.x, node.y, random_node.x, random_node.y) > 2.88 * SPACING:
|
node.randomize_target(1) # secondary set of random targets
|
||||||
random_node = rnd.choice(drawing)
|
|
||||||
if (node.x, node.y) != (random_node.x, random_node.y):
|
|
||||||
# 'aponta' para este elemento, acrescenta na sub_lista
|
|
||||||
node.points_to[0].append(random_node)
|
|
||||||
|
|
||||||
def draw():
|
def draw():
|
||||||
background(200)
|
background(200)
|
||||||
# fc = frameCount % 301 - 150
|
fc = frameCount % 301 - 150
|
||||||
# if fc < 0:
|
if fc < 0 : fase = 0
|
||||||
# DRAWING = CURRENT_DRW
|
elif 0 <= fc < 150:
|
||||||
# elif 0 <= fc < 150:
|
fase= map(fc, 0, 150, 0, 1)
|
||||||
# make_inter_nodes(map(fc, 0, 150, 0, 1), CURRENT_DRW, TARGET_DRW)
|
elif fc == 150: # and frameCount < 1050:
|
||||||
# DRAWING = INTER_DRW
|
fase = 0
|
||||||
# elif fc == 150 and frameCount < 1050:
|
for node in DRAWING:
|
||||||
# CURRENT_DRW, TARGET_DRW = TARGET_DRW, CURRENT_DRW
|
node.copy_target(1, 0)
|
||||||
# DRAWING = CURRENT_DRW
|
node.randomize_target(1)
|
||||||
# randomize_points_to(TARGET_DRW)
|
|
||||||
# else:
|
# else:
|
||||||
# if TARGET_DRW == INI_DRW:
|
# if TARGET_DRW == INI_DRW:
|
||||||
# println('end of last cicle')
|
# println('end of last cicle')
|
||||||
# noLoop() # stop draw at the end of this frame
|
# noLoop() # stop draw at the end of this frame
|
||||||
# else:
|
# else:
|
||||||
# println('start of last cicle')
|
# println('start of last cicle')
|
||||||
# CURRENT_DRW, TARGET_DRW = TARGET_DRW, INI_DRW
|
# CURRENT_DRW, TARGET_DRW = TARGET_DRW, INI_DRW
|
||||||
|
|
@ -77,26 +67,25 @@ def draw():
|
||||||
|
|
||||||
# draws white 'lines', non-arrows, INI_DRW.
|
# draws white 'lines', non-arrows, INI_DRW.
|
||||||
for node in (n for n in DRAWING if not n.is_arrow):
|
for node in (n for n in DRAWING if not n.is_arrow):
|
||||||
print node.x, node.y, node.s_weight
|
for other in node.points_now(fase): # se estiver apontando para alguém
|
||||||
for other in node.points_to[0]: # se estiver apontando para alguém
|
strokeWeight(node.s_weight)
|
||||||
#strokeWeight(node.s_weight)
|
stroke(node.s_color(fase))
|
||||||
stroke(255)
|
|
||||||
line(node.x, node.y, other.x, other.y)
|
line(node.x, node.y, other.x, other.y)
|
||||||
# desenha o círculo (repare que só em nós que 'apontam')
|
# desenha o círculo (repare que só em nós que 'apontam')
|
||||||
ellipse(node.x, node.y, node.t_size, node.t_size)
|
ellipse(node.x, node.y, node.t_size, node.t_size)
|
||||||
# then draws 'lonely nodes' in red (nodes that do not point anywhere)
|
# then draws 'lonely nodes' in red (nodes that do not point anywhere)
|
||||||
for node in (n for n in DRAWING if not n.points_to[0]):
|
for node in (n for n in DRAWING if not n.points_now(fase)):
|
||||||
strokeWeight(node.s_weight)
|
strokeWeight(node.s_weight)
|
||||||
stroke(255, 0, 0) # red stroke for lonely nodes
|
stroke(node.s_color(fase)) # red stroke for lonely nodes
|
||||||
if node.is_arrow:
|
if node.is_arrow:
|
||||||
rect(node.x, node.y, node.t_size, node.t_size)
|
rect(node.x, node.y, node.t_size, node.t_size)
|
||||||
else:
|
else:
|
||||||
ellipse(node.x, node.y, node.t_size, node.t_size)
|
ellipse(node.x, node.y, node.t_size, node.t_size)
|
||||||
# then draws black arrows
|
# then draws black arrows
|
||||||
for node in (n for n in DRAWING if n.is_arrow):
|
for node in (n for n in DRAWING if n.is_arrow):
|
||||||
for other in node.points_to: # se estiver apontando para alguém
|
for other in node.points_now(fase): # se estiver apontando para alguém
|
||||||
strokeWeight(node.s_weight)
|
strokeWeight(node.s_weight)
|
||||||
stroke(0)
|
stroke(node.s_color(fase))
|
||||||
seta(node.x, node.y, other.x, other.y,
|
seta(node.x, node.y, other.x, other.y,
|
||||||
node.t_size, node.s_weight * 5,
|
node.t_size, node.s_weight * 5,
|
||||||
rect, node.t_size)
|
rect, node.t_size)
|
||||||
|
|
@ -127,23 +116,57 @@ def seta(x1, y1, x2, y2, shorter=0, head=None,
|
||||||
if tail_func and tail_size:
|
if tail_func and tail_size:
|
||||||
tail_func(0, 0, tail_size, tail_size)
|
tail_func(0, 0, tail_size, tail_size)
|
||||||
|
|
||||||
def make_inter_nodes(amt, origin, target):
|
|
||||||
INTER_DRW[:] = []
|
class D_node(object):
|
||||||
for n1, n2 in zip(origin, target):
|
|
||||||
if n1.points_to:
|
"""
|
||||||
p1x, p1y = n1.points_to[0].x, n1.points_to[0].y
|
A class of drawing elements, that might be arrows and point to some other element
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, x, y, drawing):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.t_size = rnd.choice([5, 10, 15]) # t_size
|
||||||
|
self.s_weight = rnd.choice([1, 2, 3]) # s_weight
|
||||||
|
self.is_arrow = rnd.choice([True, False])
|
||||||
|
self.points_to = [[], [], []]
|
||||||
|
self.drawing = drawing
|
||||||
|
|
||||||
|
def randomize_target(self, index=0):
|
||||||
|
self.points_to[index][:] = []
|
||||||
|
rnd_node = rnd.choice(self.drawing) # sorteia outro elemento
|
||||||
|
while dist(self.x, self.y, rnd_node.x, rnd_node.y) > 2.88 * SPACING:
|
||||||
|
rnd_node = rnd.choice(self.drawing)
|
||||||
|
if (self.x, self.y) != (rnd_node.x, rnd_node.y):
|
||||||
|
# 'aponta' para este elemento, acrescenta na sub_lista
|
||||||
|
self.points_to[index].append(Point(rnd_node.x, rnd_node.y))
|
||||||
|
|
||||||
|
def copy_target(self, origin, destination):
|
||||||
|
self.points_to[destination] = cp.deepcopy(self.points_to[origin])
|
||||||
|
|
||||||
|
def never_empty(self, points):
|
||||||
|
if not points:
|
||||||
|
return [Point(self.x, self.y)]
|
||||||
else:
|
else:
|
||||||
p1x, p1y = n1.x, n1.y
|
return points
|
||||||
if n2.points_to:
|
|
||||||
p2x, p2y = n2.points_to[0].x, n2.points_to[0].y
|
def points_now(self, amt=0):
|
||||||
|
p0 = self.never_empty(self.points_to[0])[0]
|
||||||
|
p1 = self.never_empty(self.points_to[1])[0]
|
||||||
|
if amt == 0:
|
||||||
|
return self.points_to[0]
|
||||||
|
elif amt == 1:
|
||||||
|
return self.points_to[1]
|
||||||
else:
|
else:
|
||||||
p2x, p2y = n2.x, n2.y
|
return [Point(lerp(p0.x, p1.x, amt),
|
||||||
INTER_DRW.append(Node( # elemento/"nó" uma namedtuple com:
|
lerp(p0.y, p1.y, amt))]
|
||||||
n1.x, # x
|
def color_def(node, index):
|
||||||
n1.y, # y
|
if not node.points_to[index]: return color(255, 0, 0)
|
||||||
n1.t_size, # t_size (tail/circle size)
|
|
||||||
n1.s_weight, # s_weight (espessura da linha)
|
def s_color(self, fase):
|
||||||
n1.is_arrow, # is_arrow? (se é seta ou 'linha')
|
if fase == 0:
|
||||||
# cp.deepcopy(n1.points_to)
|
if not self.points_to[int(fase)]: return color(255, 0, 0)
|
||||||
[PVector(lerp(p1x, p2x, amt), lerp(p1y, p2y, amt))]
|
elif self.is_arrow:
|
||||||
))
|
return 0
|
||||||
|
else: return 255
|
||||||
|
else: return color(0, 0, 255)
|
||||||
Ładowanie…
Reference in New Issue