#!/usr/bin/perl
use strict;
use warnings;
use feature "say";
use Image::Imlib2;
use Math::Trig;
use Math::Round;
#my $y=0;
my $r=0;
my $g=10;
my $b=56;
my @points;
my $image = Image::Imlib2->new_transparent(16, 16);
$image->image_set_format("png");
#my $b1=0;
#my $g1=0;
#for(my $x=0;$x<=255;$x++){
#$b1  =int(((255-$b)/255)*(sqrt((255**2)-($x-255)**2))+$b);
#$g1  =int(((255-$g)/255)*(sqrt((255**2)-($x-255)**2))+$g);
#say "r= $x: g= $g1: b= $b1";

#}
#exit;

my $pixel=0;
for (my $i=0;$i<=14;$i++){
for (my $t=0;$t<=15;$t++){
$points[$i][$t]{red}=$pixel;
$points[$i][$t]{green}=int(((255-$g)/255)*(sqrt((255**2)-($pixel-255)**2))+$g);
$points[$i][$t]{blue}=int(((255-$b)/255)*(sqrt((255**2)-($pixel-255)**2))+$b);
$pixel++;
}
}

for (my $t=0;$t<=14;$t++){
$points[15][$t]{red}=$pixel;	 
$points[15][$t]{green}=int(((255-$g)/255)*(sqrt((255**2)-($pixel-255)**2))+$g);
$points[15][$t]{blue}=int(((255-$b)/255)*(sqrt((255**2)-($pixel-255)**2))+$b);
$pixel++;
}

#Save the array of pixels as an image
for (my $i=0;$i<=14;$i++){
for (my $t=0;$t<=15;$t++){
$points[$i][$t]{red}=round($points[$i][$t]{red});
$points[$i][$t]{blue}=round($points[$i][$t]{blue});
$points[$i][$t]{green}=round($points[$i][$t]{green});
$image->set_colour($points[$i][$t]{red},$points[$i][$t]{green},$points[$i][$t]{blue},255);
$image->draw_point($t,$i);
}
say "red:$points[$i][0]{red} blue:$points[$i][0]{blue} green:$points[$i][0]{green}";
}
for (my $t=0;$t<=14;$t++){
$image->set_colour($points[15][$t]{red},$points[15][$t]{green},$points[15][$t]{blue},255);
$image->draw_point($t,15);
}
#say "redS = $red_s blueS = $blue_s greenS = $green_s";
#say "\n";

my $save_name="$r:$g:$b.png";
my $save_file="palettes/$save_name";
if(! -d "./palettes"){mkdir "./palettes"}

$image->save("$save_file");

#End save the array of pixels as an image

	
