Mandelbrot set

Posted on
  • Sorry,

    but I could not resist...

    During my time as a student at university, it became cool to render the famous "Mandelbrot set" - which took hours on those old personal computers a student could afford.

    Now, that we have Bangle.js, let's see how it performs. Here is the gist which you may directly run in the emulator, as usual.

    The default settings produce a reasonably impressive result within a few seconds.

    You may play around with the code yourself by adjusting the "ColorMap" - its size also determines the max. number of iterations and directly influences the time it takes to produce some output.

    Have fun!

  • Wow, looks great!

    As with the colour wheel, if you use setTimeout/interval for each scanline then the IDE window and REPL will stay responsive while rendering (it's also unlikely to noticeably increase the time taken to render)

    also: that would be a pretty cool clock face - just slowly re-render the mandelbrot zooming in all the time :)

  • ...nice...

    Be patient and listen to the fan of your machine while the blue almond bread - sorry, Mandelbrot - gets ready... (Blue Almonds is a well known brand of almonds).

    NB: always a pic to a selling post! ;-)


    1 Attachment

    • bMandelbrot.png
  • @Gordon Nice idea, but...

    ...I'm afraid it will drain the battery dry in no time.

    And, it would require double-buffering (thus, reducing the available screen space). What, if one would reduce screen resolution - would that also reduce double-buffering memory requirements and (on the other side) handle the full screen space?

  • @allObjects thanks for the screen shot!

  • ...I'm afraid it will drain the battery dry in no time.

    It's not as bad as you think - flat out the CPU uses about 7mA I think, which is still 50 hours of life :)

    What, if one would reduce screen resolution

    That's the 'game mode' that just got added is for :)

  • 7mA ("seven") for 100% CPU usage? not "sevenhundred" or "seventy", at least? Wow, that's cheap, indeed!

    Hmm, perhaps, I'll also have to look at the "game mode" now...

  • In this case it may hurt that floating point math is done in software as the CPU in real device has only single precision floats and javascript uses doubles. Basic set would work just fine with single precision floats. I made some experiments with it and it is doable even with no changes in espruino, see http://forum.espruino.com/conversations/­337810/ This of course does not make sense with emulator now, only with real device.

  • Wow, one can even include compiled C within JS on Bangle.js?

    This makes the whole thing even more interesting.

    Thanks for your work!

  • Yes you can, but it calls C compiler over web when you send code to the device. I linked one of my gists there in the conversation. Later I made another one which is a bit slimmed down and contains result of the compiler in comments so you can see how it works. So with real nrf52 device if you comment the inline code and uncomment equivalent E.nativeCall parts below it it may run without setting up the compiler (as the online one does not support those compiler flags right now).

  • Wow, good to know - thanks a lot!

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

Mandelbrot set

Posted by Avatar for Andreas_Rozek @Andreas_Rozek

Actions