SiD
By: a guest | Nov 24th, 2008 | Syntax:
Perl | Size: 4.46 KB | Hits: 58 | Expires: Never
#!/usr/bin/perl
# Mandelbrot Set
# Language: Perl
# Author: SiD
use Math::Complex;
use Tk;
$mx = -2; $my = -2;
$nx = 2; $ny = 2;
$mw = MainWindow -> new(-background => "Black");
$mw -> title("Mandelbrot Set Fractal ~ Author: SiD");
$mw -> minsize(215, 195);
$mw -> Label(
-background => "Black",
-foreground => "#00bfff",
-text => "Output image (name.ppm):"
) -> pack(-anchor
=> "n");
$mw -> Entry(
-background => "Black",
-foreground => "White",
-textvariable => \$out
) -> pack(-anchor
=> "n");
$mw -> Label(
-background => "Black",
-foreground => "#00bfff",
-text => "Height:"
) -> pack(-anchor
=> "n");
$mw -> Entry(
-background => "Black",
-foreground => "White",
-textvariable => \$alt
) -> pack(-anchor
=>"n");
$mw -> Label(
-background => "Black",
-foreground => "#00bfff",
-text => "Width:"
) -> pack(-anchor
=> "n");
$mw -> Entry(
-background => "Black",
-foreground => "White",
-textvariable => \$lar
) -> pack(-anchor
=>"n");
$mw -> Label(
-background => "Black",
-foreground => "#00bfff",
-text => "Precision (ex -> 150):"
) -> pack(-anchor
=> "n");
$mw -> Entry(
-background => "Black",
-foreground => "White",
-textvariable => \$precision
) -> pack(-anchor
=> "n");
$mw -> Label(
-background => "Black",
-foreground => "#00bfff",
-text => "Number of set (2-12):"
) -> pack(-anchor
=> "n");
$mw -> Entry(
-background => "Black",
-foreground => "White",
-textvariable => \$sets
) -> pack(-anchor
=> "n");
$mw -> Label(
-background => "Black",
-foreground => "White",
-text => "\nMandelbrot Set Fractal ~ Options\n"
) -> pack(-anchor
=> "n");
$vert = $mw -> Checkbutton(
-text => "Vertical Fractal?",
-onvalue => "Yes",
-offvalue => "No",
-activebackground => "Black",
-activeforeground => "Orange",
-background => "Black",
-foreground => "Orange",
-variable => \$how
) -> pack(-anchor
=> "sw");
$mw -> Radiobutton(
-text => "Red Background",
-value => "Red",
-activebackground => "Black",
-activeforeground => "Orange",
-background => "Black",
-foreground => "Orange",
-variable => \$background
) -> pack(-anchor
=> "sw");
$mw -> Radiobutton(
-text => "Black Background",
-value => "Black",
-activebackground => "Black",
-activeforeground => "Orange",
-background => "Black",
-foreground => "Orange",
-variable => \$background
) -> pack(-anchor
=> "sw");
$mw -> Button(
-text => "Generate Mandelbrot Set!",
-font => "Arial 8",
-activebackground => "Black",
-activeforeground => "Green",
-background => "Black",
-foreground => "Green",
-command =>
sub {
if($out !~ /.ppm/) {
$out = "mandelbrot.ppm";
}
if(!$background) {
$background = "Black";
}
if(!$sets) {
$sets = 2;
}
if($sets < 2 or $sets > 12) {
$sets = 2;
}
open(IMG
, ">", $out) or $mw -> destroy;
print IMG
"P3\n# Mandelbrot Set Fractal (Generator) ~ By SiD\n$alt $lar\n255\n";
for($y=0; $y<$lar; $y++) {
for($x=0; $x<$alt; $x++) {
if($how) {
$a = $mx+($y*($ny-$my)/$alt);
$b = $my+($x*($nx-$mx)/$lar);
}
else {
$a = $mx+($x*($ny-$my)/$alt);
$b = $my+($y*($nx-$mx)/$lar);
}
$comp = Math::Complex -> make($a, $b);
$comp1 = $comp;
for($p=0; $p<$precision; $p++) {
$comp1 = $comp1**$sets+$comp;
last;
}
}
_color($p);
}
if($^O =~ /MSWin32/) {
}
else {
}
}
sub _color() {
}
else {
if($background eq "Black") {
}
else {
}
if ($c1 > 116) {
$c1 = 116;
}
if ($c2 > 205) {
$c2 = 205;
}
if ($c3 > 255) {
$c3 = 255;
}
print IMG
"$c1 $c2 $c3\n";
}
}
$mw -> messageBox(
-message => "Done. \"$out\" created successfully!",
-type => "Ok"
);
$mw -> destroy();
}) -> pack(-side
=> "bottom");
MainLoop;