Closed artyprog closed 8 years ago
Hi Artyprog
I've been following the links you gave. I especially like the ray-tracing program. I wonder how long it takes to generate this picture in JS rather than C/C++, the result is beautiful. Furthermore in the code under the links some things I understand, some things I don't, and on some points I have questions or remarks / suggestions for improvement, hopefully not too pedantic...
About the RapydGlow example. Since I've done many realtime simulations I take the liberty to suggest an important improvement. Currently dt has a fixed value of 0.3 s. The comment in the loop suggests it is executed 200 times per second, which is once every 5 ms. This seems quite a mismatch, unless different units were used. A more severe objection is that the time to traverse the loop will sometimes be longer than intended, due to the processor load and the low priority of browser processes.
You can solve both these problems by the following procedure:
At the start of each loop assign the current system time to a variable, e.g. current_time, first saving its old value into another variable: previous_time. Compute dt as current_time - previous_time, rather than giving it a constant value. In this way your simulation will always be realtime, although large timesteps can make the integration less accurate. But it will not accellerate or slow down if the processor load varies.
In general, always use the real loop time rather than a predicted one. This will make your simulations robust. Sorry I am being a bit 'teacherish' about this, but I teach my students real time control systems, and this is one of the things I consider absolutely crucial for a robust simulation. Everyone always starts out taking a fixed dt, and I can see their simulations slow down as soon as the system has something else to do. Taking the real dt will increase the integration step in that case, leading to no slowdown at all. In general taking the same SI units everywhere is also a good idea. So sec's rather than msec's . I haven't only used this for simulations by the way, it is the way all real-time controls I wrote (my daytime job) do their work. It is also the way PLC's (programmable logic controllers) work, using a variable called e.g. 'sweeptime' or 'period'. You'll find a PLC simulator / control code generator working like this at https://pypi.python.org/pypi/SimPyLC, and an explanation of this way of 'variable time' integration and differentiation at http://www.qquick.org/simpylchowto in the paragraph about integration and differentiation at the end.
But maybe you know all of this already...
About the RapydBox example. When I follow the link there seems to be nothing there, only an empty editor. Am I doing something wrong here?
About the RapydRay example. This is realy a very nice, compact ray tracer. It always amazes me that ray-tracing programs are so brief and yet generate such beautiful pictures, just by applying recursion.
In general:
As far as matrices and vectors are used in any of these, you could use Transcrypt's local operator overloading, or maybe even Numscrypt, which supports some matrix- and vector operations out of the box. Numscrypt will gradually be expanded, but already it contains some useful stuff for demo's like this.
Kind regards and curious about the results Jacques
Hy Jacques,
Thank you very much for your detailed response as always :-) I was absolutely not aware of all your suggestions, thank you. SimplePyLC is really impressive, congrats.
Concerning RapydBox, choose one of the samples on the menu bar (especially ants demo my favorite). The scope was to port NodeBox on the web https://www.nodebox.net/code/index.php/Home. Here I used the Javascript port : http://www.clips.ua.ac.be/pages/pattern-canvas
In fact the really one I would like to port are RapydBox and RapydRay. Betwise you can modify RapydRay in live ans see the result near instantly.
There so many projects that could benefit from Transcrypt ... i have not enough time :-)
I'll close this for now. Let me about progress with either application, looking forward to the results.
Kind regards Jacques
Hi Everybody,
Here are a couple of samples I would like to reimplement in Transcrypt :
Regards
PS : Read the about link Look at the while loop in RapydGlow. RapydGlow was a proof of concept for running VPython in browser. It is now completely implemented by Bruce Sherwood in GlowScript