SiD
By: a guest | Nov 23rd, 2008 | Syntax:
Perl | Size: 3.81 KB | Hits: 108 | 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 ~ By SiD");
$mw -> minsize(185, 165);
$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 -> 256):"
) -> pack(-anchor
=> "n");
$mw -> Entry(
-background => "Black",
-foreground => "White",
-textvariable => \$precision
) -> pack(-anchor
=> "n");
$mw -> Radiobutton(
-text => "Vertical Fractal?",
-value => "Vertical Fractal?",
-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";
}
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*$comp1+$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 -> destroy;
}) -> pack(-anchor
=> "s");
MainLoop;