Author Topic: Chladni Generation Information  (Read 2672 times)

0 Members and 1 Guest are viewing this topic.

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Chladni Generation Information
« on: December 16, 2006 »
Here is an explanation of how to build the alpha-blended chladni images that you can see in my program Chladni Generator. First, here are the chladni equations. These equations are exactly the same as mind posted on the forum, converted to Pascal.

Code: [Select]
x2 := ( cos( n*pi*x/L ) * cos( m*pi*y/L ) ) * 128;
y2 := ( cos( m*pi*x/L ) * cos( n*pi*y/L ) ) * 128;
cc := Round(x2 - y2);
if (cc < 0) then cc := 0;
if (cc > 255) then cc := 255;

M and N Values

The key values here are the M and N values. These define the pattern that the equations produce. The higher the M and N value, the more densely packed the pattern. Values over 30 aren’t really useful, and values less than or equal to 20 produce very nice images. If you limit the M and N values to 0 o 15 inclusive (which produces quite useable textures), you can pack the M and N values into the high and low nibble of a single byte.

You can produce a tileable texture by setting both M and N to even values. To produce a texture that contains a mirror image along a central axis (either vertical or horizontal), use odd M and N values. If M equals N, then a blank texture is produced.

X, Y and L Values

The x and y values are the current pixel location in the texture. The L value is the texture size; that is if L = 256, then the texture is 256*256 pixels. You can create rectangular textures, but they may not tile correctly.

X2, Y2 and CC Values

The X2 and Y2 values produced by the equations are subtracted to get the CC value, which is then adjusted if necessary to get a number from 0 to 255 inclusive. The number represents the height map of the texture. Since these values are constrained to a maximum value of 255, they can be represented by a byte value. If using byte values, the height map size would be L * L, with a single byte value representing the M and N values if constrained to a maximum value of 15. So the total size would be L * L + 1.

Color Map

The color maps in my program are integer arrays that range from 0 to 255. However, all you need to represent a color map is the start color value and the end color value and an interpolation function. The start and end colors would be integer values (4 bytes), or 8 bytes total. The program uses the linear interpolation code that Ratt posted on the forum, but you could use any type of interpolation method desired. The CC value generated from the equations is then used as a lookup index in the color map array and that color is plotted at the X and Y pixel of the texture.

Layers

To produce the fractal and layered images, generate the base chladni image as described above. Then iterate over the texture using new M and N values to produce a new CC value. Using the CC value, examine the height map and see if it has a 0 (or 255 or whatever value you desire) in the current X and Y location. If it does then save the CC value in the height-map:

Code: [Select]
if height_map (x, y) = 0 then  height_map(x, y) = cc
plot_pixel(x, y), color_map(cc)

You can iterate over the texture, as many times as you wish, but 6 iterations is usually the maximum value needed to fill out the texture. If you use a single color map for all layers you will get a Fractal Type 1 texture. If you use a different color map for each layer you will get a Fractal Type 2 texture.

Alpha Blending

The alpha-blended textures are generated as outlined above, with the addition of plotting the pixel as an alpha value, or RGBA value instead of an RGB value. The CC value is used both as a lookup index into the color map array, and as the alpha value of the plotted pixel. The color map corresponds to the RGB values, and the A value would be the CC value. This produces images that have depth to them since the alpha value is actually the height map value for the current pixel.

When using alpha blending the background color become a part of the texture color. A black background will produce darker images while a white background will produce lighter images, depending on the RGBA function being used. Generally, a darker background will produce an image with more depth, while a lighter background will produce flatter images.

This is the basic process to generate the chladni textures. It is quite simple and easy to implement, and can be generated using a small data set and code base.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Chladni Generation Information
« Reply #1 on: December 16, 2006 »
Brilliant little article.
Be sure I'll be using this in one form or another and expect greets!
Karma up (again!).
Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Chladni Generation Information
« Reply #2 on: December 16, 2006 »
Heh. Thanks!