Python 练习实例65

[复制链接]
450|0
 楼主| cooldog123pp 发表于 2022-9-25 20:48 | 显示全部楼层 |阅读模式
题目:一个最优美的图案。  
程序分析:无。
程序源代码:
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-

  3. import math
  4. class PTS:
  5.     def __init__(self):
  6.         self.x = 0
  7.         self.y = 0
  8. points = []

  9. def LineToDemo():
  10.     from Tkinter import *
  11.     screenx = 400
  12.     screeny = 400
  13.     canvas = Canvas(width = screenx,height = screeny,bg = 'white')

  14.     AspectRatio = 0.85
  15.     MAXPTS = 15
  16.     h = screeny
  17.     w = screenx
  18.     xcenter = w / 2
  19.     ycenter = h / 2
  20.     radius = (h - 30) / (AspectRatio * 2) - 20
  21.     step = 360 / MAXPTS
  22.     angle = 0.0
  23.     for i in range(MAXPTS):
  24.         rads = angle * math.pi / 180.0
  25.         p = PTS()
  26.         p.x = xcenter + int(math.cos(rads) * radius)
  27.         p.y = ycenter - int(math.sin(rads) * radius * AspectRatio)
  28.         angle += step
  29.         points.append(p)
  30.     canvas.create_oval(xcenter - radius,ycenter - radius,
  31.                        xcenter + radius,ycenter + radius)
  32.     for i in range(MAXPTS):
  33.         for j in range(i,MAXPTS):
  34.             canvas.create_line(points[i].x,points[i].y,points[j].x,points[j].y)

  35.     canvas.pack()
  36.     mainloop()
  37. if __name__ == '__main__':
  38.     LineToDemo()
5572063304e0c90afe.png

您需要登录后才可以回帖 登录 | 注册

本版积分规则

2549

主题

8357

帖子

31

粉丝
快速回复 在线客服 返回列表 返回顶部
0