This is the web version of EJS interface
EJS version 4.1
  1. Author=Fu-Kwun Hwang - Dept. of Physics, National Taiwan Normal Univ.
  2. Abstract=hwang@phy.ntnu.edu.tw
  3. CaptureTools=true
  4. DataTools=true
  5. LanguageTools=true
    NameValueTypeDimension
    NameValueTypeDimension

    Init Page

    vxs=vys=xs=ys=0; size=range/N; Ms=0; for(int i=0;i<N;i++){ if(samesize)m[i]=1; else m[i]=Math.random(); x[i]=range*(Math.random()-0.5); y[i]=range*(Math.random()-0.5); vx[i]=2*Math.sqrt(E)*(Math.random()-0.5); vy[i]=2*Math.sqrt(E)*(Math.random()-0.5); vxs+=m[i]*vx[i]; vys+=m[i]*vy[i]; xs+=m[i]*x[i]; ys+=m[i]*y[i]; D[i]=size*Math.sqrt(m[i]);//diameter view[i]=true; Ms+=m[i]; } nc=N; vxs/=-Ms; vys/=-Ms; xs/= -Ms;ys/= -Ms; for(int i=0;i<N;i++){ vx[i]+=vxs; vy[i]+=vys; x[i]+=xs; y[i]+=ys; }// so total momentum =0, center of mass is (0,0) G=Gcst*cst; if(circular){ xs=ys=0; for(int i=0;i<N;i++){ if(x[i]*vy[i]>y[i]*vx[i]){ x[i]=-x[i]; if(-x[i]*vy[i]+y[i]*vx[i]<-x[i]*vy[i]-y[i]*vx[i]){ y[i]=-y[i]; } } xs+=m[i]*x[i]; ys+=m[i]*y[i]; } xs/=-Ms; ys/=-Ms; for(int i=0;i<N;i++){ x[i]+=xs; y[i]+=ys; } } _view.traceSet.clear();

    Evol Page

    Indep. Var. Increment
    d x[i] /dt=vx[i]
    d y[i] /dt=vy[i]
    d vx[i] /dt=calFx(i,x,y)/m[i]
    d vy[i] /dt=calFy(i,x,y)/m[i]
    SolverMidPointTolerance=0.001

    FixRel Page

    for(int i=0;i<N;i++){ if(!view[i])continue; for(int j=i+1;j<N;j++){ if(view[j]){ r2=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]); d=(D[i]+D[j]);///2; d2=d*d; if(r2<d2){ M=m[i]+m[j]; x[i]=(m[i]*x[i]+m[j]*x[j])/M; y[i]=(m[i]*y[i]+m[j]*y[j])/M; vx[i]=(m[i]*vx[i]+m[j]*vx[j])/M; vy[i]=(m[i]*vy[i]+m[j]*vy[j])/M; m[i]=M; D[i]=size*Math.sqrt(m[i]); view[j]=false; nc--; } } } } npt=(int)(500/Math.sqrt(nc));
    double dv; public double dvalue (double v) { if(v>0)dv=0.5; else if(v<0)dv=-0.5; else dv=0; return (int)(v*100+dv)/100.; }
    public double calFx (int id,double x[],double y[]) { if(!view[id])return 0; fx=0; for(int i=0;i<N;i++){ if(!view[i] || i==id)continue; r2=(x[i]-x[id])*(x[i]-x[id])+(y[i]-y[id])*(y[i]-y[id]); fcst= G*m[i]*m[id]/r2; fx+=fcst*(x[i]-x[id]); } return fx; } public double calFy (int id,double x[],double y[]) { if(!view[id])return 0; fy=0; for(int i=0;i<N;i++){ if(!view[i] || i==id)continue; r2=(x[i]-x[id])*(x[i]-x[id])+(y[i]-y[id])*(y[i]-y[id]); fcst= G*m[i]*m[id]/r2; fy+=fcst*(y[i]-y[id]); } return fy; }
    EJSVIEW: Click link to view it's content
    Control variables:(testing)
    double,double,double,double,double,int
    title="Frame"
    layout=border
    visible=true
    location="0,0"
    size="499,526"
    position=center
    autoscaleX=false
    autoscaleY=false
    minimumX=xmin*scale+xc
    maximumX=xmax*scale+xc
    minimumY=ymin*scale+yc
    maximumY=ymax*scale+yc
    square=true
    elementnumber=N
    x=x
    y=y
    visible=view
    maxpoints=npt
    norepeat=true
    connected=true
    color=LIGHTGRAY
    numberOfElements=N
    x=x
    y=y
    sizeX=D
    sizeY=D
    scalex=scale2
    scaley=scale2
    visible=view
    enabledPosition=true
    elementSelected=id
    enteredAction=xc=x[id]; yc=y[id]; mn=m[id];
    fillColor=0,0,255,128
    numberOfElements=N
    x=x
    y=y
    sizeX=vx
    sizeY=vy
    scalex=scale2
    scaley=scale2
    visible=view
    lineColor=255,0,0,128
    fillColor=255,0,0,128
    sizeX=6
    sizeY=6
    pixelSize=true
    style=WHEEL
    lineColor=DARKGRAY
    fillColor=null
    position=east
    layout=GRID:0,1,0,0
    position=east
    variable=scale
    minimum=1
    maximum=50
    format="s=0.0"
    orientation=VERTICAL
    dragaction=scale2=Math.sqrt(scale);
    position=north
    variable=xc
    minimum=xmin*scale
    maximum=xmax*scale
    position=west
    variable=yc
    minimum=ymin*scale
    maximum=ymax*scale
    orientation=VERTICAL
    position=south
    layout=VBOX
    position=center
    layout=HBOX
    position=center
    variable=Gcst
    minimum=1
    maximum=10
    format="G=0.00"
    ticks=10
    closest=true
    dragaction=G=Gcst*cst;
    variable=E
    minimum=1.0
    maximum=10.0
    format="E=0.00"
    ticks=10
    closest=true
    enabled=_isPaused()
    action=_initialize()
    layout=VBOX
    variable=N
    minimum=10
    maximum=n
    format="N=0"
    enabled=_isPaused()
    dragaction=_initialize()
    layout=HBOX
    variable=mn
    minimum=0.0
    maximum=n
    format="M=0"
    size="60,0"
    variable=samesize
    text="same"
    layout=GRID:0,1,0,0
    position=east
    layout=GRID:1,0,0,0
    image=/org/opensourcephysics/resources/controls/images/reset.gif
    action=_reset()
    text="init"
    enabled=_isPaused()
    action=_initialize()
    variable=_isPaused
    imageOn=/org/opensourcephysics/resources/controls/images/play.gif
    actionOn=_play()
    imageOff=/org/opensourcephysics/resources/controls/images/pause.gif
    actionOff=_pause()
    layout=HBOX
    variable=nc
    minimum=1
    maximum=n
    format="n=0"
    size="50,0"
    variable=circular
    text="circular"
    enabled=_isPaused()
    action=_initialize()
    text="O"
    enabled=xc!=0 || yc!=0
    action=xc=0; yc=0;