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()

相关文章
|
3天前
|
Python
Python 练习实例94
Python 练习实例94
|
5天前
|
数据可视化 Python
Python绘制基频曲线——实例解析与应用探讨
Python绘制基频曲线——实例解析与应用探讨
30 9
|
3天前
|
Python
Python 练习实例92
Python 练习实例92
|
3天前
|
Python
Python 练习实例93
Python 练习实例93
|
2天前
|
Python
Python 练习实例97
Python 练习实例97
|
2天前
|
Python
Python 练习实例96
Python 练习实例96
|
5天前
|
Python
Python 练习实例86
Python 练习实例86
|
4天前
|
Python
Python 练习实例90
Python 练习实例90
|
4天前
|
数据安全/隐私保护 Python
Python 练习实例89
Python 练习实例89
|
5天前
|
Python
Python 练习实例87
Python 练习实例87