stop(); _quality="LOW"; /* Constants, variables, and other entities are registered here for later use in the script. */ _root.createEmptyMovieClip("lines",1); _root.createEmptyMovieClip("earth",2); _global.ea=_root["earth"]; _global.pt=_root["particle"]; _global.ops=_root["ops"]; _global.oops=_root["oops"]; ea._x=225; ea._y=225; ea.r=26; ea.k=.8; _global.sx=0; _global.sy=0; _global.ex=0; _global.ey=0; _global.vx=0; _global.vy=0; _global.vc=0; _global.gType=0; _global.fOn=0; _global.wOn=0; _global.paused=0; _global.drawing=0; treadout.text="Click and drag the mouse inside the field" +" to create a force vector."; _global.pi=Math.PI; /* Recall Particle: This function returns the satellite to the mouse coordinates, registers this point as an anchor, and begins the velocity vector line from there. */ _global.rPt = function(){ oops._x=sx; oops._y=sy; ops._x=sx; ops._y=sy; pt._x=sx; pt._y=sy; vx=0; vy=0; } /* Create Vector: This function completes the velocity vector and commits them to the real particle's properties. */ _global.cVt = function(){ _root["lines"].clear(); if(Key.isDown(32)){ dx=sx-ex; dy=sy-ey; } else { dx=ex-sx; dy=ey-sy; } treadout.text="Vector created. "; if(paused>0){treadout.text+="Unpause the game or click +1 or +10 to advance frames.";} vx=dx/25; vy=dy/25; } /* I don't know why this is called Frankie, but it is. No one reads my code. In any case, this just checks when the user presses or releases the left mouse button and invokes the proper functions. */ frankie=new Object(); Mouse.addListener(frankie); frankie.onMouseDown = function(){ if(_xmouse>=4 && _xmouse<=447 && _ymouse>=4 && _ymouse<=447){ drawing=1; sx=_root._xmouse; sy=_root._ymouse; rPt(); /* The text box should update each frame to show the position and vector of the particle during this period. */ } else if(_ymouse>=4 && _xmouse>=450 && _xmouse<=595 && _ymouse<=109){ if(_ymouse>=4 && _ymouse<=13){ gType=0; fgtype._y=9; treadout.text="Gravity select: Fg=0. This mode is "+ "used for systems with zero or negligible gravity."; } else if(_ymouse>=16 && _ymouse<=25){ gType=1; fgtype._y=21; treadout.text="Gravity select: Fg=k. This mode is "+ "often used for simulations of earth's surface."; } else if(_ymouse>=28 && _ymouse<=37){ gType=2; fgtype._y=33; treadout.text="Gravity select: Fg=k/r. This mode is "+ "technically inaccurate, but orbits easily."; } else if(_ymouse>=40 && _ymouse<=49){ gType=3; fgtype._y=45; treadout.text="Gravity select: Fg=k/r^2. This mode is "+ "based on the G.U.T. (Grand Unified Theory)."; } else if(_ymouse>=64 && _ymouse<=73){ fOn=1-fOn; rfon.gotoAndStop(fOn+1); treadout.text="Air friction is constant resistance to motion." +" Air friction is now "+((fOn>0)?"on.":"off."); } else if(_ymouse>=76 && _ymouse<=85){ wOn=1-wOn; rwon.gotoAndStop(wOn+1); treadout.text="Walls are static position limits." +" Walls are "+((wOn>0)?"on":"off")+" now."; } else if(_ymouse>=100 && _ymouse<=109){ if(_xmouse>=450 && _xmouse<=518){ paused=1-paused; rpaused.gotoAndStop(paused+1); treadout.text="The system is"+((paused>0)?" paused":" unpaused") +"; click +1 or +10 to advance frames."; } else if(_xmouse>=533 && _xmouse<=551){ paused=1; rpaused.gotoAndStop(2); cycle(1); treadout.text="The system is paused; advanced one frame."; } else if(_xmouse>=565){ paused=1; rpaused.gotoAndStop(2); cycle(10); treadout.text="The system is paused; advanced ten frames."; } else { treadout.text="Click and drag the mouse inside the field" +" to create a force vector."; } } } else { treadout.text="Click and drag the mouse inside the field" +" to create a force vector."; } } /* This part's a little tricky. I isolated all of the motion code for the particle and made it a function; it is called once per frame while the system is unpaused. If the user clicks the +1 button, this is invoked just once that frame. If the user clicks the +10 button, this function is invoked ten times and only the final result is rendered. Any number here would technically work. */ _global.cycle=function(iter){ for(i=0;i=445){pt._x=445;vx*=-.5;} if(pt._y>=445){pt._y=445;vy*=-.5;} } } } pt.onEnterFrame=function(){ /* If the user has clicked but not yet released the left mouse button, draw a line connecting the particle to the mouse. */ if(drawing){ ex=_root._xmouse; ey=_root._ymouse; _root["lines"].clear(); _root["lines"].lineStyle(1,0x000000,50); _root["lines"].moveTo(sx,sy); _root["lines"].lineTo(ex,ey); dir=Math.atan2(ey-sy,ex-sx)*180/pi; if(dir<0){dir+=360;} mag=Math.sqrt((ex-sx)*(ex-sx)+(ey-sy)*(ey-sy))/25; _root["treadout"].text="Creating vector: " +"<"+Math.round(mag)+", "+Math.round(dir)+"º>."; } else if(!paused){cycle(1);} } frankie.onMouseUp = function(){ if(drawing){cVt();drawing=0;} }