kopia lustrzana https://github.com/villares/sketch-a-day
update readme e comentários
rodzic
079cf735d5
commit
b4005a6b70
48
README.md
48
README.md
|
|
@ -8,6 +8,54 @@ If you enjoy this, make a small donation [here](https://www.paypal.com/cgi-bin/w
|
|||
|
||||
----
|
||||
|
||||

|
||||
|
||||
094: [code](https://github.com/villares/sketch-a-day/tree/master/s091) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
Connection 'rate' can be less than 1, prevents less than 2 nodes
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
093: [code](https://github.com/villares/sketch-a-day/tree/master/s091) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
Nodes without connection are now removed
|
||||
|
||||
```
|
||||
COM_ARESTAS = set() # para guardar pontos com aresta
|
||||
for aresta in Aresta.ARESTAS:
|
||||
if (aresta.p1 not in Ponto.SET) or (aresta.p2 not in Ponto.SET)\
|
||||
or (aresta.p1 is aresta.p2): # arestas degeneradas
|
||||
Aresta.ARESTAS.remove(aresta) # remove a aresta
|
||||
else: # senão, tudo OK!
|
||||
aresta.desenha() # desenha a linha
|
||||
aresta.puxa_empurra(TAM_ARESTA) # altera a velocidade dos pontos
|
||||
# Adiciona ao conjunto de pontos com aresta
|
||||
COM_ARESTAS.update([aresta.p1, aresta.p2])
|
||||
Ponto.SET = COM_ARESTAS # isto remove pontos sem nenhuma aresta
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
092: [code](https://github.com/villares/sketch-a-day/tree/master/s091) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
Dynamic change of connection rate
|
||||
|
||||
```
|
||||
if NUM_PONTOS * NUM_CONNECT > len(Aresta.ARESTAS):
|
||||
rnd_choice(list(Ponto.SET)).cria_arestas()
|
||||
elif NUM_PONTOS * NUM_CONNECT < len(Aresta.ARESTAS):
|
||||
Aresta.ARESTAS.remove(rnd_choice(list(Aresta.ARESTAS)))
|
||||
```
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
091: [code](https://github.com/villares/sketch-a-day/tree/master/s091) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
|
|
|||
|
|
@ -49,6 +49,12 @@ class Ponto():
|
|||
else:
|
||||
return v
|
||||
|
||||
@staticmethod
|
||||
def reset_SET(num):
|
||||
Ponto.SET = set()
|
||||
for _ in range(num):
|
||||
Ponto.SET.add(Ponto(random(width), random(height)))
|
||||
|
||||
class Aresta():
|
||||
|
||||
""" Arestas contém só dois Pontos e podem ou não estar selecionadas """
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ class Inputs:
|
|||
|
||||
if port == None:
|
||||
# start, end, default, + key, - key
|
||||
A = Slider(0, 1023, 10, 'q', 'a')
|
||||
B = Slider(0, 1023, 10, 'w', 's')
|
||||
C = Slider(0, 1023, 10, 'e', 'd')
|
||||
D = Slider(0, 1023, 10, 'r', 'f')
|
||||
A = Slider(0, 1023, 128, 'q', 'a')
|
||||
B = Slider(0, 1023, 128, 'w', 's')
|
||||
C = Slider(0, 1023, 128, 'e', 'd')
|
||||
D = Slider(0, 1023, 128, 'r', 'f')
|
||||
|
||||
A.position(40, height - 70)
|
||||
B.position(40, height - 30)
|
||||
|
|
|
|||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 1.3 MiB |
|
|
@ -17,8 +17,8 @@ def setup():
|
|||
port = Inputs.select_source(Arduino)
|
||||
# `None` will activate Sliders
|
||||
A, B, C, D = Inputs.setup_inputs(port)
|
||||
for _ in range(int(B.val / 4)):
|
||||
Ponto.SET.add(Ponto(random(width), random(height)))
|
||||
|
||||
Ponto.reset_SET(int(B.val / 4)) # cria um set vazio e popula
|
||||
|
||||
def draw():
|
||||
background(200)
|
||||
|
|
@ -32,18 +32,19 @@ def draw():
|
|||
for ponto in Ponto.SET:
|
||||
ponto.desenha() # desenha
|
||||
ponto.move(VEL_MAX) # atualiza posição
|
||||
# para cada aresta
|
||||
# checa se há Arestas com Pontos já removidos
|
||||
COM_ARESTAS = set()
|
||||
# para cada aresta checa se pode desenhar, se não teve pontos já removidos
|
||||
# ou pontos iguais
|
||||
COM_ARESTAS = set() # para guardar pontos com aresta
|
||||
for aresta in Aresta.ARESTAS:
|
||||
if (aresta.p1 not in Ponto.SET) or (aresta.p2 not in Ponto.SET)\
|
||||
or (aresta.p1 is aresta.p2):
|
||||
Aresta.ARESTAS.remove(aresta) # nesse caso remove a Aresta também
|
||||
or (aresta.p1 is aresta.p2): # arestas degeneradas
|
||||
Aresta.ARESTAS.remove(aresta) # remove a aresta
|
||||
else: # senão
|
||||
aresta.desenha() # desenha a linha
|
||||
aresta.puxa_empurra(TAM_BARRA) # altera a velocidade dos pontos
|
||||
# Adiciona ao conjunto de pontos com aresta
|
||||
COM_ARESTAS.update([aresta.p1, aresta.p2])
|
||||
Ponto.SET = COM_ARESTAS # remove pontos sem nenhuma aresta
|
||||
Ponto.SET = COM_ARESTAS # isto remove pontos sem nenhuma aresta
|
||||
# atualiza número de pontos
|
||||
if NUM_PONTOS > len(Ponto.SET):
|
||||
Ponto.SET.add(Ponto(random(width), random(height)))
|
||||
|
|
@ -59,14 +60,14 @@ def draw():
|
|||
Aresta.ARESTAS.remove(rnd_choice(list(Aresta.ARESTAS)))
|
||||
|
||||
if Inputs.TILT:
|
||||
Ponto.SET = set()
|
||||
Ponto.reset_SET(int(B.val / 4))
|
||||
|
||||
# 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()
|
||||
|
|
@ -78,4 +79,3 @@ def mouseDragged(): # quando o mouse é arrastado
|
|||
ponto.x, ponto.y = mouseX, mouseY
|
||||
ponto.vx = 0
|
||||
ponto.vy = 0
|
||||
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue