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