I would like to make the following two diagrams, but I don't understand the code very well.I'm a beginner. Could you tell me?
At the beginning of Python's corresponding documentation, depending on how well you understand this part, you will be divided into those who think it's easy and those who think it's difficult.
Turtle graphics is a common way to introduce programming to children. This was part of the original Logo programming language developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon in 1967.
Imagine a robot turtle moving from (0,0) in the x-y plane.turtle.forward(15)
command moves in the direction it faces 15 pixels (on the screen!) and draws a line along the movement.turtle.left(25)
command turns 25 degrees counterclockwise on the spot.
Combining these instructions with other similar instructions makes it easy to draw complex shapes and pictures.
The circle itself is circle().
"Drawing two equilateral triangles" and "Creating six small circles" are considered independently, so you won't understand.
"I think ""draw two regular triangles with circles on each vertex"" and to draw them, ""draw three circles and three straight lines"" is probably the concept of the Turtle Graphics style."
Possible actions include:
Define the "draw an equilateral triangle with a circle at each vertex" function
Call the above functions once
Define the function Draw an equilateral triangle with a circle at each vertex
Call the above function once
Here's the sauce
import turtle
# Define the function "draw an equilateral triangle with a circle at each vertex"
def CircleAndTriangle(t,csize,lsize):
for_in range(3):
t.pencolor ('orange')
t.circle(csize)
t.pencolor ('purple')
t.right(60)
t.forward(lsize)
t.right(60)
t=turtle.Turtle()
t.pensize(3)
csize = 20# radius of circle
lsize = 200 # Triangle side length
CircleAndTriangle(t,csize,lsize)
t.penup()
t.forward (lsize/2)
t.right (90)
t.forward (lsize/10)
t.left(30)
t.pendown()
CircleAndTriangle(t,csize,lsize)
t.hideturtle()
US>turtle.done()
Spiral diagrams can be treated as follows:
By the way, it seems that there are 20 triangles drawn in the question diagram.
Define
Draw an equilateral triangle that changes the color of each side with a specified length
Set and store the following values
range
Define the function "draw an equilateral triangle that changes the color of each side with a specified length"
Set and store the following values
Here's the sauce
import turtle
# Define the function "draw an equilateral triangle that changes the color of each side with a specified length"
def Triangle(t, lsize):
for c in ['red', 'purple', 'orange']:
t.pencolor(c)
t.forward(lsize)
t.left (120)
t=turtle.Turtle()
t.pensize(3)
divcount=20#Number of triangles drawn
age=360/divcount#360 (angle) divided by the number of triangles drawn
csize = 10 # Distance of starting position to draw the next triangle
tsizeini=20# initial value of triangle side length
tsizediff = 10 # Incremental value to the side length of the next triangle
# Create a list of sides of the triangle to be drawn in a range and loop.
for lsize in range (tsizeini, (tsizeini+(tsizediff*divcount))), tsizeiff:
Triangle(t, lsize)
t.penup()
t.right(adegree)
t.forward(csize)
t.pendown()
t.hideturtle()
US>turtle.done()
Also, if you are not familiar with coding, you should try the tutorial around here.
asweigart/simple-turtle-tutorial-for-python/simple_turtle_tutorial.md
Easy Designs-Turtle Graphics Python
Python 3 – Turtle graphics
Turtle Programming in Python
Python Turtle Graphics Tutorial#1-IntroductionYouTube
Text-Based Tutorial & Code:Text above
Complete Python Turtle Graphics Overview! (From Beginner to Advanced) Another YouTube
© 2025 OneMinuteCode. All rights reserved.