Water molecule.py

From GeoMod

Jump to: navigation, search

To run the code, once you have VPython installed, you can either.

  1. Download this file: water_molecule.py
  2. or, copy and paste the following code to a file (named "water_molecule.py" for example) using your favorite text editor.


from visual import *

class H2O:
    "water molecule"
    def __init__(self, p):
        self.f = frame(pos = p)
        dy = tan(52.25*pi/180)
        h = 1/(sin(52.25))
        self.O = sphere(radius = 1, pos=(0,0,0),color = (0,0,1), frame = self.f)
        self.H1 = sphere(radius = 0.5, pos=(-dy,1,0), color = (0,1,0), frame = self.f)
        self.H2 = sphere(radius = 0.5, pos=(dy,1,0), color = (0,1,0), frame = self.f)
        self.b1 = cylinder(radius = 0.1, pos = (0,0,0), axis=(-dy,1,0), color=(1,0,0))
        self.b1 = cylinder(radius = 0.1, pos = (0,0,0), axis=(dy,1,0), color=(1,0,0))
        self.plab = label(pos=(0,1.25,0),text="+", height =20)
        self.nlab = label(pos=(0,-1.25,0),text="-", height =20)
        self.Olab = label(pos=self.O.pos,text="O", height =40, opacity = 0, box=0)
        self.H1lab = label(pos=self.H1.pos,text="H", height =30, opacity = 0, box=0)
        self.H2lab = label(pos=self.H2.pos,text="H", height =30, opacity = 0, box=0)

scene.background = (1,1,1)
water = H2O(vector(0,0,0))

Personal tools