资源描述:
《VPython_Intro》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、VPythonIntroduction11OverviewVPythonisaprogramminglanguagethatiseasytolearnandiswellsuitedtocreating3Dinteractivemodelsofphysicalsystems.VPythonhasthreecomponentsthatyouwilldealwithdirectly:•Python,aprogramminglanguageinventedin1990byGuidovanRossem,aDutchcomputerscienti
2、st.Pythonisamodern,object-orientedlanguagewhichiseasytolearn.•Visual,a3DgraphicsmoduleforPythoncreatedbyDavidSchererwhilehewasastudentatCarnegieMellonUniversity.Visualallowsyoutocreateandanimate3Dobjects,andtonavigatearoundina3Dscenebyspinningandzooming,usingthemouse.•I
3、DLE,aninteractiveeditingenvironment,writtenbyvanRossemandmodifiedbyScherer,whichallowsyoutoentercomputercode,tryyourprogram,andgetinformationaboutyourprogram.IDLEiscurrentlynotavail-ableonpre-OSXMacintosh.ThistutorialassumesthatPythonandVisualareinstalledonthecomputeryo
4、uareusing.2SpinningandZooming>StartIDLEbydouble-clickingonthesnakeicononyourdesktop.Awindowlabeled“Untitled”shouldappear.PickOpenontheFilemenuandchoosetheprogramrandombox.py.PressF5torunthisprogram.(OnLinuxorMacintoshOSX,typevisual-demosinatypescripttostartIDLEinthedemo
5、folder.Onpre-OSXMacintosh,dragtheprogramrandombox.pyontoPythonInterpreter)Holddowntherightmousebutton(shiftkeyonMacintosh)anddragthemousetospinthe“camera”aroundthescene.Holddownthemiddlemousebutton(left+rightbuttonsonatwo-buttonmouse;controlkeyonMacintosh)anddragthemous
6、etozoomintoandoutofthescene.ThesenavigationtoolsarebuiltintoallVPythonprogramsunlessspecificallydisabledbytheauthoroftheprogram.>ClosealltheVPythonwindowstostartover.3YourFirstProgram>StartIDLEbydouble-clickingonthesnakeicononyourdesktop.Awindowlabeled“Untitled”shouldap
7、pear.Thisisthewindowinwhichyouwilltypeyourprogram.(Onpre-OSXMacintosh,useaneditorofyourchoice.)(OnLinuxorMacintoshOSX,typeidleinatypescripttostartIDLEinthecurrentfolder.)>Asthefirstlineofyourprogram,typethefollowingstatement:fromvisualimport*ThisstatementinstructsPython
8、tousetheVisualgraphicsmodule.>Asthesecondlineofyourprogram,typethefollowingstatement:sphere()4RunningtheProgra