From: Bruce S. <Bru...@nc...> - 2014-11-30 02:46:53
|
See comments added to code. from __future__ import division, print_function # should import future print_function, so that print(....) works the same in Python 2 and Python 3 from visual import* # this imports all of the math library #from math import e #import math scene.title='Simple Electric motor simulation' scene.width = 1000 scene.height = 500 scene.autoscale = 0 scene.range = (35,35,35) scene.center = (12,0,0) # not sure what you are trying to achieve; would make more sense to place the object at (0,0,0) scene.background = (.5,0.5,2) # I suspect you want this color as a background, not as a box # None of these variables are used, so they're commented out for clarity: #area=box(pos=(12,0,14),length=400,height=400,width=400,material=materials.plastic,color=(.5,0.5,2)) #fcharge=1.6e-19 #pweight=1.67e-11 #count=0 #mfrm=frame(axis=(350,5,10)) #Motor Frame #rfrm=frame(frame=mfrm) #Rotor Frame #Electric motor-Jon's battery=frame() # not clear why a frame is used here; it plays no role cylinder(frame=battery,pos=(0,0,10),axis=(0,0,.2),radius=1.5,color=color.blue,material=materials.emissive) cylinder(frame=battery,pos=(0,0,10.2),axis=(0,0,7.8),radius=1.5,color=(0.5,0.5,0.2)) cylinder(frame=battery,pos=(0,0,12),axis=(0,0,7),radius=.75,color=color.red,material=materials.emissive) #wire-Mine wire=curve(pos=[(0,-6.5,20), (0,0,20), (0,0,8.5),(0,-6.5,8.5)], radius=0.25) #Magnet of motor-Mine floor1 = box (pos=(0,-1.75,14), length=2, height=0.5, width=6, color=color.red) floor2 = box (pos=(0,-2.25,14), length=2, height=0.5, width=6, color=color.blue) #Rotor stucture-Mine # Add Ring and Rod # The armature coil (ring) rotor = frame(pos=(0,-6,14)) # set up a frame for the rotating parts, and in the loop just rotate the frame #ring(pos=(0,-6,14),axis=(350,5,10), radius=1.75, thickness=0.5,color=(1,0.5,0.3),material=materials.blazed) #rod1=cylinder(pos=(0,-6,8.5),length=11.5,axis=(0,0.5,100),radius=0.45,color=(1,0.5,0.3), material=materials.blazed) ring(frame=rotor, radius=1.75, thickness=0.5,color=(1,0.5,0.3),material=materials.blazed) rod1=cylinder(frame=rotor, pos=(0,0,-11.5/2), length=11.5, axis=(0,0,1), radius=0.45,color=(1,0.5,0.3), material=materials.blazed) #labeling of program-Mine label1=label(pos=(0,0,10.2), text='Battery', xoffset=17, yoffset=17) label2=label(pos=(0,-6,10), text='Armature', xoffset=47, yoffset=47) dtheta = 0.05 while True: rate(100) rotor.rotate(angle=dtheta, axis=(0,0,1)) print('end of simulation') |