Closed Thread Icon

Preserved Topic: Another algorithm puzzle Pages that link to <a href="https://ozoneasylum.com/backlink?for=18135" title="Pages that link to Preserved Topic: Another algorithm puzzle" rel="nofollow" >Preserved Topic: Another algorithm puzzle\

 
Author Thread
Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-11-2001 18:53

Just last night I worked very hard at this, and although it took an hour or so, I was very proud of myself, I got this algorithm to work on the *first* run-through, except for some syntax errors. So it made me happy. But now I challenge you all with it.

Plasma Fractals

Take an image of dimensions 1025 x 1025 (or any power of two plus 1) , and set the four corners of it to a random greyscale value from zero to one. (well, you could use 0 to 255, but let's just keep things simple for the sake of explanation.) Now the four corners are each their own random values.

Take each of the points in the middle of the sides of the square. Note that these points are each surrounded by two corners. To find the value of each of these side points, average the two values on either side of it, *and* another random value. So this point's value is the one on one side of it plus the one on the other side of it plus a random number from 0 to 1 all divided by three.

OK, now you have all these points defined:

*  *  *

*      *

*  *  *

Now take the point in the middle. Make its value the value of the four points surrounding it plus two other random values, all divided by six.

Now you have this:
*  *  *

*  *  *

*  *  *

Note that there are now four squares, each with four pre-defined corners. For each of those squares, do the same thing you did for the big one, and then do it again to the smaller squares, and again and again until the whole image is defined. The end result can look something like this:


(generated by Fractint)

(note: I'm not sure, but I believe this is the logic behind the clouds filter in photoshop. It also makes great terrain height maps for 3D programs. But that's not the point here.)

Oh, one more thing I didn't tell you. As you get further into the image, you know that random value you keep averaging in? You have to average it in less. What i mean is, for the first time, you averaged the surrounding values plus one random value and divided by three. The next time, you instead want to average the surrounding values and then another random value *multiplied by .5*, and then divide by 2.5, so that as you get in deeper, there is less randomness.

OK, I'm not asking you to do that (unless you're feeling very ambitious). I'm asking you to do this:

Consider the top row of pixels in this image. It is, essentially, a one dimensional plasma fractal. Write a program in whatever language you prefer that will create a one dimensional plasma fractal and store it in an array of size n, where n is 2^a + 1, and a is any positive integer.

You may want to use a language with some graphical capabilities so that you can graphically output your data and be sure it's working right.

(You may wonder why I did this. I did it to create a wave file, defined by a 1-D plasma fractal. It ended up sounding just like static, sadly.)

Good luck, if you're in the mood. =)

[This message has been edited by Slime (edited 06-11-2001).]

linear
Paranoid (IV) Inmate

From: other places
Insane since: Mar 2001

posted posted 06-12-2001 18:41

Don't worry Slime, just generate an infinite amount of those and you're bound to get some Beethoven.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-13-2001 00:56

Heh, few replies, I see. Oh, well. I got this to sound interesting, by the way. Sort of weird though.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-13-2001 02:13

We're all contemplating

-mage-

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-13-2001 14:55

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-13-2001 16:34

My friend once used a 4D plasma fractal to create a very realistic 3D fire effect. It was cool.

linear
Paranoid (IV) Inmate

From: other places
Insane since: Mar 2001

posted posted 06-13-2001 17:42

I once used a Zippo and a can of....

Oh, "effect," I get it.

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 06-13-2001 21:36

This is probably not the best algorithm for doing this. It gets really s l o o o w as the dimension get big, but, I like playing with recursive algorithms.


<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
#! /usr/bin/perl

use Getopt::Long;

my $n = 4;
my $m = 3;
my @area = ();

my ($x_min, $x_max);
my ($y_min, $y_max);
my ($min_color, $max_color) = (0, 255);
my ($indx, $jndx);

GetOptions("h

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-13-2001 22:20

woah! that's long. I'll have to try running it later, but i gg now...

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-15-2001 12:57

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

keystroke
Nervous Wreck (II) Inmate

From: TX, USA
Insane since: Jun 2001

posted posted 06-21-2001 17:47

Holy cow! And I thought I was good at reading obfuscated perl. j/k

Your program will create nonrandom patterns of light points on a dark
background because you are using your factor wrong. You should
decrease the random value's effect on the output by increasing the
number of times you count the real points. That sentence probably
doesn't make sense. Hey I know what I mean. The way you are using
the factor in your program is actually making the pixel value darker
the further recursive in the program it gets.

instead of using the factor like you did:

code:
$area[$x2][$y2]    = (
$area[$x_min][$y_min]
+ $area[$x_max][$y_min]
+ $area[$x_min][$y_max]
+ $area[$x_max][$y_max]
+ ($factor * Random_Pixel())
) / 5;


which will create something like

(output of your program converted to a gif.)

you should do something like

code:
$area[$x2][$y2]    = ( $factor * (
$area[$x_min][$y_min]
+ $area[$x_max][$y_min]
+ $area[$x_min][$y_max]
+ $area[$x_max][$y_max])
+ Random_Pixel()
) / 1 + (4 * $factor);


The 1+4*$factor is 1 for the random pixel and 4 * the factor for the
other 4 points. Your factor value should increase the deeper it
gets/the more the subroutine is called.

Here is my version http://members.fortunecity.com/keystroke/tmp/clouds.txt
and a couple of output images.




/<eystroke



[This message has been edited by keystroke (edited 06-21-2001).]

« BackwardsOnwards »

Show Forum Drop Down Menu