Disegna una sequenza di tratti con x che scivola verso destra e y verso il basso

from vpython import *
DIM = 640 # DIMENSIONE FINESTRA
MAX = 100 # MASSIMA ASCISSA / ORDINATA
NUM = 25 # NUMERO TRATTI
SPAZIO = 5
MAX2 = MAX+SPAZIO
graph(fast=False, width=DIM, height=DIM,
xmin=-SPAZIO, xmax=MAX2, ymin=-SPAZIO, ymax=MAX2)
DELTA = MAX/NUM # PASSO COORDINATE
X = 0
Y = MAX
for i in range(NUM+1):
rate(NUM)
g=gcurve(color=color.red)
g.plot(pos=(0,Y))
g.plot(pos=(X,0))
X += DELTA
Y -= DELTA
La stessa costruzione ma realizzata con una funzione che riceve come parametri i 3 punti ai vertici
from numpy import linspace
from vpython import *
DIM = 640
MAX = 100
NUM = 25
SPAZIO = 5
MAX2 = MAX+SPAZIO
graph(fast=False, width=DIM, height=DIM,
xmin=-SPAZIO, xmax=MAX2, ymin=-SPAZIO, ymax=MAX2)
def inviluppo(p1, p2, p3):
X12 = linspace(p1[0], p2[0], num=NUM, endpoint=True)
X23 = linspace(p2[0], p3[0], num=NUM, endpoint=True)
Y12 = linspace(p1[1], p2[1], num=NUM, endpoint=True)
Y23 = linspace(p2[1], p3[1], num=NUM, endpoint=True)
for x12,y12,x23,y23 in zip(X12, Y12, X23, Y23):
rate(NUM)
g=gcurve(color=color.red)
g.plot(pos=(x12, y12))
g.plot(pos=(x23, y23))
P1 = ( 0, 100)
P2 = ( 0, 0)
P3 = (100, 0)
inviluppo(P1, P2, P3)
Esperimenti
Scegliendo opportunamente la terna di punti si possono realizzare figure interessanti

inviluppo((-100, +100), (-100, 0), (+100, 0))
inviluppo((+100, -100), (+100, 0), (-100, 0))

inviluppo((-100, +100), (-100, 0), (+100, 0))
inviluppo((+100, 0), (-100, 0), (-100, -100))

inviluppo((-100, +100), (0, -100), (+100, 0))
inviluppo((+100, 0), (0, +100), (-100, -100))