Skip to content

Instantly share code, notes, and snippets.

@villares
Created January 24, 2023 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save villares/f2fddca034bce52c5cb0fccd7a505396 to your computer and use it in GitHub Desktop.
Save villares/f2fddca034bce52c5cb0fccd7a505396 to your computer and use it in GitHub Desktop.
Processing Community Day Brasil 2022 oficina Introdução à programação criativa com Python

Processing Community Day Brasil 2022

Introdução à programação criativa com Python

Alexandre B A Villares - https://abav.lugaralgum.com - @villares@ciberlandia.pt

Minhas ferramentas prediletas:

Meus materias didáticos abertos e outros recursos (https://github.com/villares ):

Para ler mais sobre Orientação a Objetos:

Participantes:

Sergio Venancio - Instagram @sergiovenancio.art

Deise Maria Bertholdi Costa - deise@ufpr.br

William Figueiredo dos Santos - @figueiredowilli4m

Adolfo Neto @adolfont (Twitter e Instagram)

André Oliveira - @andreoliveira.cebola (ig)

... e mais outros ...

primeiro exemplo, desenho com o mouse apertado

def setup():
    createCanvas(600, 600) # pode usar size(600, 600)
    background(255, 255, 200)  # fundo (Red, Greed, Blue)
    colorMode(HSB, 255)
    
def draw():
    noStroke() # py5 -> no_stroke()
    fill(random(256), 200, 200) # Matiz, Sat, Bri
    tamanho = random(10, 40)
    if mouseIsPressed:  # py5 -> is_mouse_pressed
        circle(mouseX, mouseY, tamanho)  # x, y, diâmetro

    # py5 -> mouse_x, mouse_y

bola quicante

x = 100
y = 100
vx = 5
vy = 3

def setup():
    createCanvas(600, 600) # pode usar size(600, 600)

def draw():
    global x, y, vx, vy
    #background(255, 255, 200)  # fundo (Red, Greed, Blue)
    fill(random(256), random(256), random(256))
    circle(x, y, random(10, 30)) # x, y, diâmetro
    x = x + vx  # aumente o valor da variável x
    y = y + vy
    if x > 600 or x < 0:
        vx = -vx
    if y > 600 or y < 0:
        vy = -vy

range, fábrica de números list (converte em lista)

faixa = list(range(10, 20, 2)) # inicio, parada, passo
print(faixa)

grade

def setup():
    createCanvas(600, 700) # pode usar size(600, 600)


def draw():
    randomSeed(2)
    background(200)  # cinza 200
    for j in range(20):
        for i in range(20):  # 0, 1, 2 ... 19
            x = 100 + i * 20
            y = 50 + j * 30
            circle(x, y, random(10, 30))

primeita bola com Orientação a Objetos

def setup():
    global primeira_bola
    createCanvas(600, 600) # pode usar size(600, 600)
    primeira_bola = Bola(100, 100)

def draw():
    background(255, 255, 200)  # fundo (Red, Greed, Blue)
    primeira_bola.atualizar()

class Bola:
    
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.vx = random(-3, 3)
        self.vy = random(-3, 3)
        
    def atualizar(self):
        self.desenhar()
        self.andar()
        self.quicar()        
        
    def desenhar(self):
        circle(self.x, self.y, 10) # x, y, diâmetro
        
    def andar(self):
        # self.x = self.x + self.vx
        self.x += self.vx   # aumenta o self.x
        self.y += self.vy
    
    def quicar(self):
        if self.x > width or self.x < 0:
           self.vx = -self.vx
        if self.y > height or self.y < 0:
            self.vy = -self.vy

100 partículas

bolas = []

def setup():
    createCanvas(600, 600) # pode usar size(600, 600)
    colorMode(HSB, 255)
    noStroke()
    for n in range(100):
        bola = Bola(width / 2, height / 2)
        bolas.append(bola)

def draw():
    background(0)
    for b in bolas:   # para cada bola "b" da lista bolas
        b.atualizar()

class Bola:
    
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.vx = random(-3, 3)
        self.vy = random(-3, 3)
        self.tamanho = random(10, 32)
        
    def atualizar(self):
        self.desenhar()
        self.andar()
        self.quicar()        
        
    def desenhar(self):
        fill(self.tamanho * 8, 200, 200)
        circle(self.x, self.y, self.tamanho) # x, y, diâmetro
        
    def andar(self):
        # self.x = self.x + self.vx
        self.x += self.vx   # aumenta o self.x
        self.y += self.vy
    
    def quicar(self):
        if self.x > width or self.x < 0:
           self.vx = -self.vx
        if self.y > height or self.y < 0:
            self.vy = -self.vy
        

`

final: fogos de artifício

https://tinyurl.com/bolas-pcdbr2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment