#!/usr/bin/perl -w use strict; use Chart::Gnuplot; #======================== # Draw a Barnsley fern #======================== # Number of data points my $iter = 50000; # Prepare data my @x = my @y = (0); for (my $i = 1; $i < $iter; $i++) { my $rand = rand(); if ($rand < 0.01) { $x[$i] = 0; $y[$i] = 0.16 * $y[$i-1]; } elsif ($rand < 0.08) { $x[$i] = 0.2*$x[$i-1] - 0.26*$y[$i-1]; $y[$i] = 0.23*$x[$i-1] + 0.22*$y[$i-1] + 1.6; } elsif ($rand < 0.15) { $x[$i] = -0.15*$x[$i-1] + 0.28*$y[$i-1]; $y[$i] = 0.26*$x[$i-1] + 0.24*$y[$i-1] + 0.44; } else { $x[$i] = 0.85*$x[$i-1] + 0.04*$y[$i-1]; $y[$i] = -0.04*$x[$i-1] + 0.85*$y[$i-1] + 1.6; } } # Initiate the chart object my $chart = Chart::Gnuplot->new( output => 'advanced_1.png', size => 'square', ); $chart->command('set noborder'); $chart->command('set noxtics'); $chart->command('set noytics'); # Initiate the dataSet object my $data = Chart::Gnuplot::DataSet->new( xdata => \@x, ydata => \@y, style => 'points', pointtype => 'fill-circle', pointsize => '0.2', color => 'dark-green', ); # Plot the data $chart->plot2d($data);