In this lesson we show you the importance of building a parameterized model for your 3D graphics in Python using Visual Python. You can manage large scenes unless you are doing it with parameterized dimensions. The video above takes you through it step by step. Here is the code for the parameterized box and marble we developed in Lesson 3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | from vpython import * from time import * mRadius=.75 wallThickness=.1 roomWidth=10 roomDepth=5 roomHeight=10 floor=box(pos=vector(0,-roomHeight/2,0),size=vector(roomWidth,wallThickness,roomDepth), color=color.white) ceiling=box(pos=vector(0,roomHeight/2,0),size=vector(roomWidth,wallThickness,roomDepth), color=color.white) backWall=box(pos=vector(0,0,-roomDepth/2),size=vector(roomWidth,roomHeight,wallThickness), color=color.white) leftWall=box(pos=vector(-roomWidth/2,0,0),size=vector(wallThickness,roomHeight,roomDepth), color=color.white) rightWall=box(pos=vector(roomWidth/2,0,0),size=vector(wallThickness,roomHeight,roomDepth), color=color.white) marble=sphere(radius=mRadius,color=color.red) deltaX=.1 xPos=0 while True: rate(10) xPos=xPos+deltaX if (xPos>roomWidth/2 or xPos<-roomWidth/2): deltaX=deltaX*(-1) marble.pos=vector(xPos,0,0) |