-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
128 additions
and
15 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions
60
Processing-Python-py5/estudos-para-exemplos/particulas2.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from py5_tools import animated_gif | ||
|
||
|
||
def setup(): | ||
""" Instancia três particulas """ | ||
global pa, pb, pc | ||
size(100, 100) # área de desenho (width, height) | ||
pa = Particula(50, 50, 40) | ||
pb = Particula(80, 10, 30) | ||
pc = Particula(10, 40, 20) | ||
animated_gif('particulas2.gif', count=100, period=0.10, duration=0.10) | ||
|
||
|
||
def draw(): | ||
""" Limpa a tela, desenha e atualiza particulas """ | ||
background(0) # atualização do desenho, fundo preto | ||
pa.desenhar() | ||
pa.atualizar() | ||
pb.desenhar() | ||
pb.atualizar() | ||
pc.desenhar() | ||
pc.atualizar() | ||
|
||
|
||
class Particula(): | ||
""" Classe Particula, cor sorteada, velocidade sorteada """ | ||
|
||
def __init__(self, x, y, tamanho=None): | ||
self.x = float(x) | ||
self.y = float(y) | ||
if tamanho: | ||
self.tamanho = tamanho | ||
else: | ||
self.tamanho = random(50, 200) | ||
self.vx = random(-1, 1) | ||
self.vy = random(-1, 1) | ||
self.cor = color(random(256), # R | ||
random(256), # G | ||
random(256), # B | ||
200) # alpha | ||
|
||
def desenhar(self): | ||
""" Desenha círculo """ | ||
no_stroke() | ||
fill(self.cor) | ||
circle(self.x, self.y, self.tamanho) | ||
|
||
def atualizar(self): | ||
""" atualiza a posição do objeto e devolve do lado oposto se sair """ | ||
self.x += self.vx | ||
self.y += self.vy | ||
metade = self.tamanho / 2 | ||
if self.x > width + metade: | ||
self.x = -metade | ||
if self.y > height + metade: | ||
self.y = -metade | ||
if self.x < -metade: | ||
self.x = width + metade | ||
if self.y < -metade: | ||
self.y = height + metade |
57 changes: 57 additions & 0 deletions
57
Processing-Python-py5/estudos-para-exemplos/particulas3.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from py5_tools import animated_gif | ||
|
||
particulas = [] # lista de objetos | ||
|
||
def setup(): | ||
""" Define área de desenho e popula lista de particulas """ | ||
size(400, 400) # área de desenho (width, height) | ||
meia_largura, meia_altura = width / 2, height / 2 | ||
for _ in range(50): | ||
nova_particula = Particula(meia_largura, meia_altura) | ||
particulas.append(nova_particula) | ||
animated_gif('particulas3.gif', count=100, period=0.10, duration=0.10) | ||
|
||
|
||
|
||
def draw(): | ||
""" Limpa a tela, desenha e atualiza particulas """ | ||
background(0) # atualização do desenho, fundo preto | ||
for particula in particulas: | ||
particula.desenhar() | ||
particula.atualizar() | ||
class Particula(): | ||
""" Classe Particula, cor sorteada, velocidade sorteada """ | ||
|
||
def __init__(self, x, y, tamanho=None): | ||
self.x = float(x) | ||
self.y = float(y) | ||
if tamanho: | ||
self.tamanho = tamanho | ||
else: | ||
self.tamanho = random(50, 200) | ||
self.vx = random(-1, 1) | ||
self.vy = random(-1, 1) | ||
self.cor = color(random(256), # R | ||
random(256), # G | ||
random(256), # B | ||
200) # alpha | ||
|
||
def desenhar(self): | ||
""" Desenha círculo """ | ||
no_stroke() | ||
fill(self.cor) | ||
circle(self.x, self.y, self.tamanho) | ||
|
||
def atualizar(self): | ||
""" atualiza a posição do objeto e devolve do lado oposto se sair """ | ||
self.x += self.vx | ||
self.y += self.vy | ||
metade = self.tamanho / 2 | ||
if self.x > width + metade: | ||
self.x = -metade | ||
if self.y > height + metade: | ||
self.y = -metade | ||
if self.x < -metade: | ||
self.x = width + metade | ||
if self.y < -metade: | ||
self.y = height + metade |
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