How to simulate water in 2D physics with codea?

Hi All,

I suspect this ma be a bug, but possibly only with physics. The local definitions should not be available to any of the other code , yet it runs for several cycles.

Bri_G

:slight_smile:

Hi @littfass,
I’m a newbie with Codea/Lua but I like a lot your project, because I want to use Codea for trying to simulate real world problems (if possible ) :smiley:
With regard to your “quick test”, I can’t explain (for the moment) the reason why it slows down when increasing the particle number, but I think one reason could be the way the fluid particles are “created”: at the screen-center and, due to interactions between them, they displace each other simultanously while they are created. I’m not sure if you’ve fixed that already, but I think, an improvement in the “creation” procedure could help
 but I don’t know it exactly :confused:
Greetings from Mexico,

Victor

Is not working :-((
error is

error: error: [string "function MPM:simulate ()..."]:199: attempt to index field '?' (a nil value)

Pausing playback

@littfass, just a tiny remark: the “creation” procedure in your “quick test” creates 101 particles (instead of, e.g., 100); I mean, your initial index should be 1 instead of 0 in order to create your maximum number of items.

Edit: I’ve trying to figure out what could be wrong when playing with more than 200 particles, focusing for the moment on your quick test and with my scarce knowledge of Codea/Lua. It seems to me that the “creation” function isn’t the main poblem, which begins to appear when tilting the ipad
 It might be that the problem is the drawing ability of the device (computation-speed required for the drawing loop in your code for every frame)
 :-? ~O)
Anyway, I attach here a short video from a similar simulation that I made: the “flow” of perfectly elastic “fluid particles” inside a box, “applying” a momentum in x-direction to them in order to start with an initial velocity. After that, they interact with a “solid body” (e.g. a cylinder) and the walls of the box.

http://www.youtube.com/watch?v=uX7VTicgRTY

I’ll attach my code here later, after “cleaning it”, for the use of beginners like me.
Saludos desde MĂ©xico,
Victor ~O)

Uups
 thought lists begin with an 0 index? that might solve my problems on the mpm though :slight_smile:

If you are intersted, maybe you can do operations with the image, a wave ripple must be easy thought, you only have to change the colors info of an image using set and get with an image data structure, Check this simple JavaScript
http://badassjs.com/post/932217000/water-ripple-effect-in-canvas

can anyone code this? When I try, it crash becouse big number of dots


http://www.youtube.com/watch?v=OP7_MwCkW40