kopia lustrzana https://github.com/villares/sketch-a-day
fix 92 gif & 93
rodzic
4d83dc0049
commit
cc13266181
|
|
@ -83,5 +83,8 @@ class Aresta():
|
|||
self.p2.vy = self.p2.vy - dir.y
|
||||
|
||||
def rnd_choice(collection):
|
||||
i = int(random(len(collection)))
|
||||
return collection[i]
|
||||
if collection:
|
||||
i = int(random(len(collection)))
|
||||
return collection[i]
|
||||
else:
|
||||
return None
|
||||
|
|
|
|||
BIN
s092/s092.gif
BIN
s092/s092.gif
Plik binarny nie jest wyświetlany.
|
Przed Szerokość: | Wysokość: | Rozmiar: 1.4 MiB Po Szerokość: | Wysokość: | Rozmiar: 1.6 MiB |
|
|
@ -48,17 +48,17 @@ def draw():
|
|||
if NUM_PONTOS * NUM_CONNECT > len(Aresta.ARESTAS):
|
||||
rnd_choice(list(Ponto.SET)).cria_arestas()
|
||||
elif NUM_PONTOS * NUM_CONNECT < len(Aresta.ARESTAS):
|
||||
Ponto.SET.remove(rnd_choice(list(Ponto.SET)))
|
||||
Aresta.ARESTAS.remove(rnd_choice(list(Aresta.ARESTAS)))
|
||||
|
||||
if Inputs.TILT:
|
||||
Ponto.SET = set()
|
||||
|
||||
# uncomment next lines to export GIF
|
||||
if not frameCount % 30:
|
||||
gif_export(GifMaker,
|
||||
frames=2000,
|
||||
delay=500,
|
||||
filename=SKETCH_NAME)
|
||||
# if not frameCount % 30:
|
||||
# gif_export(GifMaker,
|
||||
# frames=2000,
|
||||
# delay=500,
|
||||
# filename=SKETCH_NAME)
|
||||
|
||||
# Updates reading or draws sliders and checks mouse dragging / keystrokes
|
||||
Inputs.update_inputs()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ TAM_PONTO = 50 # TAM_PONTO dos Pontos
|
|||
class Ponto():
|
||||
VEL_MAX = 5
|
||||
SET = set()
|
||||
SET_COM_ARESTAS = set()
|
||||
|
||||
" Pontos num grafo, VEL_MAX inicial sorteada, criam Arestas com outros Pontos "
|
||||
|
||||
|
|
@ -14,7 +15,6 @@ class Ponto():
|
|||
self.z = 0 # para compatibilidade com PVector...
|
||||
self.vx = random(-VEL_MAX, VEL_MAX)
|
||||
self.vy = random(-VEL_MAX, VEL_MAX)
|
||||
self.sel = False # se está selecionado, começa sem seleção
|
||||
self.cor = color(random(128, 255), # R
|
||||
random(128, 255), # G
|
||||
random(128, 255), # B
|
||||
|
|
@ -22,11 +22,8 @@ class Ponto():
|
|||
self.cria_arestas()
|
||||
|
||||
def desenha(self):
|
||||
if self.sel:
|
||||
stroke(0)
|
||||
else:
|
||||
noStroke()
|
||||
fill(self.cor)
|
||||
noStroke()
|
||||
fill(100, 100)
|
||||
ellipse(self.x, self.y, TAM_PONTO, TAM_PONTO)
|
||||
|
||||
def move(self, VEL_MAX):
|
||||
|
|
@ -65,11 +62,12 @@ class Aresta():
|
|||
self.p2 = p2
|
||||
|
||||
def desenha(self):
|
||||
stroke(0)
|
||||
stroke(lerpColor(self.p1.cor, self.p2.cor, 0.5))
|
||||
line(self.p1.x, self.p1.y, self.p2.x, self.p2.y)
|
||||
noStroke()
|
||||
fill(0)
|
||||
fill(self.p1.cor)
|
||||
ellipse(self.p1.x, self.p1.y, TAM_PONTO / 6, TAM_PONTO / 6)
|
||||
fill(self.p2.cor)
|
||||
ellipse(self.p2.x, self.p2.y, TAM_PONTO / 6, TAM_PONTO / 6)
|
||||
|
||||
def puxa_empurra(self, TAM_BARRA):
|
||||
|
|
@ -83,5 +81,8 @@ class Aresta():
|
|||
self.p2.vy = self.p2.vy - dir.y
|
||||
|
||||
def rnd_choice(collection):
|
||||
i = int(random(len(collection)))
|
||||
return collection[i]
|
||||
if collection:
|
||||
i = int(random(len(collection)))
|
||||
return collection[i]
|
||||
else:
|
||||
return None
|
||||
|
|
|
|||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 682 KiB |
|
|
@ -1,5 +1,5 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
SKETCH_NAME = "s091" # 180401
|
||||
SKETCH_NAME = "s093" # 180403
|
||||
|
||||
add_library('serial') # import processing.serial.*;
|
||||
add_library('arduino') # import cc.arduino.*;
|
||||
|
|
@ -20,7 +20,7 @@ def setup():
|
|||
size(400, 400)
|
||||
|
||||
def draw():
|
||||
background(128)
|
||||
background(0)
|
||||
|
||||
TAM_BARRA = A.val / 4
|
||||
NUM_PONTOS = int(B.val / 4)
|
||||
|
|
@ -33,22 +33,28 @@ def draw():
|
|||
ponto.move(VEL_MAX) # atualiza posição
|
||||
# para cada aresta
|
||||
# checa se há Arestas com Pontos já removidos
|
||||
COM_ARESTAS = set()
|
||||
for aresta in Aresta.ARESTAS:
|
||||
if (aresta.p1 not in Ponto.SET) or (aresta.p2 not in Ponto.SET):
|
||||
Aresta.ARESTAS.remove(aresta) # nesse caso remove a Aresta também
|
||||
else: # senão
|
||||
aresta.desenha() # desenha a linha
|
||||
aresta.puxa_empurra(TAM_BARRA) # altera a velocidade dos pontos
|
||||
COM_ARESTAS.add(aresta.p1)
|
||||
COM_ARESTAS.add(aresta.p2)
|
||||
Ponto.SET = COM_ARESTAS # remove pontos sem nenhuma aresta
|
||||
# atualiza número de pontos
|
||||
if NUM_PONTOS > len(Ponto.SET):
|
||||
Ponto.SET.add(Ponto(random(width), random(height)))
|
||||
elif NUM_PONTOS < len(Ponto.SET):
|
||||
Ponto.SET.remove(rnd_choice(list(Ponto.SET)))
|
||||
rnd_ponto = rnd_choice(list(Ponto.SET))
|
||||
Ponto.SET.remove(rnd_ponto)
|
||||
|
||||
# atualiza número de arestas
|
||||
if NUM_PONTOS * NUM_CONNECT > len(Aresta.ARESTAS):
|
||||
rnd_choice(list(Ponto.SET)).cria_arestas()
|
||||
elif NUM_PONTOS * NUM_CONNECT < len(Aresta.ARESTAS):
|
||||
Ponto.SET.remove(rnd_choice(list(Ponto.SET)))
|
||||
Aresta.ARESTAS.remove(rnd_choice(list(Aresta.ARESTAS)))
|
||||
|
||||
if Inputs.TILT:
|
||||
Ponto.SET = set()
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue