神奇画板效果模拟

import Image,ImageDraw,ImageFont,ImageTk,Tkinter,math,time

img=Image.new('RGB',(600,600))
draw = ImageDraw.Draw(img)


def drawcircles():
    a=90
    b=35
    c=0
    d=190
    e=300    
    t=0
    x=int(a*math.sin(b*t+c)+d*math.sin(t)+e)
    y=int(a*math.cos(b*t+c)+d*math.cos(t)+e)
    x0=x
    y0=y
    t+=0.01
    while t<300:
        x=int(a*math.sin(b*t+c)+d*math.sin(t)+e)
        y=int(a*math.cos(b*t+c)+d*math.cos(t)+e)
        col=int((math.sin(4*t)+1)*180)
        draw.line((x0,y0,x,y), fill="hsl(%d,100%%,50%%)"%(col))
        x0=x
        y0=y
        t+=0.01
        
tic=time.time()
drawcircles()
toc=time.time()-tic
draw.text((5,5), "%ds"%toc, fill=(155,155,155), font=ImageFont.truetype('simfang.ttf',22))
del draw
img.save("out.png")

def button_click_exit_mainloop (event):    
    event.widget.quit()
    
root = Tkinter.Tk()
root.bind("<Button>", button_click_exit_mainloop)
root.geometry('600x600')
tkpi = ImageTk.PhotoImage(file="out.png")
label_image = Tkinter.Label(root, image=tkpi)
label_image.pack()
root.mainloop()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值