开发者社区> 问答> 正文

一个最优美的图案如何画

一个最优美的图案如何画

展开
收起
珍宝珠 2019-11-19 17:11:47 2414 0
1 条回答
写回答
取消 提交回答
  • #!/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()
    
    

    以上实例输出结果为:

    image.png

    2019-11-19 17:12:14
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载