Python编写万花尺图案实例
作者:zhimaHTTP 时间:2022-04-16 06:12:21
小的时候大家应该都玩过万花尺,将笔尖放置万花尺内不停的转动,便可以画出一幅精致的线稿图,现在我们不用万花尺,我们通过Python也能绘制出万花尺图案。
(一)代码
#!/usr/bin/python# -*- coding: UTF-8 - *-
import mathclass PTS:
def __ init __(self):
self.x = 0
self.y = 0
points = []
def LineToDemo():
from Tkinter import *
screenx = 400
screeny = 400
canvas = Canvas(width = screenx,height = screeny,bg = ‘white')
AspectRatio = 0.85
MAXPTS = 15
h = screeny
w = screenx
xcenter = w / 2
ycenter = h / 2
radius = (h - 30) / (AspectRatio * 2) - 20
step = 360 / MAXPTS
angle = 0.0
for i in range(MAXPTS):
rads = angle * math.pi / 180.0
p = PTS()
p.x = xcenter + int(math.cos(rads) * radius)
p.y = ycenter - int(math.sin(rads) * radius * AspectRatio)
angle += step
points.append(p)
canvas.create_oval(xcenter - radius,ycenter - radius,
xcenter + radius,ycenter + radius)
for i in range(MAXPTS):
for j in range(i,MAXPTS):
canvas.create_line(points[i].x,points[i].y,points[j].x,points[j].y)
canvas.pack()
mainloop()if __name__ == '__main__':
LineToDemo()
(二)实现结果
我们还可以通过修改不同的参数来实现不同的图案转化,大家可以多试试,做出多种不同的效果图。
来源:https://blog.csdn.net/zhimaHTTP/article/details/111406131
标签:Python,万花尺
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中os模块的12种用法总结
2023-12-01 07:16:28
![](https://img.aspxhome.com/file/2023/4/79734_0s.png)
Python自动化办公之Excel拆分与自动发邮件
2022-05-03 09:05:40
![](https://img.aspxhome.com/file/2023/4/93464_0s.png)
使用CSS选择器创建个性化链接样式
2009-06-02 13:07:00
![](https://img.aspxhome.com/file/UploadPic/up/2009060213205633.gif)
python利用dir函数查看类中所有成员函数示例代码
2021-02-17 19:06:23
![](https://img.aspxhome.com/file/2023/5/127785_0s.jpg)
关于“简单,可依赖”
2008-10-22 13:33:00
python绘制简单直方图的方法
2023-06-23 19:54:50
![](https://img.aspxhome.com/file/2023/3/89323_0s.jpg)
使用PHP获取当前url路径的函数以及服务器变量
2023-10-31 02:31:34
简单介绍Python中的floor()方法
2023-06-08 03:36:21
Pytorch实现WGAN用于动漫头像生成
2023-07-24 22:31:26
IE下float产生双倍margin
2007-12-26 12:29:00
![](https://img.aspxhome.com/file/UploadPic/200712/26/20071226123712415s.gif)
图解Python中浅拷贝copy()和深拷贝deepcopy()的区别
2021-12-09 21:09:39
![](https://img.aspxhome.com/file/2023/0/84970_0s.png)
asp远程网页数据采集常用函数代码
2008-10-31 12:44:00
python字符串,元组,列表,字典互转代码实例详解
2022-03-01 22:51:55
IE9四大渲染引擎模式
2010-04-20 16:57:00
![](https://img.aspxhome.com/file/UploadPic/20104/20/01-76s.jpg)
Python利用xlrd 与 xlwt 模块操作 Excel
2022-07-19 20:57:13
![](https://img.aspxhome.com/file/2023/8/103798_0s.webp)
使用layui 的layedit定义自己的toolbar方法
2023-08-24 16:21:43
如何使用SQL Mail收发和自动处理邮件?
2010-05-16 15:10:00
Pycharm快速安装OpenCV的详细操作步骤
2021-02-01 09:51:10
![](https://img.aspxhome.com/file/2023/2/128602_0s.jpg)
前端开发中的一些用户体验细节
2010-10-19 12:23:00
![](https://img.aspxhome.com/file/UploadPic/201010/19/01-17s.jpg)
教你轻松学会SQL Server记录轮班的技巧
2009-02-19 17:38:00