Python 练习实例65
python 练习实例65
题目:一个最优美的图案。
程序分析:无。
程序源代码:
#!/usr/bin/python # -*- coding: utf-8 -*- import math class 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()
以上实例输出结果为: