I haven’t been working on larger projects for a while, so here’s a couple of recent chips from the workbench.

In my ongoing quest for a faster *HX8357D* display driver, I was excited to read that the fast *TFT_eSPI* library now claims to support this beautiful but rather slow display. Unfortunately, the results were disappointing (unstable, *readPixel* freezes the screen). However, a nice bycatch of my experiments was the discovery that display updates become noticeably faster when the esp8266’s runs at 160MHz. Very useful for my fractal sketches, and for faster aircraft position updates on the Flight Radar‘s map.

Then I wondered how fast an esp8266 could actually drive my ili9341 driven 320×240 display. So I used my fast ‘offset-modulo’ Koch Snowflake algorithm for a **snowflake animation** speed test.

The result: an esp8266 at 160MHz can draw more than 100 (iteration depth 3) snowflakes per second on an ili9341 display, using the TFT_eSPI library. That’s about 5x faster than Adafruit’s HX8357 library can achieve on my 480×320 display. Hopefully, there will be a fast and reliable library for that display some day. **Update**: the TFT_eSPI library now supports driving the HX8457 in parallel mode and the results are impressive.

My renewed attention to the *Koch Snowflake* led to the discovery of a fractal that was new to me: the *Plasma fractal*. A commonly used algorithm to produce it is the *Diamond-square algorithm*. It’s apparently being used to generate nature-like backgrounds for video games.

I wrote a small demo sketch that produces **random clouds** (well, sort of…), but it can also be used to produce (non-musical) rock formations or landscapes.

*6 samples of randomly generated clouds *

*(picture quality suffers from camera pixel interference with the TFT display)
*

The Diamond-square algorithm assigns initial values to the four corners of a (2^{n}+1)x(2^{n}+1) grid. Then it starts a process of calculating the remaining elements of the grid, based on neighbour values and a random noise of decreasing magnitude. The visual result depends on the four initial corner values, the random noise and the chosen color mapping.

The name *Plasma fractal* becomes clear when we show consecutive results in a loop. While still using random noise, the trick is to initialize the random generator with the same seed value for every new loop cycle. By slightly changing the initial corner values for each new cycle, the results will also be slightly different from the previous one, which is exactly what we want for a smooth animation.

The general formula that I used for initializing corner ** k** with value

**h[**is:

*k*]**h[ k] = d[k] + a[k]*sin( t*f[k] )** where

**is a loop counter.**

*t*So the value of corner ** k** will periodically swing around value

**d[**with amplitude

*k*]**a[**. The period of the swing is determined by

*k*]**f[**.

*k*]Now we can play with the **d**, **a** and** f** values for each corner, as well as with the color mapping, in order to find visually appealing animations. Here’s a first impression (esp8266 & ili9341 320×240 display). The sketch uses a 65×65 grid, with every point filling a corresponding 3×4 rectangle on the display with it’s color value. Since grid values are stored in 4-byte *float* variables, a 129×129 grid would become too large for the esp8266.

Used values:

1 2 3 |
const float a[4] = {70.0,80.0,50.0,120.0}; const float d[4] = {0.0,0.0,0.0,0.0}; const float f[4] = {0.053,0.101,0.167,0.211}; |

Assignment:

1 2 3 4 |
h[0][0] = d[0] + a[0]*sin(t*f[0]); h[64][0] = d[1] + a[1]*sin(t*f[1]); h[64][64] = d[2] + a[2]*sin(t*f[2]); h[0][64] = d[3] + a[3]*sin(t*f[3]); |

Color mapping:

1 2 3 4 |
// ci is an index for a 128 colors rainbow array // h[c][r] is the value of grid element at row r and column c ci = (128+(int)(h[c][r]))%128; |