VRML : Chemistry in VRML
Source code for example 10 : A H2O (water) molecule. Lone electron pair are not shown.


#VRML V1.0 ascii

Separator {

#Create the lights, camera and material as usuall

	DirectionalLight { direction 0 0 -1 }
	DirectionalLight { direction 0 -1 0 }
	PerspectiveCamera { 
		position 4 2 8
		orientation 0 1 0 0.4
	}
	Material {
		diffuseColor 1 0 0
		ambientColor 0.2 0  0
	}

#Create a red O atom at (0,0,0)

	Sphere { radius 1.3 }

#Create new material for H atoms

	Material {
		diffuseColor 1 1 1
		ambientColor 0.2 0.2 0.2
	}

#Create the first H atom at (4,0,0)

	Separator {
		Translation { translation 4 0 0 }
		Sphere { radius 0.7 }
	}

#This time rotate around z axis by 104.5 degrees,
#move out 4 units, and create second H atom

	Separator {
		Rotation { rotation 0 0 1 1.823869 }
		Translation { translation 4 0 0 }
		Sphere { radius 0.7 }
	}

#Create new material for bonds

	Material {
		diffuseColor 0 0 1
		ambientColor 0 0 0.2
	}

#Move to (2,0,0), rotate 90 degrees around the z 
#axis, and create a cylinder, representing the 
#bond between one of the H atoms and the O atom

	Separator {
		Translation { translation 2 0 0 }
		Rotation { rotation 0 0 1 1.570796 }
		Cylinder {
			height 4
			radius 0.3
			parts SIDES
		}
	}

#Create the second bond, which is a little more
#complicated, but uses the same general method,
#and one additional rotation

	Separator {
		Rotation { rotation 0 0 1 1.823869 }
		Translation { translation 2 0 0 }
		Rotation { rotation 0 0 1 1.570796 }
		Cylinder {
			height 4
			radius 0.3
			parts SIDES
		}
	}
}


#End of file




Previous Topic (Chemistry in VRML)
Back to the VRML Reference
Back to the Main Page

©Tom Thurston, 1997
Please feel free to use and redistribute this NONcommercially!