Simple Python Turtle Graphic and Code E Spirograph 10

Pubblicato il: 22 gennaio 2025
sul canale di: Basic Python Turtle Art
84
1

A geometric image drawn without lifting the pen as in spirographs.

Feel free to copy the basic Python Turtle code that is given below. Don't hesitate to ask questions about the code if you have any. Enjoy! Please comment, like, or subscribe :)

Incidentally, for manually colorable graphics and variations, please visit my author site at https://www.amazon.com/author/basicpy...

import turtle
t = turtle.Turtle() #Definitions and Initializations
screen = turtle.Screen()
t.speed(9)
t.pensize(4)
radius = 250 #Changeable to a number close to 250; Size of graphic
number_of_points = 25 #Changeable; Count of ordered pairs on circumference of invisible circle
list_of_points = [] #Initialization of set named list_of_points
def set_of_points(r): #Procedure for adding orderd pairs to the set named list_of_points
for i in range(number_of_points): #Loop to list ordered pairs number_of_points times
list_of_points.append(t.position()) #Addition of ordered pair in new_point to the set list_of_points
t.circle(r, 360 / number_of_points) #Search for new point by the circumference-traveling turtle
def basic_pattern(x): #Procedure for drawing the 3 arcs in the basic pattern
t.left(45)
t.color("dark green") #Changeable color
t.circle(-1.1 * x, 60) #First arc of basic_pattern
t.circle(-x / 10, 165) #Second arc of basic_pattern
t.circle(0.8 * x, 60) #Third arc of basic_pattern
t.color("maroon") #Changeable color
t.penup() #Python_Graphic start of drawing procedure
t.goto(0, -radius) #Trail-less movement of turtle to the point with given coordinates
set_of_points(radius) #Function call to add orderd pairs to the set named list_of_points
t.color("maroon") #Changeable color, preferably the same as the one on the last line of
t.pendown() #basic_pattern
for i in range(number_of_points): #Loop to draw the basic pattern of spirograph number_of_points times
t.setheading(t.towards(0,0)) #Direction initialization for turtle before drawing a basic pattern
basic_pattern(radius) #Function call to draw a basic pattern
if i == number_of_points - 1: #Conditional execution if i value is the last one in the range
t.setheading(t.towards(list_of_points[0]))
t.forward(t.distance(list_of_points[0])) #Transitional line to next basic_pattern
else: #Conditional execution if i value is not the last one in the range
t.setheading(t.towards(list_of_points[number_of_points - 1 - i]))
t.forward(t.distance \
(list_of_points[number_of_points - 1 - i])) #A line cut by "\" -- the line continuation character: Transitional line to
t.hideturtle() #next basic_pattern
screen.exitonclick()


In questa pagina del sito puoi guardare il video online Simple Python Turtle Graphic and Code E Spirograph 10 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Basic Python Turtle Art 22 gennaio 2025, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 84 volte e gli è piaciuto 1 spettatori. Buona visione!