详解Python如何利用turtle绘制中国结
作者:顾木子吖 发布时间:2021-02-10 13:52:29
标签:Python,turtle,中国结
导语
春节是中国特有的传统节日,中国结是中华民族特有的纯粹的文化精髓,富含丰富的文化底蕴,代表着我们对未来,对美好生活的向往和憧憬。新春佳节,小编祝福大家虎年吉祥!万事如意!祝我们的祖国引领世界,勇立潮头!国富民强!
渐渐的,渐渐的,新年很快就要到来。在快过新年时,人们有一个习俗,那就是买“中国结”。
据说,中国结可以让一家人平平安安、幸福,所以,中国结就一直为人们喜爱。
中国结制作十分精巧、巧妙,令人叹为观止。今天小编用代码给大家编制拜年礼物绘制多种《中国结合集》啦~
一、中国结 01 平安喜乐
1)效果图
2)附代码
import turtle
turtle.screensize(600,800)
turtle.pensize(10)
turtle.pencolor("red")
turtle.seth(-45)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(92)
turtle.circle(-6,270)
turtle.fd(92)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(88)
turtle.fd(20)
turtle.seth(135)
turtle.fd(20)
turtle.seth(225)
turtle.fd(20)
turtle.seth(315)
turtle.fd(20)
turtle.seth(45)
turtle.fd(20)
turtle.seth(135)
turtle.begin_fill()
turtle.fillcolor("red")
turtle.fd(50)
turtle.seth(45)
turtle.fd(30)
turtle.seth(-45)
turtle.fd(30)
turtle.seth(225)
turtle.fd(30)
turtle.end_fill()
turtle.seth(90)
turtle.fd(40)
turtle.pensize(20)
turtle.fd(10)
turtle.pensize(5)
turtle.seth(105)
turtle.fd(30)
turtle.circle(-8,240)
turtle.circle(20,20)
turtle.fd(5)
turtle.circle(20,60)
turtle.fd(25)
turtle.penup()
turtle.setx(0)
turtle.sety(0)
turtle.goto(2,-127)
turtle.pendown()
turtle.pensize(5)
turtle.begin_fill()
turtle.fillcolor("red")
turtle.seth(0)
turtle.fd(15)
turtle.seth(-90)
turtle.fd(10)
turtle.seth(180)
turtle.fd(15)
turtle.seth(90)
turtle.fd(10)
turtle.seth(0)
turtle.fd(15)
turtle.end_fill()
turtle.pensize(2)
for x in range(6):
turtle.seth(-90)
turtle.fd(50)
turtle.penup()
turtle.seth(90)
turtle.fd(50)
turtle.seth(180)
turtle.fd(3)
turtle.pendown()
二、中国结 02 心想事成
1)效果图
2)附代码
import turtle as t
def goto(x,y):
t.penup()
t.goto(x,y)
t.pendown()
def init():
t.setup(800,800)
t.pensize(10)
t.pencolor("red")
t.speed(14)
def jiexin():
m,n=0,200
for i in range(11):
goto(m,n)
t.seth(-45)
t.fd(200)
m-=20/pow(2,0.5)
n-=20/pow(2,0.5)
m,n=0,200
for j in range(11):
goto(m,n)
t.seth(-135)
t.fd(200)
m+=20/pow(2,0.5)
n-=20/pow(2,0.5)
def jiexiaoban():
m=-20/pow(2,0.5)
n=200-20/pow(2,0.5)
for k in range(4):
goto(m,n)
t.seth(135)
t.fd(20)
t.circle(10,180)
t.fd(20)
m-=40/pow(2,0.5)
n-=40/pow(2,0.5)
m=20/pow(2,0.5)
n=200-20/pow(2,0.5)
for k in range(4):
goto(m,n)
t.seth(45)
t.fd(20)
t.circle(-10,180)
t.fd(20)
m+=40/pow(2,0.5)
n-=40/pow(2,0.5)
m=20/pow(2,0.5)
n=200-200*pow(2,0.5)+20/pow(2,0.5)
for k in range(4):
goto(m,n)
t.seth(-45)
t.fd(20)
t.circle(10,180)
t.fd(20)
m+=40/pow(2,0.5)
n+=40/pow(2,0.5)
m=-20/pow(2,0.5)
n=200-200*pow(2,0.5)+20/pow(2,0.5)
for k in range(4):
goto(m,n)
t.seth(-135)
t.fd(20)
t.circle(-10,180)
t.fd(20)
m-=40/pow(2,0.5)
n+=40/pow(2,0.5)
def waiyuan():
goto(90*pow(2,0.5),200-110*pow(2,0.5))
t.seth(-45)
t.circle(20,270)
goto(-90*pow(2,0.5),200-110*pow(2,0.5))
t.seth(-135)
t.circle(-20,270)
goto(80*pow(2,0.5),200-120*pow(2,0.5))
t.seth(-45)
t.circle(40,270)
goto(-80*pow(2,0.5),200-120*pow(2,0.5))
t.seth(-135)
t.circle(-40,270)
def shengzi():
goto(0,200)
t.pensize(20)
t.seth(90)
t.fd(60)
goto(0,320)
t.pensize(12)
t.seth(180)
t.circle(30,360)
goto(0,200-200*pow(2,0.5))
t.pensize(40)
t.seth(-90)
t.fd(20)
t.pensize(2)
s=-20
for i in range(11):
goto(s,200-200*pow(2,0.5))
t.seth(-90)
t.fd(200)
s+=4
def hanzi():
goto(-150,325)
t.write("幸福中国结",font=("Arial",40,"normal"))
def main():
init()
jiexin()
jiexiaoban()
waiyuan()
shengzi()
hanzi()
t.hideturtle()
三、中国结 03 烟火年年
辞慕尔尔,烟火年年,前程似锦,顺遂康安。
来源:https://blog.csdn.net/weixin_55822277/article/details/122679817


猜你喜欢
- 音乐播放器可让您快速轻松地管理和收听所有音乐文件。在本文中,我将带您了解如何使用 Python 创建音乐播放器 GUI。如何使用 Pytho
- mysql版本:8.0.28xtrabackup版本:8.0.281、安装xtrabackup下载地址:Download Percona X
- 1、静态网页与动态比较: 1)静态网页: 优势:A、 对搜索引擎友好,被收录的质量高;B、访问速度快;C、资源(cpu 等)占用少。 劣势:
- 1.网络爬虫的基本概念网络爬虫(又称网络蜘蛛,机器人),就是模拟客户端发送网络请求,接收请求响应,一种按照一定的规则,自动地抓取互联网信息的
- 网上的SQL优化的文章实在是很多,说实在的,我也曾经到处找这样的文章,什么不要使用IN了,什么OR了,什么AND了,很多很多,还有很多人拿出
- 前言段(segment)是一种在数据库中消耗物理存储空间的任何实体(一个段可能存在于多个数据文件中,因为物理的数据文件是组成逻辑表空间的基本
- //有1-22个文件夹,各文件夹下有Detect_0文件夹,此文件夹下有source与mask文件夹,目的是将需要获取图片的文件夹下的图片复
- 即使在urlencode之前str.decode(“cp936″).encode(“utf-8″)做了编码转换也是没用的。后来查询手册查到一
- 用过NumPY的应该都知道,在二维数组中可以方便地使用区域切片功能,如下图:而这个功能在Python标准库的List中是不支持的,在List
- 本文实例为大家分享了python批量梯度下降算法的具体代码,供大家参考,具体内容如下问题:将拥有两个自变量的二阶函数绘制到空间坐标系中,并通
- 起步Django 是个同步框架,本文并不是 让 Django 变成异步框架。而是对于在一个 view 中需要请求多次 http api 的场
- TextRank 是一种基于 PageRank 的算法,常用于关键词提取和文本摘要。在本文中,我将通过一个关键字提取示例帮助您了解 Text
- IEEE Spectrum 根据以下数据来源,对各大编程语言的使用普及率进行了统计。1)谷歌搜索结果2)谷歌趋势分析3)推特 (这是什么东西
- ASP获取远程文件的通过header头信息,并返回远程文件大小信息,远程文件可以是网页或RAR,EXE任何格式的文件。以下是具体代码:<
- 1 参数选择 径向畸变3个参数还是两个参数默认两个参数如果是三个参数2准备转化生成结果二参数的转化代码writeExternalandInt
- 所有数据库mysqlcheck --auto-repair -A -o -uroot -pyigeorg单一数据库mysqlcheck --
- 本文实例为大家分享了vuex实现购物车功能的具体代码,供大家参考,具体内容如下页面布局:采用了element-ui的表格对商品列表和购物车列
- 一、Node.js实现代码var http = require('http');var util = require(
- 1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :(导致 “SyntaxE
- 中文乱码问题当我第一次接触mysql,首先让我难受的是mysql的乱码问题,百度上也有许多有关的解决方案,不过作为亲身受害者,我想很有必要贴