Monday, January 11, 2021

Henon Attractor (#22)

We will explore some interesting attractor / fractal called "Henon".


Flower - an exemplary Henon atractor build using algorithm from this post and based on [1].


Introduction

Do you know the Henon attractor? So I didn't know it before I didn't came across it in the old R. Baumann, "Computer Graphics" book [1]. The book is interesting anyway - it consists of many examples of simple and appealing computer graphics figures created with the basic programs printed in the book. I think cover of the book is worth 1000 words (see image below). I really like this B&W style and symmetric figures that appear in the book.

R. Baumann book (here Polish edition, 1984) [1]

 

 

 

 

 

 

 

In his book, R. Baumann lists "problems", I mean examples with the 100% code solutions. It starts with simple 2D pictures of lines and ends with 3D models with hiding of an invisible lines (which is non trivial task today with all that shaders/3d/buffers/opengl stuff as well). The problem #22 in my edition is the "Henon attractor" and I chosed it accidentialy while looking for nice example of 2D graphics for my students of basic C programming (I teach how to save image into PPM format and I tried to find simple 2d picture model as an example). Plus, I always wanted to "play the video" of all R. Baumann pictures.

If I look at Wikipedia - Henon appears as somehow different thing than that one from the book. Thus I decided to put my few words here as I've got interesting results with it. Maybe someone finds it iteresting.

Henon attractor

R. Baumann introduces Henon attractor as an iterative algorithm that starts with (x0, y0) point and iteratively generates new positions by using the equation below:

 
 
This is the iterative equation with one parameter "a" in exactly the same form as givern in [1]. The algorithm is, in fact, very simple and explicit. It starts with initial pair (x,y) = (x0,y0) and iterates through first two above equations. This, each iteration we end up with new pair (x,y) that may be used to color the image. I like writing it algorithmically so, the implementation will be straightforward:

Henon iteration algorithm
 
1) Choose initial (x,y)
2) Choose the value for parameter "a" which is from -1 to 1
3) Calculate new (x_new,y_new) using formulas:
  x_new = y + h(x)
  y_new = -x + h(x_new)
where h(x) = ax + 2(1-a)x^2 / (1+x^2), where ^ denotes power.
4) Colour (x_new, y_new) and go back to 3) using x=x_new and y=y_new (iteratively continue until 
solution is interesting). You may also do additive colouring here to get some smooth colour gradients.

Results of Henon algorithm

Now, by using this algorithm I was able to produce the following pictures (I put some names to them so that they are more attractive). They are new, in the sense that I didn't know this "fractals" before. If they are new, let me know. Some of the pictures are actually millions of iterations where I not only simply colour the pixels visited during the iterations but do some variations of the algorithm i.e. add colour values (see 4th step of the algorithm).

 

Richelieu embroidery 1

Star


Richelieu embroidery 2

 

Footprints

Sealife

There is some work to tune parameters to achieve those pictures (+ some colour adjustments I've done). For instance, to produce "Sunflower" picture I needed 5000000 iterations at parameters a=0.545793 (x0, y0) = (10.9091,10.9091).

Sunflower

If there is any interest in that I can prepare some post with parameters vs pictures data sets but let us leave it at the moment as possibilities are endless here so, you may have some pleasure discovering it at your own.

The quest for the "strange attractor"

The original Baumann's book [1] consists of the example of Henon diagram that I didn't achieve. I don't have that much time to check all the parameters and they are not provided in the code, thus.. I have some request. If anyone finds a proper parameters (most probably "a" and x0,y0 pair) that gives the same result - please let me know in comments or via email so that other people know it. The figure taken directly from the book is below (it was named strange attractor there).

 

Strange attractor from R. Baumann book (more examples and results below) [1].

 

Animated Henon diagrams

I'll tell you a secret that I always wanted to see "Baumann's" book animated. Moreover, because of my interest in producing animation for students as an example of simple programming task, I was struggling much with varying initial (x0,y0) and "a" variations to produce some nice animations. It was not that easy! I did some first quick animation for the changes with "a" and it was sometimes smooth, sometimes changes were rapid and in general I didn't get really interesting results. It seems there are some interesting "places" where animation is smooth and sometimes little change of "a" given rapid changesd in the shape and structure of the attractor. Then I changed my objectives to produce nicer pictures, coloured them a bit and thus we have these figures above.

Instead of animated result, that is still nothing that I wanted to achieve (I will put it if I am satisfied enough), let us have a look at some animated sequences that I obtaioned while looking for interesting configurations. I varied the scale (so basically the distance of (x0,y0) from the center) at constant a or varied a while scale was kept constant. There is much more to discover and you are welcome to try it (I will be happy to see more interesting "Henon attractor" pictures so email me if you get something or put in the comments.

Animated Henon attractor at a=0.45 with changing initial (x0, y0).
 

Animated Henon attractor at changing a (from -1 to 1 at 1 frame = 1/1250 resolution) at constant x0,y0=(2.4,2.4).

Cont. animated Henon attractor at changing a (from -1 to 1 at 1 frame = 1/1250 resolution) at constant x0,y0=(2.4,2.4).
 

All the credit for the idea about using Henon to create such pictures should go to [1]. If you are interested in the lecture given with live programming (be aware it is in Polish).

[1] Rüdeger Baumann, Grafika Komputerowa, Wydawnictwa Komunikacji i Łączności, Warszawa 1989

edit (random instant shots from Henon fractal):


Where does aluminum rims shape comes from? :-)

edit: Any Scratchers here? See my Scratch implementation of the attractor in that post:

https://scratch.mit.edu/projects/475473238/


Soda Constructor (Revisited)