VPython has a LOT of 3D objects that you can create, each with their own set of attributes that define their shape or other aspects. For instance, you can create an arrow, cone, curve, points and helix, to name a few.
To access the value of an attribute <attr> of a VPython object vp_obj of type <VPythonObject>, you just need to use vp_obj.<attr>. The attributes in VPython can also be included while instantiating the object in the first place, in the form of vp_obj = <VPythonObject>(<attr>=attr).
A specific example is:
bob = sphere(pos=vector(0,1,1), color=color.cyan).
The ones we use in the Newton’s cradle are a sphere, cylinder and box. Here are a list of useful attributes for these objects!
sphere
- pos (vector) – Position of center. Default
vector(0,0,0). - radius (scalar) – Default
1.0. - color (vector) – Default
color.white. There’s a lot of cool stuff you can do with the color, including using RGB codes and HSV (hue, saturation, and value) codes, which you can learn about here. - size (vector) – Dimensions of a box surrounding the sphere. Default
vector(2,2,2). This can be edited to even make the sphere more like an ellipsoid. - axis (vector) – Default
vector(1,0,0). This is the stored orientation of the object.
box
- pos (vector) – Position of center. Default
vector(0,0,0). - axis (vector) – Extends from left to right end. Default
vector(1,0,0). - color (vector) – Default
color.white. - length (scalar) – Length of box. Default
1.0. - height (scalar) – Height of box. Default
1.0. - width (scalar) – Width of box. Default
1.0. - size (vector) – Length, width, and height in one vector. An alternative to (length, height, width).
cylinder
- pos (vector) – Position of left end. Default
vector(0,0,0). - axis (vector) – Extends from pos to end. Default
vector(1,0,0). - color (vector) – Default
color.white. - radius – Radius of the cylinder. Default is
1.0. - length (scalar) – Length of axis. Setting length sets magnitude of axis. Default is
1.0. - size (vector) – Length, height, width of a box surrounding the cylinder, which is stored as a tuple with 3 elements. Default is
vector(1,1,1).
Additionally, all of the aforementioned objects have the following attributes too:
- opacity (scalar) – Default
1.0. Anopacity=0means the object is completely transparent;opacity=1means the object is completely opaque. - shininess (scalar) – Default
0.6; Range0-1. - emissive (boolean) – Default
False. Object glows, losing all shading, ifTrue. - texture (class element or path) – Default
None. Textures are stored as image files (which means you can also use your own images as textures if you link it correctly!). You can learn a lot more about the things you can do with textures here. - visible (boolean) – If
False, object is not displayed. Default:True. - canvas (object) – This is where the object appears. Default is
scene. - make_trail (boolean) – If
True, object leaves a trail as it is moved. - up (vector) – A vector perpendicular to the axis.
References:
- https://www.glowscript.org/docs/VPythonDocs/objects.html
