Tinkering a little bit with Vpython.

  • Context: Python 
  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    Bit
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
Messages
4,662
Reaction score
372
I thought to write a naive simulation of an inflated ball, I am not sure how to implement this by Vpython.

I mean I want to see it gradually inflating minute by minute.

This is the code I wrote but I don't know how to add to it a timer.
Code:
from visual import *
ball=sphere(pos=vector(4,7,3),radius=2,color=color.green)
x=1
while x<50:
 ball.radius=ball.radius+x
 x=x+1
can anyone give me hint as to how to add a timing to this inflation?

Thanks.
 
Physics news on Phys.org
MathematicalPhysicist said:
I thought to write a naive simulation of an inflated ball, I am not sure how to implement this by Vpython.

I mean I want to see it gradually inflating minute by minute.

This is the code I wrote but I don't know how to add to it a timer.
Code:
from visual import *
ball=sphere(pos=vector(4,7,3),radius=2,color=color.green)
x=1
while x<50:
 ball.radius=ball.radius+x
 x=x+1
can anyone give me hint as to how to add a timing to this inflation?

Thanks.

I have no experience with python per se, but if your code is in some kind of loop, you could just add a sleep command in there somewhere. Basically calculate your rate and put your rate as your parameter in the sleep command.
 
MathematicalPhysicist said:
I thought to write a naive simulation of an inflated ball, I am not sure how to implement this by Vpython.

I mean I want to see it gradually inflating minute by minute.

This is the code I wrote but I don't know how to add to it a timer.
Code:
from visual import *
ball=sphere(pos=vector(4,7,3),radius=2,color=color.green)
x=1
while x<50:
 ball.radius=ball.radius+x
 x=x+1
can anyone give me hint as to how to add a timing to this inflation?

Thanks.

Interesting, never heard of VPython before. That said, I popped over to the VPython website and noticed a bouncing ball example there:

http://www.vpython.org/contents/bounce_example.html

What you're looking for seems to be rate(100), where 100 is the maximum loop iterations per second on a fast machine (so it could be less, of course). I think it may need to be right after the while statement as the first thing in the while's block (not sure, but that makes sense).