kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
7151caa5a0
commit
4696e6ef8b
|
|
@ -0,0 +1,27 @@
|
|||
# Author: Berin
|
||||
# Sketches repo: https://github.com/berinhard/sketches
|
||||
# berin lib: https://github.com/berinhard/berin/
|
||||
class Particula(object):
|
||||
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.raio = random(50, 60)
|
||||
self.angulo = random(TWO_PI)
|
||||
self.angulo_inc = random(TWO_PI / 36)
|
||||
self.raio_inc = random(1, 6)
|
||||
|
||||
def atualize(self):
|
||||
self.color = color(250, random(50, 100), 50)
|
||||
self.raio -= self.raio_inc
|
||||
self.angulo += self.angulo_inc
|
||||
self.x += random(-5, 2)
|
||||
self.y += random(-2, 5)
|
||||
|
||||
def desenha(self):
|
||||
if self.raio > 0:
|
||||
with pushMatrix():
|
||||
translate(self.x, self.y)
|
||||
rotate(self.angulo)
|
||||
fill(self.color)
|
||||
ellipse(0, 0, self.raio, self.raio)
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 122 KiB |
|
|
@ -0,0 +1,53 @@
|
|||
from random import choice, shuffle
|
||||
from particula import Particula
|
||||
|
||||
NODE_SIZE = 5
|
||||
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
global grid, f
|
||||
f = createFont("Free Sans Bold", 100)
|
||||
strokeWeight(1)
|
||||
|
||||
imagem = draw_text('PCD', 250, 225, text_size=225)
|
||||
grid = make_grid(imagem, width, height, 25, margin=10)
|
||||
background(100, 100, 200)
|
||||
|
||||
def draw():
|
||||
for particula in grid.values():
|
||||
particula.atualize()
|
||||
particula.desenha()
|
||||
|
||||
|
||||
def keyPressed():
|
||||
if key == 's':
|
||||
saveFrame("s####.png")
|
||||
|
||||
|
||||
def draw_text(txt, x, y, text_size=120):
|
||||
img = createGraphics(width, height)
|
||||
img.beginDraw()
|
||||
img.textFont(f)
|
||||
img.textAlign(CENTER, CENTER)
|
||||
img.textSize(text_size)
|
||||
# img.textFont(f)
|
||||
img.text(txt, x, y)
|
||||
img.endDraw()
|
||||
return img
|
||||
|
||||
|
||||
def make_grid(p_graphics, w, h, s, margin=None):
|
||||
off = s / 2
|
||||
margin = off if margin is None else margin
|
||||
cols, rows = (w - margin * 2) // s, (h - margin * 2) // s
|
||||
points = dict()
|
||||
for i in range(cols):
|
||||
x = off + i * s + margin
|
||||
for j in range(rows):
|
||||
y = off + j * s + margin
|
||||
bc = p_graphics.get(x, y)
|
||||
if bc != 0:
|
||||
points[(i, j)] = Particula(x, y)
|
||||
|
||||
return points
|
||||
Ładowanie…
Reference in New Issue