kopia lustrzana https://github.com/villares/sketch-a-day
cleanup
rodzic
5d2d80b07c
commit
a581234092
|
|
@ -1,33 +1,30 @@
|
|||
from __future__ import division
|
||||
|
||||
pontos0 = []
|
||||
pontos1 = []
|
||||
arrastando = [-1, -1]
|
||||
offset_curva0 = 10
|
||||
offset_curva1 = 10
|
||||
pontos = [[], []] # duas listas para armazenar tuplas (x, y)
|
||||
arrastando = [-1, -1] # -1 significa nenhom ponto arrastado
|
||||
offset_curva = [35, 5]
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
background(240, 250, 250)
|
||||
pontos1[:] = pontos0[:] = sorteia_pontos0()
|
||||
pontos[1][:] = pontos[0][:] = sorteia_pontos(5)
|
||||
|
||||
def sorteia_pontos0():
|
||||
pontos0 = []
|
||||
for _ in range(5):
|
||||
x, y = random(width * .2, width * .8), random(height * .2, height * .8)
|
||||
pontos0.append((x, y))
|
||||
return pontos0
|
||||
def sorteia_pontos(num):
|
||||
pontos = []
|
||||
for _ in range(num):
|
||||
x = random(width * .2, width * .8)
|
||||
y = random(height * .2, height * .8)
|
||||
pontos.append((x, y))
|
||||
return pontos
|
||||
|
||||
def draw():
|
||||
oc = offset_curva0
|
||||
|
||||
oc = offset_curva[0]
|
||||
background(240, 250, 250)
|
||||
last = 10
|
||||
for i in range(last):
|
||||
pts = lerp_pts(pontos0, pontos1, i / last)
|
||||
oc = lerp(offset_curva0, offset_curva1, i / last)
|
||||
draw_pontos(pts, oc, i in (0, last))
|
||||
|
||||
pts = lerp_pts(pontos[0], pontos[1], i / last)
|
||||
oc = lerp(offset_curva[0], offset_curva[1], i / last)
|
||||
draw_pontos(pts, oc, i in (0, last - 1))
|
||||
|
||||
def draw_pontos(pontos, offset, handle=False):
|
||||
for i, (x0, y0) in enumerate(pontos):
|
||||
|
|
@ -55,29 +52,25 @@ def curva(x1, y1, x2, y2, offset=0, d=False):
|
|||
curva(x1, y1, xm, ym, offset)
|
||||
curva(xm, ym, x2, y2, offset)
|
||||
|
||||
def lerp_pt(p1, p2, a):
|
||||
if a == 0:
|
||||
return p1
|
||||
if a == 1:
|
||||
return p2
|
||||
return (lerp(p1[0], p2[0], a), lerp(p1[1], p2[1], a))
|
||||
|
||||
def lerp_pts(pts1, pts2, a):
|
||||
if a == 0:
|
||||
return pts1
|
||||
if a == 1:
|
||||
return pts2
|
||||
if len(pts1) == 2:
|
||||
return (lerp(pts1[0], pts2[0], a),
|
||||
lerp(pts1[1], pts2[1], a))
|
||||
pts = []
|
||||
for p1, p2 in zip(pts1, pts2):
|
||||
pts.append(lerp_pt(p1, p2, a))
|
||||
pts.append(lerp_pts(p1, p2, a))
|
||||
return pts
|
||||
|
||||
def mousePressed():
|
||||
for i, (x0, y0) in enumerate(pontos1):
|
||||
for i, (x0, y0) in enumerate(pontos[1]):
|
||||
if dist(mouseX, mouseY, x0, y0) < 10:
|
||||
arrastando[1] = i
|
||||
return
|
||||
for i, (x0, y0) in enumerate(pontos0):
|
||||
for i, (x0, y0) in enumerate(pontos[0]):
|
||||
if dist(mouseX, mouseY, x0, y0) < 10:
|
||||
arrastando[0] = i
|
||||
|
||||
|
|
@ -86,19 +79,18 @@ def mouseReleased():
|
|||
|
||||
def mouseDragged():
|
||||
if arrastando[0] >= 0:
|
||||
pontos0[arrastando[0]] = (mouseX, mouseY)
|
||||
pontos[0][arrastando[0]] = (mouseX, mouseY)
|
||||
if arrastando[1] >= 0:
|
||||
pontos1[arrastando[1]] = (mouseX, mouseY)
|
||||
pontos[1][arrastando[1]] = (mouseX, mouseY)
|
||||
|
||||
def mouseWheel(e):
|
||||
global offset_curva0, offset_curva1
|
||||
if keyCode == SHIFT and keyPressed:
|
||||
offset_curva1 += e.getCount() / 5.
|
||||
offset_curva[1] += e.getCount() / 5.
|
||||
else:
|
||||
offset_curva0 += e.getCount() / 5.
|
||||
offset_curva[0] += e.getCount() / 5.
|
||||
|
||||
def keyPressed():
|
||||
if key == ' ':
|
||||
pontos0[:] = pontos1[:] = sorteia_pontos0()
|
||||
pontos[0][:] = pontos[1][:] = sorteia_pontos(5)
|
||||
if key == 's':
|
||||
saveFrame("####.png")
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue