利用Python turtle绘制中国结附源码

一、中国结 01 平安喜乐

1)效果图

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

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()

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星卯教育tony

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值