Simple Python Turtle Graphic and Code - E-Spirograph 8

Опубликовано: 30 Декабрь 2024
на канале: Basic Python Turtle Art
70
2

A spirograph generated electronically using a set of points on an invisible circle.

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) #Changeable speed
t.pensize(4) #Changeable pensize
radius = 255 #Changeable to a number close to 255; Distance from center to edge of graphic
number_of_points = 25 #Changeable; Count of ordered pairs on circumference of invisible circle
list_of_points = [] #Initialization of set that will contain points on invisible circumference
def set_of_points(radius): #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
new_point = t.position() #Temporary assignment of current ordered pair to new_point
list_of_points.append(new_point) #Addition of ordered pair in new_point to the set list_of_points
t.circle(radius, 360 / number_of_points) #Search for new point by the circumference-traveling turtle
def basic_pattern(): #Procedure for drawing a basic pattern in the e-spirograph
t.setheading(t.towards(0,0)) #Direction initialization for turtle before drawing a basic pattern
t.circle(-1.3 * radius, 60) #Drawing of a 60-degree arc
t.left(160) #Turtle rotation before drawing the second arc
t.circle(-1.3 * radius, 68) #Drawing of a 68-degree arc
t.penup() #Python_Graphic start of drawing procedure
t.goto(0, -radius) #Trail-less movement of turtle to starting point of graphic drawing
set_of_points(radius) #Function call to add orderd pairs to the set named list_of_points
t.color("blue") #Changeable pen color
t.pendown() #Start of drawing
for i in range(number_of_points): #Loop to draw the basic pattern in e-spirograph number_of_points times
basic_pattern() #Function call to draw a basic pattern in the e-spirograph
if i == number_of_points - 1: #Conditional execution if the transitory line to be drawn is for last pattern
t.setheading(t.towards(list_of_points[0])) #Turtle rotation to head towards first point in the set list_of_points
d = t.distance(list_of_points[0]) #Calculation of distance from current turtle poaition to list_of_points[0]
t.forward(d) #Turtle movement to draw the transitory line
else: #Conditional execution if transitory line to be drawn isn't for last pattern
t.setheading(t.towards(list_of_points[i + 1])) #Turtle rotation to head towards next point in the set list_of_points
d = t.distance(list_of_points[i + 1]) #Calculation of distance from current turtle position to list_of_points[i + 1]
t.forward(d) #Turtle movement to draw the transitory line
t.hideturtle()
screen.exitonclick()


На этой странице сайта вы можете посмотреть видео онлайн Simple Python Turtle Graphic and Code - E-Spirograph 8 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Basic Python Turtle Art 30 Декабрь 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 70 раз и оно понравилось 2 зрителям. Приятного просмотра!