NLA in Tkinter 证明版0.1.1
作者:互联网
- 修改动画细节
- 修改图表绘制细节
import time import tkinter as tk import tkinter.ttk as ttk from pyecharts.charts import * from pyecharts import options as opts def play(sec): global pg,pgl print('====================') pg['value']=0 pgl['value']=0 x=0 xs=[] spd=0.0001 spds=[] sspd=0 sspds=[] for i in range(1,50+1): print('----------(帧数'+str(i)+'/50)') print('速度:'+str(spd)) print('速度增加值(sspd):'+str(sspd)) print('位置:'+str(x)) x+=spd if i<=15: spd+=sspd+0.00001 sspd+=0.025 elif i>=35: spd-=sspd-0.001 sspd-=0.02 if spd<=0.00001: spd=0 print('此帧不移动') pg['value']=x pgl['value']+=2 win.update() xs.append(x) spds.append(spd) sspds.append(sspd) time.sleep(sec) #绘折线图 linex=Line(init_opts=opts.InitOpts(page_title='NLA in Tkinter | Position Graph',width='1800px',height='800px')) linex.add_xaxis(range(1,50)) linex.add_yaxis('Position',xs,label_opts=opts.LabelOpts(is_show=False)) linex.set_global_opts(title_opts=opts.TitleOpts(title='NLA in Tkinter',subtitle='Graph of Frames and Values'),toolbox_opts=opts.ToolboxOpts(is_show=True),datazoom_opts=opts.DataZoomOpts(is_show=True,range_start=0,range_end=100)) linex.render("Position.html") linespd=Line(init_opts=opts.InitOpts(page_title='NLA in Tkinter | Speed Graph',width='1800px',height='800px')) linespd.add_xaxis(range(1,50)) linespd.add_yaxis('Speed',spds,label_opts=opts.LabelOpts(is_show=False)) linespd.add_yaxis('SSPD',sspds,label_opts=opts.LabelOpts(is_show=False)) linespd.set_global_opts(title_opts=opts.TitleOpts(title='NLA in Tkinter',subtitle='Graph of Frames and Speed, SSPD'),toolbox_opts=opts.ToolboxOpts(is_show=True),datazoom_opts=opts.DataZoomOpts(is_show=True,range_start=0,range_end=100)) linespd.render("Speed.html") def playnos(sec): global pg,pgl print('====================') pg['value']=0 pgl['value']=0 x=0 xs=[] spd=5 spds=[] sspd=0.5 sspds=[] for i in range(0,50+1): print('----------(帧数'+str(i)+'/50)') print('速度:'+str(spd)) print('速度增加值(sspd):'+str(sspd)) print('位置:'+str(x)) x+=spd if i>=5: spd-=sspd-0.001 sspd-=0.025 if spd<=0.001: spd=0 print('此帧不移动') elif sspd<=0: sspd=0 spd=0 print('此帧不变速且不移动') pg['value']=x*1.3 pgl['value']+=2 win.update() xs.append(x) spds.append(spd) sspds.append(sspd) time.sleep(sec) #绘折线图 linex=Line(init_opts=opts.InitOpts(page_title='NLA in Tkinter | Position Graph',width='1800px',height='800px')) linex.add_xaxis(range(1,50)) linex.add_yaxis('Position',xs,label_opts=opts.LabelOpts(is_show=False)) linex.set_global_opts(title_opts=opts.TitleOpts(title='NLA in Tkinter',subtitle='Graph of Frames and Values'),toolbox_opts=opts.ToolboxOpts(is_show=True),datazoom_opts=opts.DataZoomOpts(is_show=True,range_start=0,range_end=100)) linex.render("Position.html") linespd=Line(init_opts=opts.InitOpts(page_title='NLA in Tkinter | Speed Graph',width='1800px',height='800px')) linespd.add_xaxis(range(1,50)) linespd.add_yaxis('Speed',spds,label_opts=opts.LabelOpts(is_show=False)) linespd.add_yaxis('SSPD',sspds,label_opts=opts.LabelOpts(is_show=False)) linespd.set_global_opts(title_opts=opts.TitleOpts(title='NLA in Tkinter',subtitle='Graph of Frames and Speed, SSPD'),toolbox_opts=opts.ToolboxOpts(is_show=True),datazoom_opts=opts.DataZoomOpts(is_show=True,range_start=0,range_end=100)) linespd.render("Speed.html") win=tk.Tk() win.title('非线性动画测试') tk.Label(win,text='非线性动画测试',font=('微软雅黑',25)).pack(fill=tk.X) tk.Label(win,text='非线性',font=('微软雅黑')).pack(fill=tk.X) pg=ttk.Progressbar(win) pg.pack(fill=tk.X) tk.Label(win,text='线性对比(可视作进度条)',font=('微软雅黑')).pack(fill=tk.X) pgl=ttk.Progressbar(win) pgl.pack(fill=tk.X) tk.Label(win,text='每帧间隔(秒)',font=('微软雅黑')).pack(fill=tk.X) wtenter=ttk.Entry(win) wtenter.pack(fill=tk.X) wtenter.insert(tk.END,'0.05') ttk.Button(win,text='开始 >>',command=lambda:play(float(wtenter.get()))).pack(fill=tk.X) ttk.Button(win,text='开始(无起始加速) >>',command=lambda:playnos(float(wtenter.get()))).pack(fill=tk.X) #自动大小 win.update() win.minsize(350,win.winfo_height()) win.mainloop()
标签:Tkinter,0.1,win,sspd,NLA,str,print,import,spd 来源: https://www.cnblogs.com/TotoWang/p/nla_in_tk_prove_011.html