Python編寫萬花尺圖案實例
更新時間:2021年01月03日 10:11:35 作者:zhimaHTTP
在本篇文章里小編給大家分享的是一篇關于Python編寫萬花尺圖案實例的內(nèi)容,有興趣的朋友們可以參考下。
小的時候大家應該都玩過萬花尺,將筆尖放置萬花尺內(nèi)不停的轉動,便可以畫出一幅精致的線稿圖,現(xiàn)在我們不用萬花尺,我們通過Python也能繪制出萬花尺圖案。
(一)代碼
#!/usr/bin/python# -*- coding: UTF-8 - *-
import mathclass 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()
(二)實現(xiàn)結果

我們還可以通過修改不同的參數(shù)來實現(xiàn)不同的圖案轉化,大家可以多試試,做出多種不同的效果圖。
到此這篇關于Python編寫萬花尺圖案實例的文章就介紹到這了,更多相關Python之萬花尺圖案內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Python使用QQ郵箱發(fā)送郵件報錯smtplib.SMTPAuthenticationError
這篇文章主要介紹了Python使用QQ郵箱發(fā)送郵件報錯smtplib.SMTPAuthenticationError,簡單介紹了python 發(fā)送郵件的步驟,需要的朋友可以參考下2019-12-12
Python實現(xiàn)清理微信僵尸粉功能示例【基于itchat模塊】
這篇文章主要介紹了Python實現(xiàn)清理微信僵尸粉功能,結合實例形式分析了Python使用itchat模塊刪除微信僵尸粉的相關原理、操作技巧與注意事項,需要的朋友可以參考下2020-05-05

