python中最简单的turtle绘图:奥运五环

为什么奥林匹克五环的画是最简单的?实际上,它的绘制过程是用画笔画出五个大小相同的圆。不同的是,圆圈的位置不同。

[En]

Why is it that the drawing of the Olympic rings is the simplest? in fact, its drawing process is to draw five circles of the same size with a brush. The difference is that the position of the circle is different.

阅读全文

开始之前,我特地去找了turtle的官网地址贴在下面,其实学习一个技术点官网的作用还是非常重要的。毕竟你在网上找到大量的资料都是二手资料。

因此,你可能不理解这个技术点的初衷,最终一个技术点变成了假的。因此,为了鼓励你学习一个技术点,你必须看看官方网站上的说明。从外地来的二手资料是用来理解的。

[En]

Therefore, you may not understand the original intention of this technical point, and in the end, a technical point becomes false. Therefore, to encourage you to learn a technical point, you must take a look at the instructions on the official website. Second-hand materials from other places are used to understand.

https://docs.python.org/zh-cn/3/library/tle.html

python中最简单的turtle绘图:奥运五环

使用的非标准库还是turtle,因为它在绘画中的作用还是相当重要的。

import turtle as tle

编写一个函数来初始化turtle画笔的一些全局参数。

def init():
    tle.pensize(20)

init()

这次我们使用一个全局参数,只需设置笔刷的宽度。

[En]

This time we use a single global parameter, just set the width of the brush.

下面是写一个画圆的函数,因为五个圆的大小都一样,有一些共同之处,所以可以用一个函数来写画圆的过程。

[En]

The following is to write a function to draw a circle, because the five circles are all the same size, which has something in common, so you can use a function to write the circle drawing process.

def draw_cricle(circle_size=100,x=-250,y=-30,color='blue'):
    tle.penup()
    tle.goto(x, y)
    tle.pendown()
    tle.color(color)
    tle.circle(100)

调用画圆函数,画出五个不同颜色的环,最后生成奥林匹克五环的形状。

[En]

Call the circle drawing function to draw five rings of different colors, and finally generate 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')

看了上面操作过程,操作还是挺简单的,用来做一个turtle学习素材还是很nice的。

上面的过程完成后,绘图的部分就算是完成了,最后再来完善一下逻辑。因为绘图完成后会自动关闭绘图窗口,绘图完成后还没看清楚就已经关闭了。于是,设置一下绘制窗口的属性就OK了。

绘图完成后保持窗口打开

[En]

Keep the window open after the drawing is completed

screen = tle.Screen()
screen.exitonclick()

今天的表演到此结束。欢迎交流与进步,不断分享与分享。

[En]

This is the end of today’s performance. Welcome to communicate and make progress, keep on sharing and sharing.

python中最简单的turtle绘图:奥运五环

【往期精彩】

知识汇总:python办公自动化应该学习哪些内容?

python多线程同步售票系统解决思路…

找几个好玩的游戏编程平台和你分享!

[En]

Find several fun game programming platforms to share with you!

python四个性能检测工具,包括函数的运行内存、时间等等…

python-turtle绘制雪容融,已打包成exe可直接运行(附源码)

Original: https://www.cnblogs.com/lwsbc/p/16255315.html
Author: Python集中营
Title: python中最简单的turtle绘图:奥运五环

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/499601/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球