1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
from vpython import * roomX=12 roomY=10 roomZ=16 wallT=.5 wallColor=vector(1,1,1) wallOpacity=.8 frontOpacity=.1 marbleR=.5 ballColor=vector(0,0,1) myFloor=box(size=vector(roomX,wallT,roomZ),pos=vector(0,-roomY/2,0),color=wallColor,opacity=wallOpacity) myCeiling=box(size=vector(roomX,wallT,roomZ),pos=vector(0,roomY/2,0),color=wallColor,opacity=wallOpacity) leftWall=box(size=vector(wallT,roomY,roomZ),pos=vector(-roomX/2,0,0),color=wallColor,opacity=wallOpacity) rightWall=box(size=vector(wallT,roomY,roomZ),pos=vector(roomX/2,0,0),color=wallColor,opacity=wallOpacity) backWall=box(size=vector(roomX,roomY,wallT),pos=vector(0,0,-roomZ/2),color=wallColor,opacity=wallOpacity) frontWall=box(size=vector(roomX,roomY,wallT),pos=vector(0,0,roomZ/2),color=wallColor,opacity=frontOpacity) marble=sphere(color=ballColor,radius=marbleR) marbleX=0 deltaX=.1 marbleY=0 deltaY=.1 marbleZ=0 deltaZ=.1 while True: rate(20) marbleX=marbleX+deltaX marbleY=marbleY+deltaY marbleZ=marbleZ+deltaZ if marbleX+marbleR>(roomX/2-wallT/2) or marbleX-marbleR<(-roomX/2+wallT/2): deltaX=deltaX*(-1) marbleX=marbleX+deltaX if marbleY+marbleR>(roomY/2-wallT/2) or marbleY-marbleR<(-roomY/2+wallT/2): deltaY=deltaY*(-1) marbleY=marbleY+deltaY if marbleZ+marbleR>(roomZ/2-wallT/2) or marbleZ-marbleR<(-roomZ/2+wallT/2): deltaZ=deltaZ*(-1) marbleZ=marbleZ+deltaZ marble.pos=vector(marbleX,marbleY,marbleZ) |