Skip to content

Instantly share code, notes, and snippets.

@villares
Last active October 8, 2020 17:51
Show Gist options
  • Save villares/7f8c75ef72f1d58d67a00f2151e54a51 to your computer and use it in GitHub Desktop.
Save villares/7f8c75ef72f1d58d67a00f2151e54a51 to your computer and use it in GitHub Desktop.
Processing Python mode
"""
Para rodar, installe o Processing modo Python:
https://abav.lugaralgum.com/como-instalar-o-processing-modo-python/
Teclas:
ESPAÇO: apaga tudo
c: Muda modo de cor ou cinza
x: Muda paleta de cor
SHIFT: apaga itens nas duas pontas do deque
"""
from collections import deque
s = 255
h = deque([], 512)
S = {'color': 1,
'shape': 4,
'offset': 0,
'start': 0,
}
hsb = lambda i: color((i + S['offset']) % (s - S['offset']), s, s, 200)
gray = lambda i: color(32 + i % 128, 200)
def setup():
size(1152, 648)
strokeWeight(3)
colorMode(HSB)
rectMode(CENTER)
frameRate(25)
noCursor()
def draw():
background(160, 250, 32)
stroke(45)
point(mouseX, mouseY)
for i, (x, y, sha) in enumerate(h):
noFill()
c = lerpColor(hsb(i), gray(i), S['color'])
stroke(c)
if sha == 0:
square(x, y, (i % s) / 5)
elif sha == 1:
circle(x, y, (i % s) / 5)
if keyPressed and keyCode == SHIFT:
for _ in range(4):
if h: h.popleft()
if h: h.pop()
if keyPressed and keyCode == CONTROL:
for _ in range(16):
if h: h.pop()
if h:
h.append(h.popleft())
# h.append(h.popleft())
def mouseDragged():
h.append((mouseX, mouseY, 0))
def mousePressed():
if mouseButton == RIGHT:
h.append((mouseX, mouseY, 1))
def keyPressed():
if key == 'c':
S['color'] = (1, 0)[S['color']]
if key == 'x':
S['offset'] = {0: 200, 200:0}[S['offset']]
print S['offset']
if key == ' ':
h.clear()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment