Wednesday, 8 October 2014

I noticed wikipedia has a new visualization for the Riemann zeta function. However I'm not sure it's quite best way to show it in every case. This is how it looks:

http://en.wikipedia.org/wiki/Riemann_zeta_function

This is a complex function so each point in 2D-plane has phase and amplitude. In the domain coloring scheme the phase is represented by hue (color) and amplitude by value (intensity). This particular image has some modulo coloring of the amplitude etc. and the difference can be most easily seen by comparing it to these 3D-plots I made where the hue independently represents the phase and amplitude is simply represented by the 3rd dimension.

The second image has phase exaggerated quite a lot to make it clear that for these values the true change of phase is quite different from what it appears in the wikipedia image.

While I was at it, I also plotted the Mandelbrot fractal in terms of the complex value after iteration instead of number of iterations as it's usually done. This too resulted in a rather trippy image. Though obviously hue coloring tends to always results in rather trippy images.

Here hue represents phase angle of the complex number and value (intensity) the amplitude. 3D representation is also rather interesting.

Here only hue is varied.

N = 1024;

s = zeros(N, N);

for y = 1:N

for x = 1:N

z0 = (6*x/N-3.5) + j*(6*y/N-3);

z = 0;

iteration = 0;

max_iteration = 256;

while norm(z) < 8 && iteration < max_iteration

z = z^2 + z0;

iteration = iteration + 1;

end

s(x, y) = log(iteration);

S(x, y) = z;

end

end

figure;

imagesc(s);

truesize;

colormap(hot(256));

h = angle(S);

h = h-min(min(h));

h = h/max(max(h));

v = abs(S);

hsv(:,:,1) = h;

hsv(:,:,2) = 1;

hsv(:,:,3) = 1;

% hsv(:,:,3) = v/max(max(v));

rgb = hsv2rgb(hsv);

figure;

x = 6*[1:N]/N-3.5;

y = 6*[1:N]/N-3;

surf(x, y, v, rgb, 'edgecolor', 'none');

shading interp;

figure;

image(x, y, rgb);

imwrite(rgb, 'compmand.png', 'png')

How to test shaders with minimal effort on OSX (though it'll work with relatively minor changes on linux as well)...

Looks like one can save 4 bytes in the gzip header technique by just leaving last 4 out. They are crc-32, so they aren't really needed. It'll say truncated input, but works just fine. Previous code gives 675 byte executable (Mac).