赞
踩
我们使用科赫曲线来画画雪花,主要是无聊
过程很简单,理解思路就行
import turtle import time times=time.perf_counter() def koch(size,n): if n==0: turtle.fd(size) else: for angle in [0,60,-120,60]: turtle.left(angle) koch(size/3,n-1) def main(): global times turtle.setup(600,600) turtle.penup() turtle.goto(-200,100) turtle.pendown() turtle.pensize(2) level=4 # 这是是科赫曲线的数量 koch(400,level) turtle.rt(120) koch(400,level) turtle.rt(120) koch(400,level) turtle.hideturtle() print("画图所用时间时间{}秒!".format(time.perf_counter()-times)) turtle.done() main() print("程序运行时间{}秒!".format(time.perf_counter()-times)) input('按Enter关闭窗口!!!')
这里还使用了time库,用来计算程序运行的时间
最后可以把这个程序用pyinstaller打包成一个可执行的exe文件
这样就可以在没有python环境的电脑运行啦!!!
然后把它发送你们的朋友看看哈哈哈哈哈
先使用下面命令安装pyinstaller库
pip install pyinstaller
然后就可以打包python程序了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。