Mandelbrot viewer



Could do with better pan/zoom, and better color choices. Algorithm adapted (badly) from

Pan around with the arrow buttons. Zoom in with A. Zoom out with B.


I wonder what these colorful images could be used for? I clicked on the “share” link and get the image in MakeCode but , of what use is it? Just wondering.

They’re for looking at.

Does the main link not work for you?

Let me know if anything can be improved with my post, thanks. :beer:

Looks great! Could you add some intermediate rendering steps so that one can “see” the fractal being computed?


Sounds like a fun idea. Effectively means breaking the draw() function apart, to make it a kind of resumable ‘coroutine’, to render at various stages of the inner loop, per pixel. Willing to give it a go, unless you want to try!

Edit: In the end, I just did it with a global variable - nice and dirty!

OK try this.

Press A+B together to animate the frame being drawn. It’s a bit ‘flashy’!

You can also now hold down the pan and zoom buttons, instead of repeatedly clicking them.

What I really want to do is give it a different color palette, or - even better - more colors. Is 16 color imposed by the hardware, or by the current pxt-arcade? I see the ‘Darker Duck’ example doing something with the screen colors themselves, a rectangle at a time, but it’s a bit hard to see exactly what it’s doing…

Somewhat odd behavior in console but at least the image is recognized and installed by F401 processor, I’ll put a stopwatch on it and time how long it takes for the image to be loaded onto the TFT screen, I’ll guess 2 min. at least: Thanks for the program: .

Quite interesting if there are such major differences between the hardware and the emulator I suppose. Is it just lack of computational power causing it to run at an insanely low framerate on-device?

You should expect the hardware to be 10s of times slower than your browser when doing floating point computation. The device doesn’t have 64 bit floating point unit, so operations are implemented in software, which is ~100x slower. On top of that, the MCU on the hardware is ~50x slower than your computer.

Regular games work all right on hardware (similar speed to browser), since our generated JavaScript for the browser isn’t very good.

I can’t see any response at all to button press on console (s). It could be that A+B button press would do something, eventually, as they do on the computer monitor in simulator but I have not proven that to be true up to this point. Still working on it. I question whether F401 processor even acknowledges an input from buttons on the console for this program at this point in time; but it may prove to be that you can input in this case given enough time.

Pressing and holding buttons does seem to cause a response from the console eventually. i don’t know which buttons.

Ah, ok, thanks for the confirmation.

So out of interest: 1) how does the device ‘know’ when to do integer math instead of 64-bit floating point, when the variable type is just ‘number’?; 2) is there any way to force 32-bit floating point (the chip has 32-bit FPU?)

@paul you can try to use our fixed point math numbers (see ). Those are used internally in the physics engine to stay fast at the cost of lesser numerical accuracy.

Hi - that’s good to hear… I was going to start considering creating a fixed point lib of my own. Didn’t realize there were some already!

However, the chip in question does have an FPU, albeit a single-precision one, unless I’m mistaken. If the runtime could use that, it would likely be even faster than fixed-point.

OK, well, I quickly dashed through the code and converted everything to Fx8 representations:

It’s now like molasses in the emulator, although it still ‘works’. I don’t have hardware to test at the moment, but would be fascinated to see it running.

(Of course, now the code in this version is strictly Javascript, as there are no Fx8 blocks.)

Would still be interested if there is any method for getting the compiler to use 32-bit single-precision floats, to use the FPU on the device

There is currently no way to use the FPU. We may want to rethink that at some point though there are representation problems.

The runtime represents integers between -1b and 1b (roughly, really 2^30) as integers and everything else as boxed doubles. When the result can be represented as integer, it is (so 0.5+2.5 will be represented as integer and 1/3 will not).

Or to be more exact - the choice of number representation happens at runtime with the fast path assuming integers.

Well, no easy way :slight_smile:

1 Like