What does this code look like on android? | SoloLearn: Learn to code for FREE!

+7

What does this code look like on android?

On my ipad particles fall on green water, where they slow down or even bounce. On the iphone, I see no water or deceleration. What does it do on android? I would be grateful for feedback as I cannot see it. On the pc i cannot tap. How can I make it look the same everywhere? https://code.sololearn.com/WLckKJThtQ2V/?ref=app

7/7/2020 6:57:56 PM

bell

29 Answers

New Answer

+6

bell sometimes constants like W and H must be called inside the init function. You really don't have to add everything inside onload event( I don't like that syntax) https://code.sololearn.com/WoDm7C1b151W/?ref=app

+7

Feedback on android, Deceleration on water good ✅ Weight simulation good (Big particle goes first) ✅ Particle bounce at bottom ✅ Particle left the trace behind ✅ I think its perfect in android sir!, I wish I could be pro as you, I'm a new starter and I wanna be a good Front End Developer 😁

+6

It look nice, btw there's a kind of bending behavior forming a random acute angle immediately the movers are suspended inside water. I'm wondering if that's a water refraction, cos that's not really how it should work

+6

Particles not falling straight could best be explained by the effect of the brownian motion not actually Wind. In your case, the particles are not moving in a linear direction but literally they're still moving straight instead of an irregular movement but that still isn't what I was talking about. The moment movers enter the water, the bend instead they should keep with their direction, the major thing that should affect the movement is density of the water but that doesn't exist

+5

confirm, no water on the screen in the iPhone app. The dropped elements just bounce off the bottom of the screen. It does not work at all on mobile Safari. Just a black screen. Mirielle [INACTIVE] definitely is the master cross-platform fixer. 😉👍

+4

Look at what I was talking about https://ibb.co/1TKCgfK

+4

Code Crasher check if this version works for you https://code.sololearn.com/W89ohV2Ja830/?ref=app

+3

Its stay forever on the screen sir, I provide you with the screenshot from my phone, here: https://www.sololearn.com/post/459885/?ref=app

+3

Mirielle [INACTIVE] the particles should not fall straight because there is random wind. (Fast small ones should bounce against the water). Could the angle be explained by the wind? I will check my normalisation, as wrong water resistance in the x component could cause this. The coefficient to avoid division by zero might be inappropriate. Thanks for the feedback! (Would you know why the water is not green nor viscous on the iphone?)

+3

Also, I noticed that after sometimes each mover would go offscreen maybe due to constant addition of gravity... You can make an if-else statement to correct that. If (mover's.y + mover's.radius >= H) // dont apply gravity

+3

Mirielle [INACTIVE] I see the water now. the "movers" fall straight down, hit the water, slow down, and sit a little bit on the bottom, before slowly moving off screen. The screen looks more like the snapshot earlier in the thread though. 😉👍

+3

bell good luck! This looks like a really fun project. I wish I understood physics and math more, cause this kind of physics modeling just fascinates me. Thanks for sharing! 👍 Happy Coding!

+3

Mirielle [INACTIVE] Your version looks right on my phone too! So you put al the JS inside an onload {} . Is that always the right practice? Or was having two addEventListeners on the window? or was the window the wrong element to hang them to? I tried many things to get the screentouch to trigger instantiation before anything worked. This has been really useful feedback, thank you!

+3

And the water / sky ratio makes sense now: before the area was too small for the number 0.65

+3

Bagus Arif Wicaksono I think you’re right. I use it on an android phone, a laptop, and 2 iPads and I think it’s all good.

+2

Bagus Arif Wicaksono Thank you so much, this is very helpful, gravity should act equally on all particles (after Galileo's experiment) but there is a randomly directed wind, which may lift more light particles when it goes upwards. Do the traces fade and disappear (as in ipad) or stay forever as on iphone (I wish I knew how ro make them go)?

+1

Code Crasher , Mirielle [INACTIVE] Thank you both. To make it work on a browser I should couple generation of particles to some other event, I only just found out how to use touch (so happy!). I commented my call to the wind-force method on line 127 and now particles plunge dead, no angle. It may be the residual direction with divisor approaching zero, but a slight angle is more alive. I will definitely look into brownian motion: I have some random acceleration in the code, to make slow particles look a bit hesitant (aim is to start from physics but make particles look alive) but it is turned off in this code. Thank you for input about how to stop particles from going offscreen (trying it now), I have a strange effect I did not understand. I reset acceleration to zero adter each update so I thought I had solved it. When two particles collide, only one survives, can it be this?

+1

Mirielle [INACTIVE] thanks for the picture! Would that not be the right physics? Particles hit the water with an angle from the windf, friction depends on squared velocity, which is much higher along gravity y than tiny wind x. Thus, the angle should increase? If the magnitude is wrong, I must have been too coarse fudging the normalisation to avoid zero division.

+1

Code Crasher thank you! It really is fun to pull at the strings. You should have a look at the book of Daniel Shiffman I got the ideas from: The Nature of code, it is free and easy to follow because one can choose ar every point how much complexity to include. Besides, maths and physics are kept really simple.

+1

ManUnitedMVM thank you, it is good now thanks to all the feedback and help in this thread to make the code cross platform. Thank you also for your valuable confirmation.