NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Collaborative Community of EJS => Topic started by: lookang on September 02, 2008, 10:51:27 am



Title: Physlets An attempt at bar magnet using physletbuilder java applet
Post by: lookang on September 02, 2008, 10:51:27 am
 name="AppletNames" value="Bfield">






Title: Re: An attempt at bar magnet using physletbuilder
Post by: Fu-Kwun Hwang on September 09, 2008, 02:32:38 pm
I copied the same code here:


 name="AppletNames" value="Bfield">



The javascript code is the following:
var timerID2=0;
function initApplets2(){
 clearTimeout(timerID2);
 loaded2=true;
 timerID2=setTimeout("init2()",100);
}
function init2(){
 fkh2=document.Bfield2;// define id for the physlet applet
 fkh2.setAutoRefresh(false);
 fkh2.setDefault();
 id=new Array(18);
 x1=0;
 id0=fkh2.addObject("coil","x=0.0,y=0.0,i=0,r=0.1");// no current, just for drag effect
 for(i=0;i<18;i++){
  param="x="+x1+",y=0,i=1,r=0.1";
  id[ i ]=fkh2.addObject("coil",param);
  x1+=0.02;
 }
 fkh2.setDragable(id0,true);
 fkh2.setAutoRefresh(true);
}

function movetodrag(){
 x2=fkh2.getXPos(id0);
 y2=fkh2.getYPos(id0);
 for(i=0;i<18;i++){
  fkh2.setXPos(id[ i ],x2);
  fkh2.setYPos(id[ i ],y2);
  x2+=0.02;
 }
}

And the button just call movetodrag()!