ColorStripe and ColorDisc

Posted on
  • Since I had some trouble with color encoding on Bangle.js (see this conversation), I thought it might be a good idea to post two colorful experiments:

    • ColorStripe (Gist, run in emulator) fills the display with a "rainbow stripe"
    • ColorDisc (Gist, run in emulator) fills the display with a color disc - but be warned: it takes a while for this program to finish although it should be worth waiting...)

    Enjoy!

  • Nice! For the disc, you could try something like:

      let yOffset = -Radius;
      setTimeout(function cb() {
        for (let xOffset = -Radius; xOffset <= Radius; xOffset++) {
          let OffsetSquared = xOffset*xOffset + yOffset*yOffset;
          if (OffsetSquared <= RadiusSquared) {
            let Hue        = Rad2Deg(Math.atan2(yOffset,xOffset));
            let Saturation = Math.sqrt(OffsetSquared)/Radius;
            let RGB        = HSVtoRGB(Hue, Saturation, Value);
            let Color = RGB[0] << 11 | RGB[1] << 5 | RGB[2];
            g.setPixel(Radius+xOffset,Radius+yOffset­, Color);
          }
        }
        yOffset++;
        if (yOffset <= Radius)
          setTimeout(cb,10);
      },10);
    

    To ensure that it doesn't 'hang' the browser while computing it :)

  • Indeed, a good idea!

    Although that code will slow down execution even further...

    Let's see how it will perform on a real device...

  • even setTimeout(cb,0); keeps the browser interactive and it takes 20 vs 16 seconds

    EDIT:
    and if I enable pretokenize on that setTimeout(function cb() part it fails later that cb is not defined, is this known bug of pretokenizer?

  • is this known bug of pretokenizer?

    Not that I'm aware of. Just tried to reproduce and I can't see it here - please could you slim your code down to something minimal that fails and post it as a new thread?

  • oh, it is combination of closure online simple optimizations and pretokenisation, even the gist as is breaks if you enable both checkboxes first and then open the link of the colordisc as is. if I disable pretokenization the minification works and it runs fine.

    Edit: oh it breaks even with minification turned off now. just enable pretokenization, close emulator and then click the colordisc emulator link again, I see HSVtoRGB is not defined, do you see it?

  • ...infinite loop locks up the emulator ide... only way to get out of it is wait for the ide (browser) popup whether to continue waiting or kill / close it. So saving code before upload is always a good thing.

  • Ahh ok, I can reproduce, and just fixed this (it'll need both a new IDE and firmware) - so just to be clear:

    • E.setFlags({pretokenise: 1}) (pretokenisation in Espruino) works fine
    • Web IDE pretokenise minification setting causes errors
  • I don't know if you like this. but have a look and enjoy:

    https://www.espruino.com/ide/emulator.ht­ml?gist=c63a9d49a09847144666ea8b0a6a2fd5­&upload

    @MaBe - add this feature in his list Enhancement for Graphics #1702

  • @Abhinav fell free to add anything you like to see on this list by your own.

  • Great!! thanks!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

ColorStripe and ColorDisc

Posted by Avatar for Andreas_Rozek @Andreas_Rozek

Actions