{"id":7330,"date":"2024-04-07T08:01:01","date_gmt":"2024-04-07T00:01:01","guid":{"rendered":""},"modified":"2024-04-07T08:01:01","modified_gmt":"2024-04-07T00:01:01","slug":"Python turtle\u5236\u4f5c\u4e66\u6cd5\u4f5c\u54c1\u2014\u2014\u300a\u9e1f\u9e23\u6da7\u300b","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7330.html","title":{"rendered":"Python turtle\u5236\u4f5c\u4e66\u6cd5\u4f5c\u54c1\u2014\u2014\u300a\u9e1f\u9e23\u6da7\u300b"},"content":{"rendered":"

\u672c\u7bc7\u4ee5\u5510\u738b\u7ef4\u8bd7\u4f5c\u300a\u9e1f\u9e23\u6da7\u300b\u4e3a\u4f8b\uff0c\u4ecb\u7ecdPython\u7528turtle\u5236\u4f5c\u4e66\u6cd5\u4f5c\u54c1\u3002<\/p>\n

\u4e00\u3001\u7e41\u4f53\u5b57\u5e93\u5b89\u88c5<\/strong><\/p>\n

\u4e66\u6cd5\u4f5c\u54c1\u4ee5\u7e41\u4f53\u5b57\u4e3a\u4e3b\uff0c\u56fe\u7ae0\u4e00\u822c\u7528\u65b9\u7bc6\u4f53\u6216\u5370\u7ae0\u7bc6\u4f53\uff0c\u6587\u5b57\u4e00\u822c\u7528\u5c0f\u7bc6\u3001\u884c\u4e66\u3001\u884c\u6977\u3001\u8349\u4e66\u7b49\u3002\u672c\u4f8b\u4f7f\u7528\u201c\u5370\u7ae0\u7bc6\u4f53\u201d\u5236\u4f5c\u5370\u7ae0\uff0c\u4f7f\u7528\u201c\u65b9\u6b63\u5c0f\u7bc6\u4f53\u201d\u4e66\u5199\u4e66\u6cd5\u4e3b\u4f53\u6587\u5b57\uff0c\u843d\u6b3e\u4f7f\u7528\u201c\u6c49\u4eea\u884c\u6977\u7e41\u201d\u5b57\u4f53\u3002\u6240\u4ee5\u8981\u8fd0\u884c\u672c\u6848\u4f8b\uff0c\u9700\u8981\u9884\u5148\u4e0b\u8f7d\u5e76\u5b89\u88c5\u201c\u5370\u7ae0\u7bc6\u4f53\u201d\u3001\u201c\u65b9\u6b63\u5c0f\u7bc6\u4f53\u201d\u548c\u201c\u6c49\u4eea\u884c\u6977\u7e41\u201d\u4e09\u79cd\u5b57\u4f53\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u7528\u5176\u4ed6\u5b57\u4f53\u66ff\u4ee3\uff0c\u4f46\u6548\u679c\u4f1a\u4e0d\u4e00\u6837\u3002<\/p>\n

\u4e8c\u3001\u5370\u7ae0\u5236\u4f5c<\/strong><\/p>\n

\u4e66\u6cd5\u4f5c\u54c1\u843d\u6b3e\u4e00\u822c\u7528\u65b9\u7ae0\uff0c\u6587\u5b57\u53ef\u7528\u201c\u67d0\u67d0\u67d0\u5370\u201d\uff0c\u5916\u52a0\u65b9\u6846\u3002<\/p>\n

\u5e38\u89c4\u753b\u65b9\u6846\u7528\u56db\u4e2a\u76f4\u7ebf+(90\u00b0)\u8f6c\u5f2f\u7ed8\u5236\uff0c\u672c\u7bc7\u4ecb\u7ecd\u7528circle()\u65b9\u6cd5\u7ed8\u5236\u65b9\u6846\uff0c\u6ca1\u6709\u9519\uff0c\u7528\u753b\u5706\u65b9\u6cd5\u7ed8\u5236\u3002\u753b\u5706\u51fd\u6570\u7684\u8bed\u6cd5\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n

turtle.circle(radius,extent=None, steps=None)<\/p>\n

\u5176\u4e2d\uff1aradius\u4e3a\u6570\u503c\uff0c\u8868\u793a\u5706\u7684\u534a\u5f84\uff0c\u5982\u679c\u534a\u5f84\u4e3a\u6b63\u5219\u6309\u9006\u65f6\u9488\u65b9\u5411\u7ed8\u5236\u5706\u5f27\uff0c\u5426\u5219\u6309\u987a\u65f6\u9488\u65b9\u5411\u7ed8\u5236\u5706\u5f27\uff1bextent(\u53ef\u9009)\u4e3a\u6570\u503c\uff0c\u8868\u793a\u4ece\u5f53\u524d\u4f4d\u7f6e\u5f00\u59cb\u7ed8\u5236\u5706\u5f27\u7684\u89d2\u5ea6\uff0c\u5982\u679c\u7f3a\u7701\u5219\u7ed8\u5236\u6574\u4e2a\u5706\uff1bsteps(\u53ef\u9009)\u4e3a\u6574\u6570\uff0c\u8868\u793a\u5206\u591a\u5c11\u6bb5\u7ed8\u5236\u6307\u5b9a\u89d2\u5ea6\u7684\u5f27\u6216\u6574\u5706(\u5185\u63a5\u591a\u8fb9\u5f62)<\/p>\n

\u7531\u4e8e\u5706\u662f\u7531\u5185\u63a5\u6b63\u591a\u8fb9\u5f62\u8fd1\u4f3c\u7ed8\u5236\u7684\uff0c\u56e0\u6b64steps\u51b3\u5b9a\u8981\u4f7f\u7528\u7684\u6bb5\u6570\u3002\u5982\u679c\u672a\u7ed9\u51fa\uff0c\u5c06\u81ea\u52a8\u8ba1\u7b97\u3002\u53ef\u4ee5\u7528\u6765\u753b\u6b63\u591a\u8fb9\u5f62\u3002<\/p>\n

\u5e38\u89c4\u7f16\u7a0b\u4e3a\uff1a<\/p>\n

for i in range(4):<\/p>\n

    tl.fd(d)<\/p>\n

    tl.lt(90)<\/p>\n

\u7528circle()\u7f16\u7a0b\u4e3a\uff1a<\/p>\n

turtle.circle(d*0.707,360, 4)<\/p>\n

\u4f46\u7528circle()\u7ed8\u5236\u591a\u8fb9\u5f62\u65f6\uff0c\u5f53\u524d\u70b9\u662f\u5176\u4e2d\u7684\u4e00\u4e2a\u9876\u70b9\uff0c\u6240\u4ee5\u4e0a\u8ff0\u8bed\u53e5\u7ed8\u5236\u51fa\u6765\u7684\u662f\u4e00\u4e2a\u83f1\u5f62\uff0c\u9700\u8981\u9884\u544a\u53f3\u8f6c90\u00b0\uff0c\u624d\u80fd\u7ed8\u5236\u6b63\u65b9\u5f62\u3002<\/p>\n

\u5370\u7ae0\u5206\u201c\u9633\u523b\u201d\u4e0e\u201c\u9634\u523b\u201d\uff0c\u9633\u523b\uff1a\u5916\u6846\u548c\u6587\u5b57\u4e3a\u5370\u6ce5\u989c\u8272\u3001\u7a7a\u767d\u5904\u4e3a\u80cc\u666f\u989c\u8272\uff1b\u9634\u523b\uff1a\u5916\u6846\u548c\u6587\u5b57\u4e3a\u80cc\u666f\u989c\u8272\u3001\u7a7a\u767d\u5904\u4e3a\u5370\u6ce5\u989c\u8272\u3002<\/p>\n

\u7528turtle\u5236\u4f5c\u5370\u7ae0\u65f6\uff0c\u9633\u523b\u7528\u5370\u6ce5\u8272\u7ed8\u5236\u65b9\u6846\uff0c\u7528\u80cc\u666f\u8272\u586b\u8272\uff0c\u518d\u7528\u5370\u6ce5\u8272\u7ed8\u5236\u6587\u5b57\uff1b\u9634\u523b\u7528\u80cc\u666f\u8272\u7ed8\u5236\u65b9\u6846\uff0c\u7528\u5370\u6ce5\u8272\u586b\u8272\uff0c\u518d\u7528\u80cc\u666f\u8272\u7ed8\u5236\u6587\u5b57\u3002\u53c2\u89c1\u56fe1\u3002<\/p>\n

\"Python<\/p>\n

\u56fe<\/strong>1 <\/strong>\u5370\u7ae0<\/strong>(<\/strong>\u5de6\u4e3a\u9633\u523b\u3001\u53f3\u4e3a\u9634\u523b)<\/strong> <\/p>\n

\u4e09\u3001\u6587\u5b57\u7ad6\u6392\u663e\u793a\u8f93\u51fa<\/strong><\/p>\n

turtle\u7ed8\u5236\u6587\u5b57\u4f7f\u7528write()\u65b9\u6cd5\uff0c\u8bed\u6cd5\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n

write(arg, move=False,, font=('Arial', 8,'normal'))<\/p>\n

\u5176\u4e2d\uff1aarg\u4e3a\u5fc5\u9009\u53c2\u6570\uff0c\u7528\u4e8e\u6307\u5b9a\u8981\u8f93\u51fa\u7684\u6587\u5b57\u5185\u5bb9\uff0c\u8be5\u5185\u5bb9\u4ee5\u5f53\u524d\u5149\u6807\u6240\u5728\u5750\u6807\u4e3a\u5de6\u4e0b\u89d2\u8f93\u51fa\u5230\u5c4f\u5e55\uff1bmove(\u53ef\u9009\u53c2\u6570)\uff0c\u903b\u8f91\u503c\uff0c\u6307\u5b9a\u5149\u6807\u662f\u5426\u8ddf\u968f\uff0c\u9ed8\u8ba4\u4e3aFalse\uff0c\u4e0d\u8ddf\u968f(\u5149\u6807\u4f4d\u7f6e\u4e0d\u53d8)\uff1balign(\u53ef\u9009\u53c2\u6570)\u7528\u4e8e\u8bbe\u7f6e\u5bf9\u9f50\u65b9\u5f0f\uff0c\u53d6'left'\u3001'center'\u6216'right'\u4e2d\u7684\u4e00\u4e2a\uff0c\u8868\u793a\u5de6\u5bf9\u9f50\u3001\u5c45\u4e2d\u5bf9\u9f50\u6216\u53f3\u5bf9\u9f50\uff0c\u9ed8\u8ba4\u4e3a\u5de6\u5bf9\u9f50\uff1bfont(\u53ef\u9009\u53c2\u6570)\u7528\u4e8e\u8bbe\u7f6e\u5b57\u4f53\u3001\u5b57\u53f7\u548c\u5b57\u578b\uff0c\u4e3a\u4e09\u5143\u7ec4(\u5b57\u4f53\u540d\u79f0, \u5b57\u53f7\u5927\u5c0f, \u5b57\u578b)\u3002<\/p>\n

\u8bf4\u660e\uff1a\u5982\u679cmove\u8bbe\u7f6e\u4e3aTrue\uff0c\u5149\u6807\u5c06\u79fb\u52a8\u5230\u8f93\u51fa\u6587\u5b57\u7684\u53f3\u4e0b\u89d2\uff1b\u5b57\u578b\u8bbe\u4e3a'normal'\u8868\u793a\u6b63\u5e38\u3001'bold'\u8868\u793a\u7c97\u4f53\u3001'italic'\u8868\u793a\u659c\u4f53\u3001'underline'\u8868\u793a\u52a0\u4e0b\u5212\u7ebf\u7b49\u3002<\/p>\n

\u7531\u4e8e\u540c\u5b57\u4f53\u540c\u5b57\u53f7\u7684\u6c49\u5b57\u7684\u5bbd\u5ea6\u662f\u76f8\u540c\u7684\uff0c\u6240\u4ee5\u53ea\u8981\u5b57\u4e0e\u5b57\u4e4b\u95f4\u52a0\u5165\u6362\u884c\u7b26(\\n)\u7528write()\u65b9\u6cd5\u663e\u793a\u8f93\u51fa\u65f6\u5c31\u4f1a\u663e\u793a\u5728\u540c\u4e00\u5217\u4e0a\u3002<\/p>\n

str = '\u8fd9\u662f\u4e2a\u6d4b\u8bd5'<\/p>\n

str = '\\n'.join(list(str))<\/p>\n

write(str, font=('\u6c49\u4eea\u884c\u6977\u7e41', 36))<\/p>\n

\"Python<\/p>\n

\u56fe<\/strong>2 \u6587\u5b57\u7ad6\u6392\u6548\u679c\u56fe<\/strong> <\/p>\n

\u56db\u3001\u5236\u4f5c\u4e66\u6cd5\u4f5c\u54c1\u300a\u9e1f\u9e23\u6da7\u300b<\/strong><\/p>\n

\u5510\u738b\u7ef4\u300a\u9e1f\u9e23\u6da7\u300b\u8bd7\u4e3a\u4e94\u8a00\u56db\u53e5\uff1a<\/p>\n

\u4eba\u95f2\u6842\u82b1\u843d\uff0c\u591c\u9759\u6625\u5c71\u7a7a\u3002<\/p>\n

\u6708\u51fa\u60ca\u5c71\u9e1f\uff0c\u65f6\u9e23\u6625\u6da7\u4e2d\u3002<\/p>\n

\u7ad6\u6392\u57fa\u672c\u4e0a\u5448\u65b9\u5f62\uff0c\u7528\u201c\u56e2\u6247\u201d\u683c\u5f0f\u8868\u8fbe\u6bd4\u8f83\u5408\u9002\u3002\u5148\u7ed8\u5236\u5706\u5f62\u201c\u56e2\u6247\u201d\uff0c\u518d\u5728\u5176\u4e0a\u4ece\u53f3\u5230\u5de6\u4e66\u5199\u300a\u9e1f\u9e23\u6da7\u300b\u56db\u540d\u8bd7\uff0c\u5728\u5de6\u4fa7\u6dfb\u52a0\u843d\u6b3e\u548c\u5370\u7ae0\u3002<\/p>\n

\u5b8c\u6574\u7684\u5236\u4f5c\u7a0b\u5e8f\u5982\u4e0b\uff1a<\/p>\n

############################################\n# \u8bbe\u8ba1 Zhang Ruilin  \u521b\u5efa 2021-12-15 07:26 #\n# Python\u7528turtle\u5236\u4f5c\u4e66\u6cd5\u4f5c\u54c1\u2014\u2014\u300a\u9e1f\u9e23\u6da7\u300b #\n# \u8981\u8fd0\u884c\u672c\u7a0b\u5e8f\u5e76\u4ea7\u751f\u4e66\u6cd5\u6548\u679c\uff0c\u60a8\u7684\u7535\u8111\u9700\u8981 #\n# \u5b89\u88c5\u5370\u7ae0\u7bc6\u4f53\u3001\u65b9\u6b63\u5c0f\u7bc6\u4f53\u548c\u6c49\u4eea\u884c\u6977\u7e41\u5b57\u4f53 #\n############################################\nimport turtle as tl\n\ntl.setup(600,600)\ntl.bgcolor('ivory')\t\t\t\t# \u8c61\u7259\u8272\uff0c\u4f5c\u54c1\u88c5\u88f1\u8272\nbgcolor = 'wheat'\t\t\t\t# \u5c0f\u9ea6\u8272\uff0c\u4f5c\u54c1\u80cc\u666f\u8272\ntl.dot(550, bgcolor)\n\ndef downwards(_str,_font,_size=45):\t\t# \u6587\u5b57\u8f6c\u7ad6\u6392\uff0c\u4ece\u4e0a\u5411\u4e0b\u663e\u793a\n    _words = list(_str)\t\t\t\t# \u5b57\u7b26\u8f6c\u5217\u8868\n    _str = '\\n'.join(_words)\t\t\t# \u5217\u8868\u8fde\u63a5\u6210\u5b57\u7b26\u4e32\n    tl.write(_str,font=(_font,_size,'normal'))\t# \u7ad6\u6392\u663e\u793a\u8f93\u51fa\n\ndef yin(_word='red',_back='white'):\t\t\t\t# \u7ed8\u5236\u5370\u7ae0\uff0c_word\u5370\u7ae0\u989c\u8272\uff0c\n    tl.pensize(1)\t\t\t\t# _back\u5370\u7ae0\u80cc\u666f\u8272\uff0c\u63a7\u5236_word\n    tl.color(_word,_back)\t\t\t# \u548c_back\u53ef\u4ea7\u751f\u9633\u523b\u548c\u9634\u523b\u6548\u679c\n    tl.begin_fill()\n    tl.rt(45)\n    tl.pd()\n    tl.circle(20,steps=4)\n    tl.end_fill()\n    tl.lt(45)\n    tl.fd(3)\n    tl.write('\u745e\\n\u6797',font=('\u5370\u7ae0\u7bc6\u4f53',10,'normal'))\n    tl.fd(13)\n    tl.write('\u5f20\\n\u5370',font=('\u5370\u7ae0\u7bc6\u4f53',10,'normal'))\n    tl.pu()\n\nif __name__ == '__main__':\n    tl.pu()\n    tl.goto(150,-160)\n    downwards('\u4eba\u95f2\u6842\u82b1\u843d','\u65b9\u6b63\u5c0f\u7bc6\u4f53',45)\n    tl.goto(70,-160)\n    downwards('\u591c\u9759\u6625\u5c71\u7a7a','\u65b9\u6b63\u5c0f\u7bc6\u4f53',45)\n    tl.goto(-10,-160)\n    downwards('\u6708\u51fa\u60ca\u5c71\u9e1f','\u65b9\u6b63\u5c0f\u7bc6\u4f53',45)\n    tl.goto(-90,-160)\n    downwards('\u65f6\u9e23\u6625\u6da7\u4e2d','\u65b9\u6b63\u5c0f\u7bc6\u4f53',45)\n\n    tl.goto(-150,-100)\n    downwards('\u9e1f\u9e23\u6da7\u8bd7 \u5510\u738b\u7ef4','\u6c49\u4eea\u884c\u6977\u7e41',15)\n    tl.goto(-180,-150)\n    downwards('\u8f9b\u4e11\u5e74\u51ac\u6708\u745e\u6797\u5236\u4f5c\u4e8e\u676d\u5dde','\u6c49\u4eea\u884c\u6977\u7e41',15)\n    tl.goto(-155,-135)\n    yin('red',bgcolor)\n    tl.goto(-155,-170)\n    yin(bgcolor,'red')\n    tl.ht()\ntl.done()<\/code><\/pre>\n<\/p>\n

\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n

\"Python<\/p>\n

\u56fe<\/strong>3 \u7531\u4e0a\u8ff0\u7a0b\u5e8f\u751f\u6210\u7684\u4e66\u6cd5\u4f5c\u54c1\u300a\u9e1f\u9e23\u6da7\u300b<\/strong> <\/p>\n

\u5f53\u53e5\u5b50\u6bd4\u8f83\u957f\u65f6\uff0c\u53ef\u4ee5\u5e03\u5c40\u4e3a\u6979\u8054\u683c\u5f0f\uff0c\u5982\u56fe4\u6240\u793a\u3002<\/p>\n

\"Python<\/p>\n

\u56fe4 \u4e66\u6cd5\u4f5c\u54c1\u300a\u6613\u7ecf\u7b2c\u4e00\u5366\u300b<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"Python turtle\u5236\u4f5c\u4e66\u6cd5\u4f5c\u54c1\u2014\u2014\u300a\u9e1f\u9e23\u6da7\u300b\u672c\u7bc7\u4ee5\u5510\u738b\u7ef4\u8bd7\u4f5c\u300a\u9e1f\u9e23\u6da7\u300b\u4e3a\u4f8b\uff0c\u4ecb\u7ecdPython\u7528turtle\u5236\u4f5c\u4e66\u6cd5\u4f5c\u54c1","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\/7330"}],"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=7330"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7330\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}