Closed villares closed 3 years ago
arrastando = None
pontos = [(100, 100),
(200, 100),
(200, 200),
(100, 200),
(50, 200),
(50, 100),
(50, 200),
]
tam = 10
def setup():
size(300, 300)
noFill()
strokeWeight(3)
def draw():
background(100)
for i, ponto in enumerate(pontos):
x, y = ponto
if i == arrastando:
stroke(200, 0, 0)
else:
stroke(255)
ellipse(x, y, tam, tam)
stroke(0)
# p1 = pontos[0]
# x1, y1 = p1
# curve(x1, y1, ...
beginShape()
vertex(pontos[0][0], pontos[0][1])
bezierVertex(pontos[1][0], pontos[1][1],
pontos[2][0], pontos[2][1],
pontos[3][0], pontos[3][1])
bezierVertex(pontos[4][0], pontos[4][1],
pontos[5][0], pontos[5][1],
pontos[6][0], pontos[6][1])
endShape()
def mousePressed(): # quando um botão do mouse é apertado
global arrastando
for i, ponto in enumerate(pontos):
x, y = ponto
dist_mouse_ponto = dist(mouseX, mouseY, x, y)
if dist_mouse_ponto < tam:
arrastando = i
break # encerra o laço
def mouseReleased(): # quando um botão do mouse é solto
global arrastando
arrastando = None
def mouseDragged(): # quando o mouse é movido apertado
if arrastando is not None:
x, y = pontos[arrastando]
x += mouseX - pmouseX
y += mouseY - pmouseY
pontos[arrastando] = (x, y)
Mais uma tentativa...
arrastando = None
pontos = [
(100, 50),
(150, 100),
(250, 100),
(250, 200),
(150, 200),
(50, 200),
(50, 100),
]
def setup():
size(300, 300)
noFill()
def draw():
background(100)
strokeWeight(3)
stroke(0)
beginShape()
curveVertex(pontos[0][0], pontos[0][1])
for x, y in pontos:
curveVertex(x, y)
curveVertex(pontos[-1][0], pontos[-1][1])
endShape(),
strokeWeight(1)
for i, ponto in enumerate(pontos):
x, y = ponto
if i == arrastando:
stroke(200, 0, 0)
else:
stroke(255)
ellipse(x, y, 10, 10)
text(i, x + 5, y - 5)
Falta por bezier()
e tal, mas eu já vou fechar esta issue! :grin:
https://github.com/villares/material-aulas/blob/master/Processing-Python/curvas.md
E relacionados