BangleJS 2 Emulator slows down when writing an app #7281
Replies: 1 comment
-
Posted at 2025-01-04 by @devsnd Hey @ramzy23, Your code is slow because of overdraw. Overdraw means that you paint the same pixel over and over again, no matter if it has already been painted before. Since you step through your circle at 0.1 degree increments, it gets really expensive to draw your circle even in the emulator. The real hardware watch would take a lot longer still. I recommend looking at drawing algorithms using the implicit circle equation or the bresenham algorithm. Posted at 2025-01-05 by @halemmerich There is also https://github.com/espruino/BangleApps/blob/master/modules/graphics_utils.js. Maybe you can use that or modify it to have the features you need. Posted at 2025-01-05 by @fanoush
The Bresenham algorithm is used in Graphics.drawEllipse some discussion here EDIT: there is also https://www.espruino.com/Reference#l_Graphics_setClipRect so that could work to limit drawEllipse/drawCircle Posted at 2025-01-06 by @gfwilliams
That would work out really nicely - figure out the right coordinates needed for |
Beta Was this translation helpful? Give feedback.
-
Posted at 2025-01-04 by ramzy23
Hi all,
Hope you are doing well. I bought myself a BangleJS2 over a year ago with the goal of writing my own app and finally I have gotten to it! I'm not a JS dev in any respects so, I'm quite new to the language in a manner of speaking but have been quite exposed to languages like C and Python so can get my way round the basic syntax e.t.c.
I have been trying to use the WebIDE to get an app going and have been working on a function to draw arcs, which I hope to upstream to the main repo, but have met a few hiccups along the way. For a start, I wrote this app in Javascript, and have it as follows:
So with that in mind, here is what I have done with it, to test it out - every so often, I increment one of 3 counters which will increase the radius of the arc drawn (watch video for what I mean). You will notice that at some point, the drawing starts t stutter. I'd love to know why this is the case, and how I could avoid this? (Oh, I'm working on a line thickness feature, hence why there are two lines per point). I'd also appreciate some input on the value for dt to use given it's in radians (and Pi is quite the relatively small number)
I am wondering if the JS version of this will perform worse than the C version of this function. I'm just finishing up the last bits before posting a PR in the Espruino repository but don't yet know how to test this code on my device. I'm also trying to get some form of a local dev environment going to test out this code. Any advice or help on this issue would be greatly appreciated.
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions