String art > Angolo

String art con i chiodini disposti ad angolo

  • 50 chiodini da A a B
  • 50 chiodini da B a C
  • un filo collega le coppie di chiodini alla stessa posizione

import math
from   numpy import linspace
from   time  import sleep
import turtle
#-----------------------------------------------------------------------------
DIM       = 800
RAGGIO    = 0.45*DIM   # Distanza
N_CHIODI  = 50         # Numero chiodini
TITOLO    ='String art'

COLORE0 = "pink"    # Sfondo
COLORE1 = "purple"  # Chiodini
COLORE2 = "red"     # Spago
#-----------------------------------------------------------------------------
def string_art(p1, p2, p3):
    X_12 = linspace(p1[0], p2[0], num=N_CHIODI, endpoint=True)
    Y_12 = linspace(p1[1], p2[1], num=N_CHIODI, endpoint=True)
    X_23 = linspace(p2[0], p3[0], num=N_CHIODI, endpoint=True)
    Y_23 = linspace(p2[1], p3[1], num=N_CHIODI, endpoint=True)
    
    turtle.tracer(0)
    for i in range(N_CHIODI):
        turtle.penup()
        turtle.setposition(X_12[i], Y_12[i]); turtle.dot(COLORE1)
        turtle.setposition(X_23[i], Y_23[i]); turtle.dot(COLORE1)
        turtle.setposition(X_12[i], Y_12[i])
        turtle.pendown();
        turtle.setposition(X_23[i], Y_23[i])
    turtle.update()
#-----------------------------------------------------------------------------
turtle.setup(DIM, DIM)
turtle.bgcolor(COLORE0)
turtle.hideturtle()
turtle.pencolor(COLORE2)
turtle.title(TITOLO)
#-----------------------------------------------------------------------------
A = (-RAGGIO, +RAGGIO)
B = (-RAGGIO, -RAGGIO)
C = (+RAGGIO, -RAGGIO)
string_art(A, B, C)

A = (+RAGGIO, +RAGGIO)
B = (+RAGGIO, -RAGGIO)
C = (-RAGGIO, -RAGGIO)
D = (-RAGGIO, +RAGGIO)
string_art(A, B, C);sleep(1)
string_art(B, C, D)

A = (+RAGGIO, +RAGGIO)
B = (+RAGGIO, -RAGGIO)
C = (-RAGGIO, -RAGGIO)
D = (-RAGGIO, +RAGGIO)
string_art(A, B, C);sleep(1)
string_art(B, C, D);sleep(1)
string_art(C, D, A);sleep(1)
string_art(D, A, B)

A = (+RAGGIO, +RAGGIO)
B = (+RAGGIO, -RAGGIO)
C = (-RAGGIO, -RAGGIO)
D = (-RAGGIO, +RAGGIO)
string_art(A, B, D);sleep(1)
string_art(B, C, A);sleep(1)
string_art(C, D, B);sleep(1)
string_art(D, A, C)

Lascia un commento