Simple Python Turtle Graphic and Code: Pills

Pubblicato il: 02 gennaio 2023
sul canale di: Basic Python Turtle Art
47
0

A circular arrangement of pills standing on their sides. The convex surfaces of the pills are represented by two arcs generated clockwise; that is, with negative radii. This graphic illustrates how Python Turtle connects the initial and final turtle positions in the color-filling procedure.

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 Iniializations
screen = turtle.Screen()
t.pensize(4) #Changeable
pill_size = 190 #Defined as radius corresponding to convex surface of pill; Changeable
number_of_pills = 9 #Changeable, preferably from 7 to 11
pill_width = 38 #Defined here as length of straight edge of pill at side view
def pill(): #Procedure for drawing a pill
t.fillcolor("pink") #Start of Color-filling at current turtle position -- thr midpoint
t.begin_fill() #of pill's straight edge at side view; Color changeable
t.forward(pill_width / 2) #Drawing half the first edge of pill at side view
t.right(60) #Turtle rotation to start drawing one convex surface of pill
t.circle(-pill_size, 60) #Drawing of one convex surface of pill
t.right(60) #Turtle rotation to draw half of the pill's second edge
t.forward(pill_width / 2) #Drawing half the second edge of pill at side view
t.end_fill() #Implementation of color fill for half the pill's side view
t.forward(pill_width / 2) #Drawing the next half of the second edge of pill at side view
t.right(60) #Turtle rotation to start drawing the other convex surface of pill
t.circle(-pill_size, 60) #Drawing of the other convex surface of pill
t.right(60) #Turtle rotation to draw next half of pill's first edge at
t.forward(pill_width / 2) #side view, and drawing it
t.penup() #Python_Graphic start of drawing procedure
for i in range(number_of_pills): #Loop to draw the indicated number_of_pills
t.forward(60) #Trail-less movement pf turtle to starting point of drawing a pill
t.left(90) #Turtle rotation before drawing a pill
t.pendown() #Start of drawing a pill
pill() #Function call to start drawing a pill
t.penup() #End drawing a pill
t.home() #Trail-less movement of turtle to default position and direction
t.left((1 + i) * (360 / number_of_pills)) #Turtle rotation towards starting point of drawing the next pill
t.hideturtle()
screen.exitonclick()


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