In my 9 Axis IMU Lessons the following code is used to demonstrate a moving graphic. I can see where the lectures are going where we move ‘objects’ by the value read from the serial port. My issue the code in the lectures isn’t working for me.
This code below is from part of the lectures:
from vpython import *
import time
y=cylinder(length=6,radius=0.5,color=color.yellow)
y.pos=vector(-3,0,0)
j=0
change=0.5
while True:
rate(20)
j=j+change
y.length=j
if(j==10):
change=-0.2
if(j==1):
change=0.2
I’ve created a cylinder successfully using this code
from vpython import *
import time
myCylinder = cylinder(pos=vector(-3,0,0), axis=vector(0,0,0),size=vector(6,0.5,0.5))
So, my thought process was this, to get it working dynamically:
replace size=vector(6,0.5,0.5) with size=vector(j,0.5,0.5) but the code throws up something unexpected when I run vpython
from vpython import *
import time
j=0
#y.pos=vector(-3,0,0)
change=0.5
while True:
rate(20)
myCylinder = cylinder(pos=vector(-3,0,0), axis=vector(0,0,0),size=vector(j,0.5,0.5))
j=j+change
#y.length=j
if(j==10):
change=-0.2
if(j==1):
change=0.2
Any help greatly appreciated for a newbie.