Nugroho's blog.: Update Visual.Graph Python

Pages

Friday, September 25, 2015

Update Visual.Graph Python

 The code below's from vpython example program, modified here and there, of course, :). It plots 5.0+5.0*cos(-0.2*t-p)*exp(0.015*t). Notice that p is act as phase, so the plot will 'walk'. The essential part is

 funct1.gcurve.pos=[]

 without it, the graph wont refresh the old curve (the old plot wouldn't be erased)



from __future__ import division, print_function
from visual import *
from visual.graph import *
import wx

L = 400
H = 200

w = window(width=2*(L+window.dwidth), height=L+window.dheight+window.menuheight+H,
menus=True, title='Widgets',
style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)

funct1 = gcurve(color=color.cyan)

p = 0.

while True:
rate(100)
funct1.gcurve.pos=[]
for t in arange(-30, 74, 1):
funct1.plot( pos=(t, 5.0+5.0*cos(-0.2*t-p)*exp(0.015*t)) )
p = p + 0.1
if p >100:
p = 0

.



.
 

No comments:

Post a Comment