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


    一、中国结 01 平安喜乐

    1)效果图

    1. import turtle
    2. turtle.screensize(600,800)
    3. turtle.pensize(10)
    4. turtle.pencolor("red")
    5. turtle.seth(-45)
    6. turtle.fd(102)
    7. turtle.circle(-6,180)
    8. turtle.fd(102)
    9. turtle.circle(6,180)
    10. turtle.fd(102)
    11. turtle.circle(-6,180)
    12. turtle.fd(102)
    13. turtle.circle(6,180)
    14. turtle.fd(102)
    15. turtle.circle(-6,180)
    16. turtle.fd(102)
    17. turtle.circle(6,180)
    18. turtle.fd(92)
    19. turtle.circle(-6,270)
    20. turtle.fd(92)
    21. turtle.circle(6,180)
    22. turtle.fd(102)
    23. turtle.circle(-6,180)
    24. turtle.fd(102)
    25. turtle.circle(6,180)
    26. turtle.fd(102)
    27. turtle.circle(-6,180)
    28. turtle.fd(102)
    29. turtle.circle(6,180)
    30. turtle.fd(102)
    31. turtle.circle(-6,180)
    32. turtle.fd(88)
    33. turtle.fd(20)
    34. turtle.seth(135)
    35. turtle.fd(20)
    36. turtle.seth(225)
    37. turtle.fd(20)
    38. turtle.seth(315)
    39. turtle.fd(20)
    40. turtle.seth(45)
    41. turtle.fd(20)
    42. turtle.seth(135)
    43. turtle.begin_fill()
    44. turtle.fillcolor("red")
    45. turtle.fd(50)
    46. turtle.seth(45)
    47. turtle.fd(30)
    48. turtle.seth(-45)
    49. turtle.fd(30)
    50. turtle.seth(225)
    51. turtle.fd(30)
    52. turtle.end_fill()
    53. turtle.seth(90)
    54. turtle.fd(40)
    55. turtle.pensize(20)
    56. turtle.fd(10)
    57. turtle.pensize(5)
    58. turtle.seth(105)
    59. turtle.fd(30)
    60. turtle.circle(-8,240)
    61. turtle.circle(20,20)
    62. turtle.fd(5)
    63. turtle.circle(20,60)
    64. turtle.fd(25)
    65. turtle.penup()
    66. turtle.setx(0)
    67. turtle.sety(0)
    68. turtle.goto(2,-127)
    69. turtle.pendown()
    70. turtle.pensize(5)
    71. turtle.begin_fill()
    72. turtle.fillcolor("red")
    73. turtle.seth(0)
    74. turtle.fd(15)
    75. turtle.seth(-90)
    76. turtle.fd(10)
    77. turtle.seth(180)
    78. turtle.fd(15)
    79. turtle.seth(90)
    80. turtle.fd(10)
    81. turtle.seth(0)
    82. turtle.fd(15)
    83. turtle.end_fill()
    84. turtle.pensize(2)
    85. for x in range(6):
    86. turtle.seth(-90)
    87. turtle.fd(50)
    88. turtle.penup()
    89. turtle.seth(90)
    90. turtle.fd(50)
    91. turtle.seth(180)
    92. turtle.fd(3)
    93. turtle.pendown()

    二、中国结 02 心想事成

    1)效果图

    1. import turtle as t
    2. def goto(x,y):
    3. t.penup()
    4. t.goto(x,y)
    5. t.pendown()
    6. def init():
    7. t.setup(800,800)
    8. t.pensize(10)
    9. t.pencolor("red")
    10. t.speed(14)
    11. def jiexin():
    12. m,n=0,200
    13. for i in range(11):
    14. goto(m,n)
    15. t.seth(-45)
    16. t.fd(200)
    17. m-=20/pow(2,0.5)
    18. n-=20/pow(2,0.5)
    19. m,n=0,200
    20. for j in range(11):
    21. goto(m,n)
    22. t.seth(-135)
    23. t.fd(200)
    24. m+=20/pow(2,0.5)
    25. n-=20/pow(2,0.5)
    26. def jiexiaoban():
    27. m=-20/pow(2,0.5)
    28. n=200-20/pow(2,0.5)
    29. for k in range(4):
    30. goto(m,n)
    31. t.seth(135)
    32. t.fd(20)
    33. t.circle(10,180)
    34. t.fd(20)
    35. m-=40/pow(2,0.5)
    36. n-=40/pow(2,0.5)
    37. m=20/pow(2,0.5)
    38. n=200-20/pow(2,0.5)
    39. for k in range(4):
    40. goto(m,n)
    41. t.seth(45)
    42. t.fd(20)
    43. t.circle(-10,180)
    44. t.fd(20)
    45. m+=40/pow(2,0.5)
    46. n-=40/pow(2,0.5)
    47. m=20/pow(2,0.5)
    48. n=200-200*pow(2,0.5)+20/pow(2,0.5)
    49. for k in range(4):
    50. goto(m,n)
    51. t.seth(-45)
    52. t.fd(20)
    53. t.circle(10,180)
    54. t.fd(20)
    55. m+=40/pow(2,0.5)
    56. n+=40/pow(2,0.5)
    57. m=-20/pow(2,0.5)
    58. n=200-200*pow(2,0.5)+20/pow(2,0.5)
    59. for k in range(4):
    60. goto(m,n)
    61. t.seth(-135)
    62. t.fd(20)
    63. t.circle(-10,180)
    64. t.fd(20)
    65. m-=40/pow(2,0.5)
    66. n+=40/pow(2,0.5)
    67. def waiyuan():
    68. goto(90*pow(2,0.5),200-110*pow(2,0.5))
    69. t.seth(-45)
    70. t.circle(20,270)
    71. goto(-90*pow(2,0.5),200-110*pow(2,0.5))
    72. t.seth(-135)
    73. t.circle(-20,270)
    74. goto(80*pow(2,0.5),200-120*pow(2,0.5))
    75. t.seth(-45)
    76. t.circle(40,270)
    77. goto(-80*pow(2,0.5),200-120*pow(2,0.5))
    78. t.seth(-135)
    79. t.circle(-40,270)
    80. def shengzi():
    81. goto(0,200)
    82. t.pensize(20)
    83. t.seth(90)
    84. t.fd(60)
    85. goto(0,320)
    86. t.pensize(12)
    87. t.seth(180)
    88. t.circle(30,360)
    89. goto(0,200-200*pow(2,0.5))
    90. t.pensize(40)
    91. t.seth(-90)
    92. t.fd(20)
    93. t.pensize(2)
    94. s=-20
    95. for i in range(11):
    96. goto(s,200-200*pow(2,0.5))
    97. t.seth(-90)
    98. t.fd(200)
    99. s+=4
    100. def hanzi():
    101. goto(-150,325)
    102. t.write("幸福中国结",font=("Arial",40,"normal"))
    103. def main():
    104. init()
    105. jiexin()
    106. jiexiaoban()
    107. waiyuan()
    108. shengzi()
    109. hanzi()
    110. t.hideturtle()

  • 相关阅读:
    H7-TOOL的CANFD/CAN接口脱机烧写操作说明, 已经更新(2022-07-12)
    计算机毕业设计选什么题目好?springboot 学习笔记系统
    ESP32网络开发实例-连接信号最强的热点
    利用uvicorn、Starlette和pipeline将一个训练好的大模型发布成一个web服务
    MyBatis笔记03------XXXMapper.xml文件解析
    艺术与科技的狂欢,阿那亚2022砂之盒沉浸艺术季
    微信小程序之图片上传并保存在服务器
    2022-08-29 第六小组 瞒春 学习笔记
    linux centos7提示 cannot found font installed on the system.calibri
    通过HTTP来总结网络编程知识
  • 原文地址:https://blog.csdn.net/abilix_tony/article/details/133880821