• 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:

    function deg_to_rad(deg){
      return deg * PI / 180;
    }
    
    function drawArc(cx, cy, x, y, t, col) {
      const dt = 0.01;
    
      let radius = Math.sqrt(Math.pow(cx-x,2) + Math.pow(cy-y,2));
    
      let start_angle = Math.atan2(y - cy, x - cx);
      let end_angle = start_angle + deg_to_rad(t);
    
      for (let angle = start_angle; angle < end_angle; angle += dt ) {
          let x_cord = parseInt(radius * Math.cos(angle));
          let y_cord = parseInt(radius * Math.sin(angle));
    
          g.setPixel(x_cord + cx, y_cord + cy, col);
      }
    }
    

    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.


    1 Attachment

About

Avatar for ramzy23 @ramzy23 started