用python中的turtle库绘制一个好看的图案
程序中必须包含流程控制(循环)、组合数据类型(列表、元组、集合、字典)、自定义函数内容。代码不少于30行
如何用python中的turtle库绘制一个好看的图案程序中必须包含流程控制(循环)、组合数据类型(列表、元组、集合、字典)、自定义函数内容?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- CSDN专家-sinJack 2022-12-09 16:58关注
from turtle import Screen, Turtle, mainloop from time import perf_counter as clock, sleep def mn_eck(p, ne,sz): turtlelist = [p] #create ne-1 additional turtles for i in range(1,ne): q = p.clone() q.rt(360.0/ne) turtlelist.append(q) p = q for i in range(ne): c = abs(ne/2.0-i)/(ne*.7) # let those ne turtles make a step # in parallel: for t in turtlelist: t.rt(360./ne) t.pencolor(1-c,0,c) t.fd(sz) def main(): s = Screen() s.bgcolor("black") p=Turtle() p.speed(0) p.hideturtle() p.pencolor("red") p.pensize(3) s.tracer(36,0) at = clock() mn_eck(p, 36, 19) et = clock() z1 = et-at sleep(1) at = clock() while any(t.undobufferentries() for t in s.turtles()): for t in s.turtles(): t.undo() et = clock() return "runtime: %.3f sec" % (z1+et-at) if __name__ == '__main__': msg = main() print(msg) mainloop()
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 Llama如何调用shell或者Python
- ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
- ¥15 win10权限管理,限制普通用户使用删除功能
- ¥15 minnio内存占用过大,内存没被回收(Windows环境)
- ¥65 抖音咸鱼付款链接转码支付宝
- ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
- ¥15 blast算法(相关搜索:数据库)
- ¥15 请问有人会紧聚焦相关的matlab知识嘛?
- ¥15 网络通信安全解决方案
- ¥50 yalmip+Gurobi