Please help (solved) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
19th Mar 2021, 9:49 PM
Michael
Michael - avatar
8 Answers
+ 3
I've reduced canvas size to fit in my phone screen ^^ and made some changes to let it (better) works: https://code.sololearn.com/W0G61ka6VAgY/?ref=app 𝕄𝕚𝕔𝕙𝕒𝕖𝕝 𝕃𝕚𝕦 [🄰🄲🅃🄸🅅🄴] (っ◔◡◔)っ edited to use canvas dimensions instead of hardcoded bounds ^^
19th Mar 2021, 10:15 PM
visph
visph - avatar
+ 2
Eddy M thanks, but I only set canvas size to roughly fit my phone screen for testing purpose... what I would do if it was my code, would be to set canvas size to exact viewport size, dynamically... maybe resizing it on window resize ^^ similarly I've added a simple log overlay for tests ;)
19th Mar 2021, 11:33 PM
visph
visph - avatar
+ 2
Eddy M not providing the delay argument default to minimal delay (around 4ms if I remember right)... however, you cannot be sure that interval will be of the delay provided (or default 4ms), as it depends on your device cpu charge and how many things you do in the script, both meanwhile and in callback(s) ^^
20th Mar 2021, 4:17 AM
visph
visph - avatar
+ 1
@visph To prevent repeating a too short sequence and keep the canvas within current size you can set height="399" if the circle bounces at 10 from the margin.
19th Mar 2021, 11:27 PM
Eddy M
+ 1
I played a little with the code modified by visph an noticed setInterval() is missing the timing parameter, normally required. I don't know of a specific browser that would complain but I suggest using "}, 0)" instead of "})" near the end of code. It may work a bit faster without it but I don't know how to time it precisely.
20th Mar 2021, 4:14 AM
Eddy M
+ 1
I was only thinking about conforming to standards and if some improvement is still necessary it may probably be made elsewhere in the code. I've read it is required and I can see it works without it in my browser. Is it safe to leave it off? I don't know.
20th Mar 2021, 4:32 AM
Eddy M
0
Just in case someone understands otherwise, the timing parameter of setInterval() is missing in the original code also. I just used the modified code because it's working :)
20th Mar 2021, 4:49 AM
Eddy M
0
yes, it's safe: that's an optional argument ;) as well as you could provide arguments to be passed to the callback after it if you need/want :)
20th Mar 2021, 4:50 AM
visph
visph - avatar