SoFunction
Updated on 2024-11-10

python standard library turtle turtle drawing implementation of simple Olympic rings

Why is it that the drawing of the five Olympic rings is the easiest, in fact, its drawing process is to draw five circles of the same size through the brush can be. The difference is that the position of the circles is different.

Before I started, I specifically went to find turtle's official website address posted below, in fact, learning a technical point of the role of the official website is still very important. After all, you find a lot of information on the Internet are second-hand information.

As a result, you may not understand the original purpose for which the technical point was created, and in the end, a technical point becomes a blackmail. Therefore, it is encouraged that you should always look at the official website for instructions on learning a technical point, and second-hand information elsewhere is for understanding.

Official Documentation:/cnhuzi/python/1081864

The non-standard library used is still turtle, as its role in painting is still quite important.

import turtle as tle

Write a function to initialize some global parameters of the turtle brush.

def init():
    (20)
init()

This time we're using a single global parameter, just setting the width of the brush.

The following write a function to draw the circle, because the five circles are the same size, which creates a commonality, so you can use a function to write the circle drawing process can be.

def draw_cricle(circle_size=100,x=-250,y=-30,color='blue'):
    ()
    (x, y)
    ()
    (color)
    (100)

Call the circle drawing function to draw five different colors of the circle, and finally generated the shape of the Olympic rings.

draw_cricle(x=-250,y=-30,color='blue')
draw_cricle(x=0,y=-30,color='black')
draw_cricle(x=250,y=-30,color='red')
draw_cricle(x=-125,y=-105,color='yellow')
draw_cricle(x=125,y=-105,color='green')

Read the above operation process, the operation is still quite simple, used to make a turtle learning material is still very nice.

After the above process is completed, the drawing part is considered to be finished, and finally the logic is refined. Because the drawing window will be closed automatically after the drawing is finished, the drawing will be closed before you can see it clearly after the drawing is finished. So, setting the properties of the drawing window is OK.

Keeps the window open after the drawing is complete

screen = ()
()

Above is python use turtle turtle drawing to realize the details of the simple Olympic five rings, more information about python turtle turtle drawing please pay attention to my other related articles!