Simple Python Turtle Graphic and Code Line Segments 1 Made with Clipchamp

Описание к видео Simple Python Turtle Graphic and Code Line Segments 1 Made with Clipchamp

A graphic drawn by line segments connecting point pairs from four arms.

Feel free to copy the simple 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.pensize(4)
t.speed(4)
side_length = 255 #Changeable; Length of one of 4 arms
side_pts_number = 9 #Changeable; Count of points on one of 4 arms
distance_betw_pts = side_length * 2 ** 0.5 / (side_pts_number - 1) #Gap bewteen consecutive points on an arm
point_set1 = [] #Initialization of list to contain points on 1st arm in a pair of arms
point_set2 = [] #Initialization of list to contain points on 2nd arm in a pair of arms
def point_sets(x): #Procedure to identify and list points on the 1st and 2nd arms in the
for j in range(2): #current pair of arms, where x is identified below as distance_betw_pts
for i in range(side_pts_number):
if j == 0:
point_set1.append(t.pos())
if j == 1:
point_set2.append(t.pos())
if i == side_pts_number - 1: #Conditional execution if the point that is listed is the last in an arm
t.right(90)
else: #Alternative execution if the point that is listed is not the last in an arm
t.forward(x)
def connect_pts(a, b): #Procedure for connecting point pairs from (a) 1st and (b) 2nd arms
for i in range(side_pts_number - 1):
t.goto(a[i])
t.pendown()
t.goto(b[i + 1])
t.penup()
t.penup() #Python_Graphic start of drawing procedure
t.goto(-side_length, side_length) #Trail-less turtle movement to outer tip of northwest pointing arm
t.right(45)
t.pendown()
for i in range(4): #Loop to identify and list the connecting points in the 4 possible pairs of arms,
point_sets(distance_betw_pts) #namely, northwest (NW) - southwest (SW), SW - SE, SE - NE, and NE - NW
t.penup()
connect_pts(point_set1, point_set2)
point_set1.clear() #Stepwise emptying of point_set1 and point_set2 lists after connecting points in
point_set2.clear() #a pair of arms
t.right(90)
t.pendown()
t.hideturtle()
screen.exitonclick()

Комментарии

Информация по комментариям в разработке