python进阶练习之——画组合图形❤️
Posted 肥学大师
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python进阶练习之——画组合图形❤️相关的知识,希望对你有一定的参考价值。
**题目:**一个最优美的图案。
import math
from tkinter import *
class PTS:
def __init__(self):
self.x = 0
self.y = 0
points = []
def LineToDemo():
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()
📣小白练手专栏,适合刚入手的新人欢迎订阅编程小白进阶
📣有什么不明白的欢迎私信或留言,得到细致讲解。另外想要进阶的朋友可以关注练手项目专栏
📣另外想学JavaWeb进厂的同学可以看看这个专栏:传送们
以上是关于python进阶练习之——画组合图形❤️的主要内容,如果未能解决你的问题,请参考以下文章