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

 更新时间:2022年02月11日 10:40:16   作者:顾木子吖  
春节是中国特有的传统节日,中国结是中华民族特有的纯粹的文化精髓,富含丰富的文化底蕴。本文将利用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 烟火年年

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

总结

最后祝大家:大吉大利,平安喜乐,锦鲤附体,好事发生,发个大财,心想事成!

到此这篇关于详解Python如何利用turtle绘制中国结的文章就介绍到这了,更多相关Python turtle绘制中国结内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Python使用面向对象方式创建线程实现12306售票系统

    Python使用面向对象方式创建线程实现12306售票系统

    目前python 提供了几种多线程实现方式 thread,threading,multithreading ,其中thread模块比较底层,而threading模块是对thread做了一些包装,可以更加方便的被使用
    2015-12-12
  • 关于python tushare Tkinter构建的简单股票可视化查询系统(Beta v0.13)

    关于python tushare Tkinter构建的简单股票可视化查询系统(Beta v0.13)

    这篇文章主要介绍了python tushare Tkinter构建的简单股票可视化查询系统(Beta v0.13),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-10-10
  • python数据分析之单因素分析线性拟合及地理编码

    python数据分析之单因素分析线性拟合及地理编码

    这篇文章主要介绍了python数据分析之单因素分析线性拟合及地理编码,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下
    2022-06-06
  • 详解字典树Trie结构及其Python代码实现

    详解字典树Trie结构及其Python代码实现

    Trie多被用来查找和统计字符串,利用公共前缀来减少搜索时间,下面我们就来详解字典树Trie结构及其Python代码实现
    2016-06-06
  • python中enumerate函数遍历元素用法分析

    python中enumerate函数遍历元素用法分析

    这篇文章主要介绍了python中enumerate函数遍历元素用法,结合实例形式分析了enumerate函数遍历元素的相关实现技巧,需要的朋友可以参考下
    2016-03-03
  • 简单介绍Python中的JSON模块

    简单介绍Python中的JSON模块

    这篇文章主要介绍了简单介绍Python中的JSON模块,包括初步的从Python中的数据格式转换为JSON格式等,需要的朋友可以参考下
    2015-04-04
  • Python 解析获取 URL 参数及使用步骤

    Python 解析获取 URL 参数及使用步骤

    这篇文章主要介绍了Python 解析获取 URL 参数及使用,本文分步骤通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-06-06
  • Python 3.x踩坑实战汇总

    Python 3.x踩坑实战汇总

    因项目需要最近接手维护后续python程序并做后续开发,下面这篇文章主要给大家介绍了关于Python 3.x踩坑的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-03-03
  • 使用Python读取大文件的方法

    使用Python读取大文件的方法

    这篇文章主要介绍了使用Python读取大文件的方法,需要的朋友可以参考下
    2018-02-02
  • 基于Python 优化 MUI标题栏

    基于Python 优化 MUI标题栏

    这篇文章主要介绍的是基于Python 优化 MUI标题栏,一个特色鲜明MUI界面无疑是能够吸引用户的关键之一,这利用css和JavaScript可以很快进行实现,但是同时对于初学者来说也是困难的,下面文章就来学习几个简单的小技巧实现页面美化吧,需要的朋友可以参考一下
    2021-11-11

最新评论