Nugroho's blog.: September 2012

## Wednesday, September 19, 2012

### Simulate Circular Motion using Visual Python

This little code below show how to move an object in VPython. There’s two object in program, a box and a sphere. The latter object move in circular using simple sin and cos formula.

I set the angular speed 10 and radius of the motion (not the sphere) is 10. I use label to show sphere’s x and y position.

Here the result

Here the code

`from visual import *kotak = box(pos=vector(0, 0, 0), length=14, height=14, width=1, color = (0.7,0.7,0.7))ball=sphere(color=color.green,radius=5)ball.pos=vector(10,10,0)timestep = 0.05a=10t = .0omega= 10px = label(pos=(0,-1,0), text='x = %1.5f' % pi)py = label(pos=(0,+1,0), text='y = %1.5f' % pi)while (1==1):    rate(100)    ball.pos.x = a*sin(omega*t)    ball.pos.y = a*cos(omega*t)    px.text = 'x = %1.5f' % ball.pos.x    py.text = 'y = %1.5f' % ball.pos.y    t=t+0.01       `
323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)