详解Python如何利用turtle绘制中国结

作者:顾木子吖 时间:2021-02-10 13:52:29 

导语

春节是中国特有的传统节日,中国结是中华民族特有的纯粹的文化精髓,富含丰富的文化底蕴,代表着我们对未来,对美好生活的向往和憧憬。新春佳节,小编祝福大家虎年吉祥!万事如意!祝我们的祖国引领世界,勇立潮头!国富民强!

详解Python如何利用turtle绘制中国结

渐渐的,渐渐的,新年很快就要到来。在快过新年时,人们有一个习俗,那就是买“中国结”。

据说,中国结可以让一家人平平安安、幸福,所以,中国结就一直为人们喜爱。

中国结制作十分精巧、巧妙,令人叹为观止。今天小编用代码给大家编制拜年礼物绘制多种《中国结合集》啦~

详解Python如何利用turtle绘制中国结

一、中国结 01  平安喜乐

1)效果图

详解Python如何利用turtle绘制中国结

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)效果图

详解Python如何利用turtle绘制中国结

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 烟火年年

辞慕尔尔,烟火年年,前程似锦,顺遂康安。

详解Python如何利用turtle绘制中国结

来源:https://blog.csdn.net/weixin_55822277/article/details/122679817

标签:Python,turtle,中国结
0
投稿

猜你喜欢

  • 低效的键盘和高效的登录框

    2007-08-22 09:17:00
  • 探秘TensorFlow 和 NumPy 的 Broadcasting 机制

    2023-07-22 06:09:50
  • sql之IN和BETWEEN条件运算

    2007-09-11 13:35:00
  • django ManyToManyField多对多关系的实例详解

    2023-08-11 20:21:01
  • Python matplotlib画图时图例说明(legend)放到图像外侧详解

    2021-03-05 13:42:45
  • python密码学RSA密码加密教程

    2023-08-03 17:09:10
  • ASP访问数量统计代码

    2011-04-08 10:59:00
  • 详解python中的文件与目录操作

    2023-10-15 06:15:03
  • PHP字符转义相关函数小结(php下的转义字符串)

    2023-11-16 14:29:18
  • 使用pdb模块调试Python程序实例

    2023-08-11 08:36:28
  • 如何编写高质量的Javascript代码

    2011-03-07 16:04:00
  • python使用wxPython打开并播放wav文件的方法

    2023-08-23 10:30:58
  • MySQL列类型的选择与MySQL的查询效率

    2009-01-14 12:53:00
  • 简单介绍利用TK在Python下进行GUI编程的教程

    2023-01-05 21:24:25
  • Python逐行读取文件中内容的简单方法

    2023-03-02 16:01:09
  • pycharm如何设置自动生成作者信息

    2021-01-21 22:20:58
  • Win10系统提示“Python 0x80070643安装时发生严重错误”怎么办?

    2023-06-13 06:50:25
  • Idea开发工具之SpringBoot整合JSP的过程

    2023-06-14 19:50:23
  • MySQL在命名用过程中所遇到的常见问题

    2008-12-05 16:03:00
  • SQL Server 2008中有关XML的新功能

    2008-06-04 12:57:00
  • asp之家 网络编程 m.aspxhome.com