Last active
March 24, 2020 22:26
-
-
Save villares/1dcabd2587066474a977547812679fd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# exemplo_lista = [10, 20, 3, 13, 1] | |
# exemplo_tupla = (10, 22, "sim", color(0)) | |
# [(100, 100, 5, cor), (200, 100, 10, cor), ...] | |
from itertools import combinations | |
def setup(): | |
global dados_bolas, combos | |
size(500, 500) | |
fill(200, 200, 0) # amarelo | |
dados_bolas = cria_grade(5, 5, 100, 100) # cria uma lista de tuplas | |
combos = list(combinations(dados_bolas, 2)) | |
print(len(combos)) | |
def draw(): | |
background(0) | |
translate(50, 50) | |
for x, y, tam, cor in dados_bolas: | |
fill(cor) | |
noStroke() | |
ellipse(x, y, tam, tam) | |
ini = int(random(300)) - 11 | |
for a, b in combos[ini:ini+10]: | |
x1, y1, _, _ = a | |
x2, y2, _, _ = b | |
stroke(255) | |
strokeWeight(5) | |
line(x1, y1, x2, y2) | |
def cria_grade(colunas, filas, espaco_x=1, espaco_y=1): | |
pontos = [] | |
for i in range(colunas): | |
x = i * espaco_x | |
for j in range(filas): | |
y = j * espaco_y | |
tam = random(10, 50) | |
colorMode(HSB) | |
# cor = color(random(256), 200, 255) | |
h = (128 + map(tam, 10, 50, 0, 255)) % 256 | |
cor = color(h, 200, 255) | |
pontos.append((x, y, tam, cor)) | |
return pontos | |
def keyPressed(): | |
global dados_bolas | |
if key == ' ': | |
dados_bolas = cria_grade(5, 5, 100, 100) | |
Author
villares
commented
Mar 24, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment