Python Tinkering a little bit with Vpython.

  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    Bit
AI Thread Summary
To create a simulation of an inflated ball in VPython that gradually inflates over time, a timer can be added to control the rate of inflation. The initial code provided defines a sphere and increases its radius in a loop, but lacks timing functionality. To implement timing, the suggestion is to use the `rate()` function, which limits the number of iterations per second. For instance, incorporating `rate(100)` at the beginning of the while loop will allow the simulation to run at a maximum of 100 iterations per second, effectively controlling the inflation speed. This adjustment will enable the ball to inflate gradually, as desired.
MathematicalPhysicist
Science Advisor
Gold Member
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.
 
Technology 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).
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
13
Views
7K
Replies
1
Views
2K
Replies
1
Views
4K
Replies
2
Views
3K
Replies
30
Views
6K
Replies
10
Views
3K
Replies
4
Views
5K
Replies
1
Views
1K
Back
Top