Simple Python Turtle Graphic and Code Brig Gen Insignia

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

A General's star created with the "math" library to be able to use trigonometric functions and pi.

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 url at https://www.amazon.com/author/basicpy...

import turtle
import math #Requirement to use trigonometric functions and pi
t = turtle.Turtle() #Definitions and Initializations
screen = turtle.Screen()
t.pensize(4)
star_size = 260 #Changeable; Distance from center to upper tip of star
t.penup() #Python_Graphic start of drawing procedure
t.left(90) #Turtle rotation to point toward upper tip of star
t.forward(star_size) #Trail-less movement of turtle over a distance of star_size
t.right(162) #Turtle rotation toward upper-right boundary of star's "head"
t.pendown() #Preparation to draw star outline
t.fillcolor("silver") #Setting of fill color for star
t.begin_fill()
for i in range(5): #Loop to draw the five "v" boundaries of star: NorthEast, SE, S, SW, and NW
t.forward(star_size * math.sin(math.pi * 36 / 180) / math.sin(math.pi * 126 / 180)) #The left arm of "v"
t.left(72)
t.forward(star_size * math.sin(math.pi * 36 / 180) / math.sin(math.pi * 126 / 180)) #The right arm of "v"
t.right(144)
t.end_fill()
t.pensize(2) #Change of pensize for the inner ridges of star
t.setheading(90) #Initial turtle direction before drawing the inner ridges
for i in range(5): #Loop to draw 5 pairs of inner ridges; a pair containing a long and a short ridge
t.penup()
t.goto(0, 0)
t.pendown()
t.forward(star_size) #Turtle movement to draw a long ridge
t.right(36)
t.penup()
t.goto(0, 0)
t.pendown()
t.forward(star_size * math.sin(math.pi * 18 / 180) / math.sin(math.pi * 126 / 180)) #Turtle movement to draw a short ridge;
t.right(36) #sine((18/180) of pi) and sine((126/180) of pi) from law of sines on an 18-36-126 triangle,
t.hideturtle() #the longest side of which has length star_size, and the two shorter sides have lengths
screen.exitonclick() #of "v" arms