Web VPython

Web VPython is an easy-to-use, powerful environment for creating 3D animations. You can also use VPython with installed Python: see vpython.org.

Helpful Web VPython resources:

Web VPython Example

Here is a quick example to help get you started.

Web VPython 3.2

canvas(caption="""Right button drag or Ctrl-drag to rotate "camera" to view scene.
Middle button or Alt-drag to drag up or down to zoom in or out.
  On a two-button mouse, middle is left + right.
Touch screen: pinch/extend to zoom, swipe or two-finger rotate.""")

side = 4.0
thk = 0.3
s2 = 2*side - thk
s3 = 2*side + thk

wallR = box (pos=vector( side, 0, 0), size=vector(thk, s2, s3),  color = color.red)
wallL = box (pos=vector(-side, 0, 0), size=vector(thk, s2, s3),  color = color.red)
wallB = box (pos=vector(0, -side, 0), size=vector(s3, thk, s3),  color = color.blue)
wallT = box (pos=vector(0,  side, 0), size=vector(s3, thk, s3),  color = color.blue)
wallBK = box(pos=vector(0, 0, -side), size=vector(s2, s2, thk), color = vector(0.7,0.7,0.7))

ball = sphere (color = color.green, radius = 0.4, make_trail=True, retain=200)
ball.mass = 1.0
ball.p = vector (-0.15, -0.23, +0.27)

side = side - thk*0.5 - ball.radius

dt = 0.3
while True:
  rate(200)
  ball.pos = ball.pos + (ball.p/ball.mass)*dt
  if not (side > ball.pos.x > -side):
    ball.p.x = -ball.p.x
  if not (side > ball.pos.y > -side):
    ball.p.y = -ball.p.y
  if not (side > ball.pos.z > -side):
    ball.p.z = -ball.p.z

1
2
GlowScript 3.1 VPython
#Adepted from Rhett Allain's Trinket
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Loading

This is a Monte Carlo simulation of radioactive decay

by Valentina Erastova, University of Edinburgh, Nov 2021

adapted from Rhett Allain's Trinket

A 2D material slab made of element X is composed from stable blue particles and radioactive red particles. Radioactive red decay into a new element Y, made of stable cyan particles.

The total amount of particles forming element X is 2000, N=2000 and 22.4% are radioactive nuclei, N2=0.224*N

The decay rate for the X -> Y is 1/5, r=1/5 i.e. a particle has 20% chance to decay over a given timeunit (=arbitrary unit of time).

We will simulate what happens over the 50 time units. t=0 tmax=50

For this we will run the calculation with a step of 2 timeunits,dt=2 to find out how many particles have undergone the decay after each step.

The results are then plotted on a graph, showing how a population of each element, X and Y, changes with time.


You can zoom in/out and rotate the material: Middle button or Alt-drag to drag up or down to zoom in or out. On a two-button mouse 'middle' is left + right. Mac touchpad: two-finger press and drag. Touch screen: pinch/extend to zoom, swipe or two-finger rotate.

Run your code first!

It looks like you haven't tried running your new code.

Try clicking  Run and if you like the result, try sharing again.

×