Re: Move a clock pulse train, please help

Bruce Sherwood <[email protected]> Fri, 19 Oct 2012 10:14:24 -0600
Newsgroups gmane.comp.python.visualpython.user
Message-ID <CAFDG03jhk32EV194oSfKUJjOHo=o6PJxQ18tDiChnjgWBa4N+w@mail.gmail.com>
That's a clever way to make a pulse train; I wouldn't have thought of
using the math ceil function. Here's one way to animate the pulse
train, moving to the right. I set the range to 9 so that the pulses
fill the screen. I move the display's center to the left until one
period has elapsed, when I reset the center to the origin:

from visual import *

g = []
g.append(display(x = 0, y = 100, width=1000, height=400, range=9))

g[0].title="Second try"

k = 5
T = 2*pi/k
c = curve( x = arange(-10,10,0.01),
        display=g[0],radius=0.07,color=color.yellow  ) # Draw a pulse train
c.y = ceil(sin( k*c.x ))

t = 0
dt = T/20
while True:
    rate(100)
    g[0].center.x -= dt
    t += dt
    if t >= T:
        g[0].center.x = 0
        t = 0

You might wish to disable userspin and userzoom to prevent the viewer
from messing up the display.

Just in case you hadn't noticed it, I'll comment that in your original
program you don't need a loop at the end to keep the display alive.
When you come to the end of a VPython program, the display remains on
the screen and you can zoom and rotate.

Bruce Sherwood

On Fri, Oct 19, 2012 at 9:39 AM, liming xiu <[email protected]> wrote:
> Hi,
>
> I am new to VPython. I want to use this tool to do a project for my work.
>
> I create a clock pulse train using the few lines below.
>
> ----------------------------------------------------
> from visual import *
>
> g = []
> g.append(display(x = 0, y = 100, width=1000, height=400))
>
> g[0].title="First try"
>
> c = curve( x = arange(-10,10,0.01),
> display=g[0],radius=0.07,color=color.yellow  ) # Draw a helix
> c.y = ceil(sin( 5.0*c.x ))
>
> while True:
>     rate(5)

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct