温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么使用Python+turtle绘制对称图形

发布时间:2022-07-12 10:00:53 来源:亿速云 阅读:499 作者:iii 栏目:开发技术

这篇文章主要介绍“怎么使用Python+turtle绘制对称图形”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“怎么使用Python+turtle绘制对称图形”文章能帮助大家解决问题。

1.图1

第一个图是由三角形组成的花,感兴趣的小伙伴可以自己尝试在python中用turtle库绘制一下。

怎么使用Python+turtle绘制对称图形

具体代码如下:

# -*- coding: UTF-8 -*-
import os
import time
import pygame
import turtle as t 

t.title('')
t.speed(10)
t.setup(startx=0, starty = 0, width=800, height = 600)
#第一幅图
def w_sg1(theta):
    t.setheading(theta)
    t.color('green')
    t.begin_fill()
    t.forward(60)
    t.left(100)
    t.forward(20)
    t.left(100)
    t.forward(60)
    t.end_fill()
for i in range(8):
    w_sg1(70 + i*45)
    t.hideturtle()

2.图2

第二个图是旋风轮,怎么通过调整图1代码,绘制出如下图形?

怎么使用Python+turtle绘制对称图形

具体代码如下:

# -*- coding: UTF-8 -*-
import os
import time
import pygame
import turtle as t 

t.title('')
t.speed(10)
t.setup(startx=0, starty = 0, width=800, height = 600)
#第二幅图
def w_sg2(theta):
    t.setheading(theta)
    t.color('green')
    t.begin_fill()
    t.forward(55)
    t.left(100)
    t.forward(20)
    t.left(100)
    t.forward(60)
    t.end_fill()
for i in range(24):
    w_sg2(70 + i*15)
    t.hideturtle()

3.图3

第三个图是八叶花,你也可以试着把叶子改成别的颜色。

怎么使用Python+turtle绘制对称图形

具体代码如下:

# -*- coding: UTF-8 -*-
import os
import time
import pygame
import turtle as t 

t.title('')
t.speed(10)
t.setup(startx=0, starty = 0, width=800, height = 600)
#第三幅图
def w_sg3(theta):
    t.color('green')
    t.begin_fill()
    t.setheading(theta)
    t.circle(80, 50)
    t.left(130)
    t.circle(80, 50)
    t.end_fill()
for i in range(8):
    w_sg3(30 + i*45)
    t.hideturtle()

4.图4

第四个图是16叶花,怎么通过调整8叶花代码,绘制出如下图形?

怎么使用Python+turtle绘制对称图形

具体代码如下:

t.clearscreen()
#第四幅图
for i in range(16):
    w_sg3(30 + i*30)
    t.hideturtle() 
t.goto(0, -3)
t.color('white')
t.begin_fill()
t.circle(6, 360)
t.end_fill()

5.图5

第五个图是小太阳,怎么通过调整8叶花代码,绘制出如下图形?

怎么使用Python+turtle绘制对称图形

具体代码如下:

# -*- coding: UTF-8 -*-
import os
import time
import pygame
import turtle as t 

t.title('')
t.speed(10)
t.setup(startx=0, starty = 0, width=800, height = 600)
#第五幅图
def w_sg3(theta):
    t.color('red')
    t.begin_fill()
    t.setheading(theta)
    t.circle(80, 50)
    t.left(130)
    t.circle(80, 50)
    t.end_fill()
for i in range(24):
    w_sg3(30 + i*15)
    t.hideturtle()

6.图6

第六个图是阴阳图。

怎么使用Python+turtle绘制对称图形

具体代码如下:

# -*- coding: UTF-8 -*-
import os
import time
import pygame
import turtle as t 

t.title('')
t.speed(10)
t.setup(startx=0, starty = 0, width=800, height = 600)
#阴阳图
def w_sg4():
    t.color('black')
    t.begin_fill()
    t.circle(80, 360)
    t.end_fill()
    t.color('black', 'white')
    t.begin_fill()
    t.circle(80, 180)
    t.circle(40, 180)
    t.circle(-40, 180)
    t.end_fill()
    t.penup()
    t.goto(0, 130)
    t.pendown()
    t.begin_fill()
    t.color('black')
    t.circle(8, 360)
    t.end_fill()
    t.penup()
    t.goto(0, 130-90)
    t.pendown()
    t.begin_fill()
    t.color('white')
    t.circle(8, 360)
    t.end_fill()
    t.hideturtle()
w_sg4()

关于“怎么使用Python+turtle绘制对称图形”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI