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 21, 2010, 01:45:23 pm



Title: how do make Ejs applet run forever unless the pause or reset
Post by: lookang on June 21, 2010, 01:45:23 pm
how do make Ejs applet run forever (time increase by dt ) unless the pause or reset?

i have a strange applet which i remixed from, i tried to track down the codes for the end of simulation but i don't see any.

any idea what is causing the applet to end?

you can make the applet end by changing e=0, i thought it would continue to count t which is what i wanted.



Title: Re: how do make Ejs applet run forever unless the pause or reset
Post by: Fu-Kwun Hwang on June 21, 2010, 03:23:53 pm
I did check out your ejs code.
There are several strange code
1. Why the drawingPanel was assigned to be autoscale?
2. Why maxX= -carSize/2 ???
3. Why Lmax was not defined?
...

You should have assigned initlal value for defined variables.
I do not know how to change your code because I do not know the specification for your simulation.

The code in the event are strange,too!

If I have something bounced between xmin and xmax (xmax>xmin)

I will have code like this for zero condition:
Code:
if (v>0)return x-xmax; // bounced at x=xmax
else if(v<0)return x-xmin; // bounced at x=xmin
return 1;
// the event occurs when return value is less than zero.

And the action will be
Code:
v=-e*v;


Title: Re: how do make Ejs applet run forever unless the pause or reset
Post by: lookang on June 21, 2010, 04:59:54 pm
I did check out your ejs code.
There are several strange code
1. Why the drawingPanel was assigned to be autoscale?
so that maximum view is achieved.
Lmax was original 10, i need to customize it to only 1 metre cos in school, the length of the ramp is about 1.2 m
if i keep Lmax = 10 m, and i vary L, the mainview becomes a very small car and ramp with about of empty space, because L = 10m, so i made L = 1m
and with autoscale, the view is squared and maximum. should i make the view constant?


2. Why maxX= -carSize/2 ???
it is commented cos i was debugging it.  :D
Fixed relations.FixRel Page(43): //maxX= -carSize/2;

3. Why Lmax was not defined?
Lmax = 0.

You should have assigned initlal value for defined variables.
ok, but i blank them because the applet accepts new values after reset button, which is how i make the applet remember/stored previous user inputs without much troublesome variables assignment techniques such as variable_stored to remember last user values.

I do not know how to change your code because I do not know the specification for your simulation.

The code in the event are strange,too!

If I have something bounced between xmin and xmax (xmax>xmin)

I will have code like this for zero condition:
Code:
if (v>0)return x-xmax; // bounced at x=xmax
else if(v<0)return x-xmin; // bounced at x=xmin
return 1;
// the event occurs when return value is less than zero.

And the action will be
Code:
v=-e*v;

interesting, i never did zero crossing before! thx for the tip!

i modify the idea from Ejs default examples http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=797.0
but you are right, i could not get the applet to detect the state correctly  sometimes, so i changes the dt =0.1 to 0.05 s thinking it will lesser the detection state error.
i have adopted your zero crossing method
Code:
if (v>0) return x+carSize/2-xbumperbottom; // bounced at x=xmax
else if(v<0)return x-carSize/2-xbumpertop; // bounced at x=xmin or x+carSize/2
return 1.0;
//return 1.0;
action
Code:
v=-e*v;
will try all the more elegant coding!
thx!


Title: Re: how do make Ejs applet run forever unless the pause or reset
Post by: Fu-Kwun Hwang on June 21, 2010, 07:52:30 pm
Quote
ok, but i blank them because the applet accepts new values after reset button, which is how i make the applet remember/stored previous user inputs without much troublesome variables assignment techniques such as variable_stored to remember last user values.

The effect you need is better done with _initialize() instead of _reset()

Write code need to be initialized at initlalize page and EJS will remember user's inputs.

_reset() is used to restart everything.