世界视点!Python+turtle绘制对称图形的示例代码
目录
1.图12.图23.图34.图45.图56.图6最近有个朋友,想要我帮忙用python画几个图,在画的过程中觉得有些图还挺有意思的,分享给大家。
1.图1
第一个图是由三角形组成的花,感兴趣的小伙伴可以自己尝试在python中用turtle库绘制一下。
具体代码如下:
【资料图】
# -*- coding: UTF-8 -*-
"""
代码用途 :画对称图形
作者 :阿黎逸阳
博客 : https://blog.csdn.net/qq_32532663/article/details/106176609
"""
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代码,绘制出如下图形?
具体代码如下:
# -*- coding: UTF-8 -*-
"""
代码用途 :画对称图形
作者 :阿黎逸阳
博客 : https://blog.csdn.net/qq_32532663/article/details/106176609
"""
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
第三个图是八叶花,你也可以试着把叶子改成别的颜色。
具体代码如下:
# -*- coding: UTF-8 -*-
"""
代码用途 :画对称图形
作者 :阿黎逸阳
博客 : https://blog.csdn.net/qq_32532663/article/details/106176609
"""
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叶花代码,绘制出如下图形?
具体代码如下:
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叶花代码,绘制出如下图形?
具体代码如下:
# -*- coding: UTF-8 -*-
"""
代码用途 :画对称图形
作者 :阿黎逸阳
博客 : https://blog.csdn.net/qq_32532663/article/details/106176609
"""
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
第六个图是阴阳图。
具体代码如下:
# -*- coding: UTF-8 -*-
"""
代码用途 :画对称图形
作者 :阿黎逸阳
博客 : https://blog.csdn.net/qq_32532663/article/details/106176609
"""
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绘制对称图形的示例代码的文章就介绍到这了,更多相关Python turtle绘制对称图形内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
X 关闭
X 关闭
- 1转转集团发布2022年二季度手机行情报告:二手市场“飘香”
- 2充电宝100Wh等于多少毫安?铁路旅客禁止、限制携带和托运物品目录
- 3好消息!京东与腾讯续签三年战略合作协议 加强技术创新与供应链服务
- 4名创优品拟通过香港IPO全球发售4100万股 全球发售所得款项有什么用处?
- 5亚马逊云科技成立量子网络中心致力解决量子计算领域的挑战
- 6京东绿色建材线上平台上线 新增用户70%来自下沉市场
- 7网红淘品牌“七格格”chuu在北京又开一家店 潮人新宠chuu能红多久
- 8市场竞争加剧,有车企因经营不善出现破产、退网、退市
- 9北京市市场监管局为企业纾困减负保护经济韧性
- 10市场监管总局发布限制商品过度包装标准和第1号修改单

