Simple Python Turtle Graphic and Code: Poster

Опубликовано: 14 Октябрь 2024
на канале: Basic Python Turtle Art
82
0

A wall message embellished with ruffles that border the four sides. The basic Python Turtle code here utilized the turtle.write() to display the text, and two elementary arcs to generate the ruffles.

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 more graphics and variations, please visit my author url at https://www.amazon.com/author/basicpy...


import turtle
t = turtle.Turtle() #Definitions and Initializations
screen = turtle.Screen()
t.pensize(4)
arc_radius = 36 #Radius corresponding to bigger arc in border design
def s(): #Procedure for drawing one of 4 borders
t.fillcolor("red") #Start of fill procedure
t.begin_fill()
for i in range(2): #Loop for 2 arcs in first half of outer border
t.circle(-arc_radius, 180) #Bigger arc drawn clockwise
t.circle(arc_radius / 2, 180) #Smaller arc
t.right(180) #Turtle rotation for second half of border, outer and inner
for i in range(2): #Loop for second half of border, outer first then inner
for i in range(2): #Loop for 2 arcs in second half of border, outer first then inner
t.circle(arc_radius / 2, 180) #Smaller arc
t.circle(-arc_radius, 180) #Bigger arc drawn clockwise
t.right(180) #Turtle rotation for second half of inner border first, then
#going backward for first half of inner border
for i in range(2): #Loop for 2 arcs in first half of inner border
t.circle(-arc_radius, 180)
t.circle(arc_radius / 2, 180)
t.end_fill() #Implementation of fill
#Python_Graphic start of drawing procedure; "\" for cutting long instruction
for point in [(-arc_radius * 6, arc_radius * 6), (arc_radius * 6, arc_radius * 6), \
(arc_radius * 6, -arc_radius * 6), (-arc_radius * 6, -arc_radius * 6)]:
t.penup() #Preparation to go to the listed points, one per loop iteration
t.goto(point) #Trail-less movement of turtle to starting point of current border
t.left(90) #Turtle rotation to start next border
t.pendown()
s() #Function call to draw a border
t.penup() #Preparation for writing text
t.goto(0, 50) #The three lines of text given in the next instructions
t.pendown()
t.write("python", False, "center", ["arial", 80, "bold"])
t.penup()
t.goto(0, -60)
t.pendown()
t.write("turtle", False, "center", ["arial", 80, "bold"])
t.penup()
t.goto(0, -170)
t.pendown()
t.write("rocks!!", False, "center", ["arial", 80, "italic"])
t.hideturtle()
screen.exitonclick()