Skip to content

Instantly share code, notes, and snippets.

@twatteyne
Created April 4, 2014 06:36
Show Gist options
  • Save twatteyne/9969311 to your computer and use it in GitHub Desktop.
Save twatteyne/9969311 to your computer and use it in GitHub Desktop.
Dynamic VPython-based visualization of a vector
import random
import visual
MAXDIFF = 0.05
class ArrowCoords(object):
x = random.random()
y = random.random()
z = random.random()
def get(self):
self.x += -MAXDIFF/2+MAXDIFF*random.random()
self.y += -MAXDIFF/2+MAXDIFF*random.random()
self.z += -MAXDIFF/2+MAXDIFF*random.random()
return (self.x,self.y,self.z)
#============================ main ============================================
def main():
coords = ArrowCoords()
arr = visual.arrow(
pos = (0,0,0),
color = visual.color.green,
material = visual.materials.emissive,
)
while True:
visual.rate(100)
arr.axis = coords.get()
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment