Posted by SiD on Mon 24 Nov 16:56
report abuse | download | new post
- #!/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):"
- $mw -> Entry(
- -background => "Black",
- -foreground => "White",
- -textvariable => \$out
- $mw -> Label(
- -background => "Black",
- -foreground => "#00bfff",
- -text => "Height:"
- $mw -> Entry(
- -background => "Black",
- -foreground => "White",
- -textvariable => \$alt
- $mw -> Label(
- -background => "Black",
- -foreground => "#00bfff",
- -text => "Width:"
- $mw -> Entry(
- -background => "Black",
- -foreground => "White",
- -textvariable => \$lar
- $mw -> Label(
- -background => "Black",
- -foreground => "#00bfff",
- -text => "Precision (ex -> 150):"
- $mw -> Entry(
- -background => "Black",
- -foreground => "White",
- -textvariable => \$precision
- $mw -> Label(
- -background => "Black",
- -foreground => "#00bfff",
- -text => "Number of set (2-12):"
- $mw -> Entry(
- -background => "Black",
- -foreground => "White",
- -textvariable => \$sets
- $mw -> Label(
- -background => "Black",
- -foreground => "White",
- -text => "\nMandelbrot Set Fractal ~ Options\n"
- $vert = $mw -> Checkbutton(
- -text => "Vertical Fractal?",
- -onvalue => "Yes",
- -offvalue => "No",
- -activebackground => "Black",
- -activeforeground => "Orange",
- -background => "Black",
- -foreground => "Orange",
- -variable => \$how
- $mw -> Radiobutton(
- -text => "Red Background",
- -value => "Red",
- -activebackground => "Black",
- -activeforeground => "Orange",
- -background => "Black",
- -foreground => "Orange",
- -variable => \$background
- $mw -> Radiobutton(
- -text => "Black Background",
- -value => "Black",
- -activebackground => "Black",
- -activeforeground => "Orange",
- -background => "Black",
- -foreground => "Orange",
- -variable => \$background
- $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;
- }
- 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() {
- print IMG "0 0 0\n";
- }
- 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();
- MainLoop;
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.