{"id":9187,"date":"2024-05-09T21:01:01","date_gmt":"2024-05-09T13:01:01","guid":{"rendered":""},"modified":"2024-05-09T21:01:01","modified_gmt":"2024-05-09T13:01:01","slug":"python:turtle\u753b\u56fe \u5854","status":"publish","type":"post","link":"https:\/\/mushiming.com\/9187.html","title":{"rendered":"python:turtle\u753b\u56fe \u5854"},"content":{"rendered":"

\u622a\u56fe\uff1a<\/p>\n

\"python:turtle\u753b\u56fe<\/p>\n

\u7f51\u5740\uff1a<\/p>\n

https:\/\/python123.io\/index\/turtles\/5f277f1977034976bcae26f1<\/p>\n

\u6280\u672f\u8981\u70b9\uff1a<\/p>\n

1.\u6ce8\u610fturtle\u81ea\u8eab\u7684\u5750\u6807\u7cfb\u3001\u5750\u6807\u8f74\u671d\u5411\u3002<\/p>\n

2.\u6bcf\u4e00\u5c42\u8981\u786e\u5b9a\u4e00\u4e2a\u6d77\u9f9f\u8d77\u70b9\uff0c\u6211\u7528\u7684\u662f\u4e00\u5c42\u56fe\u6848\u7684\u5de6\u4e0b\u89d2\u4f4d\u7f6e\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002\u6839\u636e\u8fd9\u4e2a\u8d77\u59cb\u70b9\uff0c\u6765\u8ba1\u7b97\u6bcf\u5c42\u7684\u6570\u636e\u53d8\u5316\u3001\u8bbe\u5b9a\u753b\u56fe\u8ddd\u79bb\u3002<\/p>\n

\u7ea2\u8272\u4f4d\u7f6e\u5c31\u662f\u6bcf\u5c42\u56fe\u6848\u7684\u8d77\u70b9\u3002<\/p>\n

\"python:turtle\u753b\u56fe<\/p>\n

3. \u77e9\u5f62\u3001\u68af\u5f62\u3001\u4e09\u89d2\u5f62\uff0c\u90fd\u53ef\u4ee5\u505a\u6210\u51fd\u6570\u3002\u5982\u679c\u68af\u5f62\u53ef\u4ee5\u4efb\u610f\u6307\u5b9a\u9ad8\u5ea6\u53c2\u6570\uff0c\u9700\u8981\u518d\u52a0\u4e09\u89d2\u51fd\u6570\u7684\u8ba1\u7b97\u3002\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6211\u7684\u68af\u5f62\u90fd\u7528\u9ad8\u5ea615\u3001\u5e95\u89d2tan\u4e3a15\u6bd430\uff0c\u8fd9\u6837\u4e0a\u5e95\u7684\u957f\u5ea6\u6bd4\u4e0b\u5e95\u5c1160. \u68af\u5f62\u7684\u6a21\u5757\uff0c\u53c2\u6570\u6709\u591a\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff0c\u53ef\u4ee5\u662f\u957f\u5ea6\u3001\u89d2\u5ea6\u3001\u659c\u8fb9\u957f\u5ea6\u3002<\/p>\n

\u4ee3\u7801\uff1a<\/p>\n

#20200803 \u94a2\u4e03\u8fde\n# python\u753b\u56fe\nimport turtle\nimport math\n\n\nmapx=-240\nmapy=-240\nlevel_h=60\n\ndef top_tri(size):\n    turtle.begin_fill()\n    turtle.fillcolor('#84c1ff')\n    turtle.forward(15)\n    for i in range(3):\n         turtle.forward(size)\n         turtle.left(120)\n    turtle.end_fill()\n    \ndef rect(w,h):\n    turtle.begin_fill()\n    turtle.fillcolor('#0f0')\n    for x in range(4):\n        if x % 2 == 1:\n            n = h\n        else:\n            n = w\n        turtle.forward(n)\n        turtle.left(90)\n    # end for\n    turtle.end_fill()\n\n# \u68af\u5f62\ndef trapezoid(w1, w2 ):\n    angle_c=27\n    turtle.begin_fill()\n    turtle.fillcolor('#00f')\n    turtle.forward(w1)\n    turtle.left(180-angle_c )\n    turtle.forward(34)\n    turtle.left(angle_c )\n    turtle.forward(w2)\n    turtle.left(angle_c )\n    turtle.forward(34)\n    turtle.end_fill()\n\ndef draw_level(size,level):\n        turtle.penup()\n        turtle.goto( (480- size)\/2+ mapx ,mapy+ level* level_h)\n        turtle.setheading(0)\n        # \u79fb\u52a8\u5230\u77e9\u5f62\u5de6\u4e0b\u89d2\n        turtle.penup()\n        turtle.forward(15)\n        #\u753b\u4e00\u5c42\n        turtle.pendown()\n        rect(size-30, level_h-15)\n        #\u5148\u62ac\u7b14\uff0c\u518d\u79fb\u52a8\u5230\u623f\u6a90\u5de6\u4e0b\u89d2\n        turtle.penup()\n        turtle.goto( (480- size)\/2+ mapx ,mapy+ level* level_h+45)\n        trapezoid(size, size-60 )\n\ndef main():\n    draw_w=260\n    turtle.speed(5)\n    turtle.showturtle()\n    # \u753b\u7b14\u9690\u5f62\n    # \u753b\u7b14\u6709\u6548\n    turtle.pendown()\n    turtle.pensize(2)\n    turtle.color('brown')\n\n    for i in range(7):\n        draw_level( draw_w ,i)\n        draw_w-=30\n    #\u5854\u5c16    \n    turtle.goto( (480- 260+ 7*30 )\/2+ mapx ,mapy+ 7* level_h)\n    turtle.setheading(0)\n    top_tri(20) \n    turtle.hideturtle()\n        \n# unit test\n#rect(90, 45)\n#trapezoid(200, 140 )\n\n\nmain()\n\n\n<\/code><\/pre>\n

\u4e00\u4e2apython\u7684\u7b80\u5355\u4f8b\u5b50\u3002\u5b66\u4e60\u7684\u901a\u75c5\uff0c\u5b66\u751f\u53ea\u662f\u4f1a\u4e86\u8fd9\u4e2a\u7b54\u6848\uff0c\u7f3a\u5e94\u7528\u548c\u53d8\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"python:turtle\u753b\u56fe \u5854\u622a\u56fe\uff1a\u7f51\u5740\uff1ahttps:\/\/python123.io\/index\/turtles\/5f277f1977034976bcae26f1\u6280\u672f\u8981\u70b9\uff1a1.\u6ce8\u610fturtle\u81ea\u8eab...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/9187"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=9187"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/9187\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=9187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=9187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=9187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}