#!usr/bin/perl #use strict; sub bmp { my ($width, $height, $zoom, $function, $min, $max, $r) = @_; my $Graph; $err = &error(@_);return (0,$err) if $err; my $instructions = &translate($function, $zoom); return (0,"Error in Function") unless $instructions; my ($color1, $color2,$Graph); my ($off_1, $off_2) = (int($height/2+.5), int($width/2+.5)); for (my $x=0; $x<=$max-$min; $x=$x+$r) { for (my $y=0; $y<=$max-$min; $y=$y+$r) { my ($R, $C) = &map($x+$min,$y+$min, $instructions); ($C, $R) = (int($C+$off_1+.5), int($R+$off_2+.5)); #Offset. next if ($C < 0 || $R < 0); $color1 = (($x>=-1*$min) ? 1 : 3); $color2 = (($y>=-1*$min) ? 0 : 1); push ( @{$Graph->[$C]->[$R]} , ($x==-1*$min || $y==-1*$min) ? 5 : $color1 + $color2 ); #print scalar(@{$Graph->[$C]->[$R]})."\t"; #Now an Array!? } } return $Graph; } #Technical Subroutines sub error { my ($w, $h, $z, $f, $min, $max, $step) = @_; my @Array = ("Improper Width or Height","Invalid Function Specified", "Improper Min/Max", "Step is too extreme"); return $Array[0] if ($w > 2000 || $h > 1600 || $h < 0 || $w< 0); return $Array[1] if ($f !~ /z/i && $f !~ /^[\d\.]+$/); return $Array[2] if ($max<$min); return $Array[3] if ($step > 100 || $step < .01); return 0; } sub disp { my @Total; my $n = scalar(@_); for (my $x=0; $x<$n; $x++) { my @Colors=(0,0,0); $Colors[($_[$x]+1)%3] = 255 if ($_[$x] && $_[$x] <= 3); #Big endian or little endian? @Colors=(255,255,255) if $_[$x]==5; #White @Colors=(0,255,255) if $_[$x]==4; #Yellow for (my $y=0; $y<3; $y++) { $Total[$y]+=$Colors[$y]; $Total[$y]=$Total[$y]%256 if ($x==$n-1); # %256 Method #$Total[$y]=int($Total[$y]/$n +.5) if ($x==$n-1) # 1/$n Method } } print $n." : ".join ('-', @Total)."\n" if $n != 1; return pack ("c3", @Total); } sub translate { $_[0]=~s/ //g; my @PlusMinus = $_[0] =~ /(\+|-)/g; my @Terms = split (/(?:\+|-)/, $_[0]); my $first_minus; if ($_[0] =~ /^-/) { shift (@Terms);$first_minus=shift(@PlusMinus); } my $n = scalar(@Terms); my $sub= ($n>1) ? '&VA([' : ''; for (my $x=0; $x<$n; $x++) { print "$x : $Terms[$x]\t"; my ($m,$p) = $Terms[$x] =~ /(.*?|)(?:\*|)z(?:\^|)(.*)/i; $p = 1 if (!$p && $Terms[$x] =~ /z/); print " m = $m : p = $p\n"; my $sub_temp; my $c = (($x==0 && $first_minus) || ($x>0 && $PlusMinus[$x-1] eq '-')) ? -1 : 1; foreach ($m, $p) { if ($_ =~ /(?:\/|\*)/) { my ($o) = $_ =~ /(\/|\*)/; my ($a, $b) = $_ =~ /(.*)$o(.*)/; if ($b) { $_ = ($o eq '/') ? $a/$b:$a*$b; #$_ = sprintf("%.5g", $_); #Not sure if this iwll help. } else { #"Dividing by 0 will take considerable time to compute. Please wait."; return 0; } } } if ($p) { $p=~ s/[^\d\.]//g and $p=int($p+.5) if $p !~ /^\d+$/; $m=1 if !$m; $sub_temp = ($p!=1) ? '&power('.$p.', $_[0] , $_[1])' : '$_[0], $_[1]'; if ($m) { $sub_temp = '&SM('.$c*$m.', '.$sub_temp.')' unless ($c*$m==1); } } else { $sub_temp.=$c*$Terms[$x].', 0'; } $sub.= ($n > 1) ? $sub_temp.'],[' : $sub_temp.','; } $sub =~ s/,(?:\[|)$//; $sub = '&SM('.$_[1].','.$sub.')' unless $_[1] == 1; $sub = "(".$sub.")" if ($sub !~ /(?:\(|\))/); $sub = ($n>1) ? $sub.');' : $sub.';'; print STDOUT "$sub\n"; #chomp($_ = );exit if $_ eq "q"; return ($internet) ? &dummy($internet, $sub) : $sub; } #Internet Version sub dummy { open FILE, ">$_[0]" or return "There is an error."; print FILE "#!/usr/bin/perl\n"; print FILE "sub dummy{\nreturn ".$_[1]."\n}"; print FILE "1;"; close FILE; require "$_[0]"; return $_[0]; } # ** Warning ** #Mathematics Below # ** ** ** ** ** sub map { return ($internet) ? &dummy($_[0], $_[1]) : eval $_[2]; } # Vector/Scalar Addition/Multiplication respectively sub VM { return ($_[0][0]*$_[1][0] - $_[1][1]*$_[0][1], $_[0][1]*$_[1][0] + $_[1][1]*$_[0][0]); } sub SM { return ($_[0]*$_[1], $_[0]*$_[2]); } sub SA { return ($_[1]+$_[0], $_[2]); } sub VA { my ($a, $b) = ($_[0][0] , $_[0][1]); for (my $x=0; $x