Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Kings Dream

by snowsmann (Scribe)
on Mar 01, 2004 at 18:18 UTC ( #333005=sourcecode: print w/ replies, xml ) Need Help??

Category: Miscellaneous
Author/Contact Info snowsmann
Michael Haas
snowsmann@yahoo.com
Description: This is an implementation of the "King's Dream" found in the book Chaos in Wonderland by Clifford A. Pickover. It is a complex algorithm to realize some aspects of chaos theory. It creates some very beautiful pictures and this program has three of the infinite possibilites of cool images produced. My program also allows the user to select the resolution and how many iterations to repeat the set of equations while drawing. Any comments or suggestions would be welcome. Anyone think of a good way to use colors to make this look even cooler?
Update: btw, for all who either cant get image::magick to install or are too lazy to do it, here are some images produced by this program the default image produced big(7.45 meg) image, 10000x10000 with 1.5 million iterations a not so good attempt at color scemes(in case you were wondering, i am in fact somewhat color blind) i would like any suggestion on a better way to color-enable this program
use Image::Magick;

$x = 1;
$y = 1;
print "Welcome to the King's Dream.\n
1. To Draw the King's Dream.\n
2. To draw another cool picture.\n
3. To draw another diffrent cool picture.\n
4. To enter your own points to draw.\n Choice: ";
chomp($choice = <>);
if($choice==4){
print "A: ";chomp($a = <>);
print "B: ";chomp($b = <>);
print "C: ";chomp($c = <>);
print "D: ";chomp($d = <>);
}elsif($choice==2){
$a=-.942868;
$b=-1.934392;
$c=1.084818;
$d=1.015843;
}elsif($choice==3){
$a=-.9986501;
$b=-2.325941;
$c=1.016406;
$d=.7704654;
}else{
$a=-.966918;
$b=2.979879;
$c=.765145;
$d=.744728;
}
print "Enter the X resolution(enter for 1000): ";
chomp($xres = <>);
if(!$xres){$xres = 1000;}
print "Enter the Y resolution(enter for 1000): ";
chomp($yres = <>);
if(!$yres){$yres = 1000;}
print "Enter the number of iterations(enter for 40000): ";
chomp($iterations = <>);
if(!$iterations){$iterations = 40000;}
print "Enter file name(enter for kingsdream.jpg): ";
chomp($filename = <>);
if(!$filename){$filename = "kingsdream.jpg";}
$image = Image::Magick->new;
$image->Set(size=>"$xres"."x"."$yres");
$image->ReadImage('xc:black');
for($i = 1;$i<$iterations;$i++){
$xn = sin($y*$a) + $c*sin($x*$a);
$yn = sin($x*$b) + $d*sin($y*$b);
$x = $xn;
$y = $yn;
$xp = int($x*$xres/4 + $xres/2);
$yp = int($y*$yres/4 + $yres/2);
$image->Set("pixel[$xp,$yp]"=>"white");
}
$image->Write("$filename");
print "Done.";

Comment on Kings Dream
Download Code
Re: Kings Dream
by flyingmoose (Priest) on Mar 02, 2004 at 00:24 UTC
    As for color, perhaps you could somehow alter the color between each iteration, taking the modulus with 255 would work nicely for at least one color, and maybe you could alternate R/G/B between points. Dunno.

    Cool pics though!

Re: Kings Dream
by zentara (Archbishop) on Mar 02, 2004 at 15:03 UTC
    This seems like it could work with PDL and give you 3D images. Check out the examples here-> PDL screenshots. They have a contest to see who can make the coolest examples.

    I'm not really a human, but I play one on earth. flash japh
      How to you propose mapping his 2D points into the 3D space? That's non-trivial...unless perhaps the equations already have a Nth-dimensional variant.

      (Though I do agree the 3D OpenGL plotter from PDL is really awesome -- it puts Maple, Matlab, etc to shame)

        Probably some sort of parametric equations, like they show in the example 1, notice it all is derived from x and y
        $size = 25; $x = (xvals zeroes $size+1,$size+1) / $size; $y = (yvals zeroes $size+1,$size+1) / $size; $z = 0.5 + 0.5 * (sin($x*6.3) * sin($y*6.3)) ** 3; # Bumps imag3d [$x,$y,$z]; # Draw a shaded surface

        I'm not really a human, but I play one on earth. flash japh
      interesting idea for the PDL 3D graphics stuff, ive never used PDL before, and have been wanting to learn it, this could be a good time to learn some. ill try to come up with some sort of equations, perhaps like you suggested, and i think i have another idea for the 3D-ness of the image, something having to do with the concentration of points in a single area, ill try to post some code for comment/suggestion/flame/praise in the next few days
      ~michael

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://333005]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-07-29 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (217 votes), past polls