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

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on June 02, 2009, 07:11:41 pm



Title: how to make the left right button to vary x? for all modes
Post by: lookang on June 02, 2009, 07:11:41 pm
hi prof

currently, the left n right button works for mode singapore

code
action:
x=x+0.25714; right
and
x=x-0.25714; left

i need some tips on a generalized code for the other modes

attached in my attempt

i don't understand how to read some of your codes
Code:
if(mode.equals("0.02 mm version 1")){
 dycst=1.;
 n2s=51;
 dx2=49*dxm/50;
 nmode=5;
 L=50*dxm+size;
// l_unit="0.02mm";
 unit=0.02;
}else if(mode.equals("0.1 mm version 1")){
 dycst=0.;
 n2s=51;
 dx2=49*dxm/50;
 nmode=5;
 L=50*dxm+size;
// l_unit="0.1mm";
 unit=0.1;
}else if(mode.equals("0.05 mm version 1 singapore schools")){
 dx2=39*dxm/40*2; //
 n2s=21; // number of intervals on the lower scale
 dycst=1.; //
 nmode=2; //
 L=40*dxm+size;
// l_unit="0.05mm";
 unit=0.05;
}else if(mode.equals("0.1 mm version 2")){
 dx2=39*dxm/40*2;
 n2s=21;
 dycst=0.;
 nmode=2;
 L=40*dxm+size;
// l_unit="0.1mm";
 unit=0.1;
}else if(mode.equals("0.05 mm version 2")){
 dx2=19*dxm/20;
 n2s=21;
 dycst=1.;
 nmode=2;
 L=20*dxm+size;
// l_unit="0.05mm";
 unit=0.05;
}else if(mode.equals("0.1 mm version 3")){
 dx2=19*dxm/20;
 n2s=21;
 dycst=0.;
 nmode=2;
 L=20*dxm+size;
// l_unit="0.1mm";
 unit=0.1;
}
l_unit=unit+"mm";
x6[4]=x6[5]=x2+L;


i will try to figure out asap.





Title: Re: how to make the left right button to vary x? for all modes
Post by: Fu-Kwun Hwang on June 02, 2009, 07:25:13 pm
1.  dycst=0; no minor ticks. dycst=1; draw minus ticks.
     The length of the ticks are evated by dycst*minor_ticke_length.
2. 0.02mm case without minor ticks will be the same as 0.1mm case. That is why all the rest parameters are the same.
3. n2s is the number of ticks on the scale.


Title: Re: how to make the left right button to vary x? for all modes
Post by: lookang on June 02, 2009, 10:35:43 pm
i think i figure out a way! critical thinking from thinking whole day LOL.
thanks!

will report finding asap


Title: Re: how to make the left right button to vary x? for all modes
Post by: Fu-Kwun Hwang on June 03, 2009, 09:08:15 am
The code you wrote was:
x=x-0.25718;// take 257.16 divide 50 mm divide 20

which is equal to x=x-dxm/20.;  for your case (20 smaller division). ;)


Title: Re: how to make the left right button to vary x? for all modes
Post by: lookang on June 03, 2009, 11:11:15 am
i am making a super applet from remixing yours, thanks for code
x=x-dxm/20.; // for your case (20 smaller division).

just the right tip i need to make sense. Thanks!


Title: Re: how to make the left right button to vary x? for all modes
Post by: lookang on June 03, 2009, 07:56:58 pm
in the left button
i added code on action

if(x<=0){
x=0;
}
else {
x=x-increment;
}

initialization
i added
   increment = dxm/(1/unit);

it work beautifully, and i even added scaffolds to suggest the relationship

 if ( error == 0 ) {
 l_x="d="+l_x;
}
 else if ( vs*unit+(-error*unit) >= 1 ){
 l_x="d=" + dvalue((int)(x/dxm-1),unit)+ "+" +dvalue(vs*unit,unit)+ "+(" + dvalue(-error*unit,(unit))+ ") = " + l_x;
// l_x="d=" + dvalue((int)(x/dxm-1),unit)+ "+" +dvalue(vs*unit,unit)+ "+(" + dvalue(-error*unit,(unit)) + ")+ "=" ;
}
else if ( vs*unit+(-error*unit) <= 0 ){
 l_x="d=" + dvalue((int)(x/dxm+1),unit)+ "+" +dvalue(vs*unit,unit)+ "+(" + dvalue(-error*unit,(unit))+ ") = " + l_x;
}
 else {
    l_x="d="+l_x;
    }

it is a work of art and definitely a great java for sense making!

thanks!
http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=684.msg2452#msg2452
to see this great applet!


Title: Re: how to make the left right button to vary x? for all modes
Post by: Fu-Kwun Hwang on June 03, 2009, 08:57:04 pm
Good works! I believe you did feel great when you find out how to solve it by yourself.