Pirate Fractal

(c) Earl Hinrichs

Pirate Fractal

Nerd Level: Medium This fractal uses a formula I played with a lot, many years ago. I call it the Pirate Formula. I am not sure why I called it that. Nor am I sure that I remember it correctly. Here is the formula in C#:

(z, c) => {
  var a = z * z + c;
  return new Complex(a.Real, Math.Sin(a.Imaginary));

It is the usual z*z+c, but with the imaginary part of the result replaced with its sin(). Mathematically, this formula is not very useful. It is a continuous function, that is good, however, it is not analytical. You can use it to draw pictures, and I suppose technically you can call the result a fractal. However fractal pictures associated with z*z+c and similar formulas have important mathematical meaning; they show the points which have connected Julia sets. (Don’t worry if you don’t know or care what a Julia set is. Gaston Julia found them interesting in 1918, as have many other mathematicians since them.)

Still, it can be fun to play with these non-analytical functions. Usually the pictures are just a mess, it takes more effort to find something interesting. Notice the distored mini-brot and the extra tendrils in this image.

Exif, jpg, and .net

Fractal 2228. (c) Earl Hinrichs

Nerd Level: High Today’s fractal is the result of playing around with the 4D color scheme I blogged about last week. The color scheme still requires way too much effort to get a reasonable result, but I have not given up on it yet.

Today’s topic is exif, jpeg, and .net.

Exif is a way of storing metadata inside jpeg files. I wanted to add exif or similar information to my images. I often lose track of the files on my hard drive, and then rediscover them later. It would be nice if these forgotten images had some information with them. The metadata will also stay with the image if it gets separated from the original post on the internet.

Adding exif metadata to the image should be a simple task. It is not. Well, to be accurate, it is simple, but not at all obvious. I will avoid boring you with the play by play, and just list some of the highlights.

My program is written in C# / .Net 4.0. Don’t bother looking in the msdn .net documentation. Exif is mentioned a few times, just enough to make you think you are on the right track, but it leads nowhere.

OK, perhaps I could post-process the image with a third party utility. I found several exif readers, but few writers. Almost all of the writers involved decompressing the jpeg image, adding the tags, and recompressing the image. With jpeg there is a loss of quality in every decode/encode cycle. I did some tests, the loss was not visually noticeable, but I knew it was there and that was unacceptable. It turns out you can change the exif information only if there is exif information in the original image, and the new information is “smaller”. That did not work for me.

OK, back to DIY. I can read the spec and twiddle the bits myself. exif spec. What? 150 pages just to attach a few strings to a jpeg? OK, exif is a lot more than a few strings and a copyright notice. It is obviously designed by a committee where everyone insisted that it be backwards compatible to many pre-existing non-standard “standards”. This is getting way too complicated. Maybe I should just give up on the idea and get better at keeping track of the files.

Back to .Net. Now you won’t find something clearly described as “Exif Tags”. However .Net does have a BitmapEncoder base class with many specific derived classes for the common image formats, jpeg, tiff, png, bmp, etc. It does make some sense to abstract out the format details. Bitmap.SaveAsJpg would be too obvious. The BitmapEncoder base class works with frames. Some formats have frames, so the concept is built into the base class. Jpg does not have frames, so it is just confusing and useless in that case. But that is the price to pay for the generalization.

Next there is a BitmapMetadata class. BitmapMetadata is also an abstraction which hides the details of how the data is formatted. OK, that is a nice design idea, but for me at least, it is not an obvious place to look first. The msdn documentation for the BitmapMetadata constructor lists four supported formats, gif, jpg, png, tiff. However there is an example which includes exif. I was unable to get the exif example to work, but specifying jpg format for the metadata got the job done.

Here is the source code. If you happen to be writing an application in .Net, and if you just happen to be wondering how to put exif information into a jpg, I hope this saves you some time. Or if you are a programmer, perhaps you can show me a better way to do this. (The code creates two files, full size and thumbnail. And obviously I would not hard-code my name if I ever share the program.)

void JpgSave( BitmapSource source, string file ) {
  JpegBitmapEncoder encoder = new JpegBitmapEncoder();
  encoder.QualityLevel = 90;
  var scale = 100.0 / source.Width;
  var thumb = new TransformedBitmap(source, new ScaleTransform(scale, scale));
  var colorContext = new ReadOnlyCollection( new ColorContext[] {new ColorContext(source.Format)});
  var metadata = new BitmapMetadata("jpg");
  metadata.DateTaken = DateTime.Now.ToString();
  metadata.Copyright = "2013 Earl Hinrichs";
  metadata.ApplicationName = "ComputerArt";
  metadata.Author = new ReadOnlyCollection( new List() {"Earl Hinrichs"} );
  metadata.Subject = "Computer Art";
  metadata.Comment = "Computer Generated Art";
  metadata.Keywords = new ReadOnlyCollection( new List() {"Fractal", "Computer Generated" } );
  encoder.Frames.Add(BitmapFrame.Create(source,thumb,metadata, colorContext ));
  using(var stream = new FileStream(file, FileMode.CreateNew)) {
  encoder = new JpegBitmapEncoder();
  encoder.QualityLevel = 90;
  encoder.Frames.Add(BitmapFrame.Create(thumb,null, metadata,colorContext));
  var thumbFile = file.Replace(".jpg", "_thumb.jpg");
  using(var stream = new FileStream(thumbFile, FileMode.CreateNew)) {

4D Colors

4D Color Fractal Image

Image copyright 2012 Earl Hinrichs

Nerd Level: Medium. Today’s fractal uses a coloring method that I call 4D Colors. The fractal calculation is still 2D; the pixels on the screen correspond to a rectangular section of the 2D complex plane. Colors are 3D, the three red, green, blue components on your computer screen, which roughly maps to the three (S,M,L) types of cones in your eye.

The reason this is called 4D coloring is due to the way the colors are calculated. The typical fractal calculation produces a single number, the escape count. That number is then converted to a full 3D color, either by a direct calculation or by a look up table. The key is that the handoff from the fractal calculation to the coloring function is a single real number.

Here, the fractal calculation produces four real numbers, actually two complex numbers, for each pixel. The four numbers are the input into the coloring function. The 4D Coloring refers to the number of inputs to the coloring function.

I will provide the implementation details in a later post.

The idea, or hope, is that since the input space is one dimension larger than the output space, this scheme will provide much more flexibility for coloring functions.

You may not see any difference yet. That is ok, the difference, if any will be subtle. The intent, at least most of the time, is that the color enhances the fractal shape, and does not overwhelm it.

The current set up has about thirty parameters that define the 4D color function. And that is just the start. There is a general affine transformation on four variables (twenty parameters). Then there are a few parameters for some non-linear steps intended to “tame infinity”. (Similar to first applying a log or a log-log function in the 1D case.) The result is then projected to 3D space, and three different sin functions (each with parameters controlling frequency and phase) generate the RGB color values.

Needless to say, there are way too many parameters to keep track of. Mostly it seems like making random changes and getting random results. You cannot easily fine-tune this beast. By contrast, a simple color palette with linear interpolation between just a few fixed colors for the 1D case may have fewer options, but you have a good idea what the results will look like.

Individually tweaking the huge number of parameters for the 4D color case is not the end game. It is only the first step, and a fallback option later on. I plan on creating an interface which take higher level commands, such as rotate colors 10 degrees, move the origin, more/fewer colors, more/less of a specific color, more/less contrast, etc. and then programmatically tweak the individual parameters to produce the desired effect.

Torus Fractal

Torus Fractal

Torus Fractal

Nerd Content: Low.

I call these Torus Fractals. Look closely at the edges of this fractal. Notice that the top and bottom match. By that I mean that shapes and colors along the top edge are continued on the bottom. The same is true for the left and right edges.

You can download image and set it as your desktop background with the “tile” option on. The edges will fit together seamlessly, creating one continuous scene.

Image that the image is printed on a sheet of paper, or better yet on a piece of stretchy rubber. Grab the left side and move it over so that it lines up with the right side. You now have a tube with a continuous image wrapped around it. Next grab the top of the tube and move it so it abuts the bottom. You now have a donut shape with a fractal painted on the surface.

The mathematical name for the shape of the surface of a donut is called a torus. For more information about the mathematics see Wikipedia http://en.wikipedia.org/wiki/Torus.

Image was created on 2012-04-29. Copyright Earl Hinrichs.

How Is It Going?

How Do You Do
I have been busy with this project, even if it does not show on the posts. I have a lot of unposted new art on my hard drive. And I have plenty of topics that I want to write about. The problem is that I feel that every image I post must be a masterpiece. Every blog entry must contain a brilliant insight.

There are things I do not like with the blog format. The focus should be on the images, not on the my writings. The web site needs to be a gallery motif, with the blog secondary. Also the images must be put into ascetically pleasing groups.

When I worry about all those things, nothing gets posted.

Currently the web site is set up as a blog and blogs do not work that way. I need to accept that. When I read someone else’s blog, I do not expect each post to be as well designed and thought out as a Ph.D. thesis. I am looking for something quick and disposable. If something sticks with me then great. If not, it is like a short visit with a friend, where even a meaningless “How are you doing?” generates a pleasant feeling.

I need to get in the habit of writing daily, or more realistically once or twice a week. Whether I have something profound to write or not. Maybe with practice I can get good at making the mundane seem interesting.

I do not know much about today’s fractal. I can tell by the date on the file that I created it last April. Obviously it contains many bright colors. It has been patiently waiting on my hard drive to get uploaded to the web.

See you tomorrow.

Fire Fractal

Fire Fractal Art Image

Fire Fractal

More messing around with word press. I am going to try to use this fractal image as a brackground for the header section.

Testing Image Post

Colorful fractal test image

Colorful fractal test image

This is a test post. I am experimenting with themes and stuff. I know, I should try this out on a test set up first. I am just lazy, and I want to see how the changes work with real posts. Sorry for the distraction. But it is still a cool picture, and someday I should put it into a real post.


Dragon fractal

Dragon Fractal

Old Site
I was scrapping an old computer, and I wanted to wipe the hard drive. As I was checking for files to save, I found this picture. I created the image ten years ago, 2002. It was on the old spyke.com web site then. The hard drive also contained most of the files from that web site. I am working on recreating the web site. I have plenty of bandwidth and storage space here, the only limitation is finding the time to clean up the html and upload the files. You can view the main gallery page, with six pictures from the Dragon series at http://computerart.org/index.html. Currently only the dragon gallery is on line. I will be adding the others as time permits.

Spam in comments

This is depressing. I have deleted 2000 spam comments. If I was overzealous and deleted your non-spam comment I apologize. Please send me an email at artadmin_at_spyke_dot_com. (I hope the spam bots are not able to translate the email address.)

I was about to give up on the comments entirely, and perhaps wordpress as well, then I found a wordpress spam killing service, Akismet. I signed up for the personal use / free trial version. We will see how it works.

Please send me a real comment, anything, even “you suck”. Actually that would be quite welcome. The typical pattern for spam is “Your blog is amazing, you are a great writer and I am inspired. Please visit my blog at www.freeviagra.com”.

There is a subtle difference in this one. This one is based on the formula c*cos z instead of the traditional z*z+c. It does not make much difference, but notice that the thorns poking out from the spirals are longer and sharper.