Tinkering a little bit with Vpython.

  • Thread starter MathematicalPhysicist
  • Start date
  • Tags
    Bit
In summary, the conversation was about implementing a simulation of an inflated ball using VPython and adding a timer to gradually inflate the ball minute by minute. The individual was unsure how to add a timer to their code and asked for hints. Another person suggested using a sleep command or the rate function in VPython to control the speed of the simulation.
  • #1
MathematicalPhysicist
Gold Member
4,699
371
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.
 
Technology news on Phys.org
  • #2
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.
 
  • #3
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).
 

1. What is Vpython?

Vpython is a free, open-source software library that allows for easy creation of 3D animations and simulations using the Python programming language. It is commonly used in the field of scientific computing and education.

2. How do I get started with Vpython?

To start tinkering with Vpython, you will need to download and install the software on your computer. You can find the installation instructions and necessary downloads on the official Vpython website.

3. What can I do with Vpython?

Vpython can be used to create 3D visualizations of scientific data, simulate physical phenomena, and create interactive animations and games. It is a versatile tool that can be used for a wide range of scientific and educational purposes.

4. Do I need to know programming to use Vpython?

While some basic knowledge of programming and Python syntax can be helpful, Vpython is designed to be easy to use for beginners. The official Vpython website offers tutorials and resources for users of all levels.

5. Can I use Vpython for research purposes?

Yes, Vpython is a powerful tool for conducting scientific research and visualizing complex data. Many researchers in various fields, such as physics, chemistry, and biology, use Vpython to create simulations and animations to aid in their research.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
13
Views
6K
  • Programming and Computer Science
Replies
30
Views
4K
  • Programming and Computer Science
Replies
2
Views
2K
  • Nuclear Engineering
Replies
2
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
5K
  • Special and General Relativity
Replies
6
Views
1K
Back
Top