package ONO::Lib::PDF::Elements::Dice;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::Lib::PDF::Draw;
#: This module generates specific PDF content.
sub dice {
my (
$self,
$canvas,
$x,
$y,
$num,
$size,
$radius,
$color,
$dotcolor,
) = @_;
#: This generates a dice image.
eval "use PDF::Reuse";
if (!$@) {
if (!$radius) {
$radius = 1+int($size/5);
}
if ($color eq "") {
my $c1 = 50+int(rand(150));
my $c2 = 50+int(rand(150));
my $c3 = 50+int(rand(150));
$color = "0:$c1:$c2:$c3";
}
my $color2 = ONO::Lib::PDF::Draw->color_change($color,50);
my $color3 = ONO::Lib::PDF::Draw->color_change($color,50);
my $dotcolor1 = "0:244:244:244";
my $dotcolor2 = "0:222:222:222";
if ($dotcolor) {
$dotcolor1 = $dotcolor;
$dotcolor2 = ONO::Lib::PDF::Draw->color_change($dotcolor,-22);
}
my $dotsize = $size/12;
if ($num) {
ONO::Lib::PDF::Draw->rect($canvas,$x,$y,$x+$size,$y+$size,1,$color2,$color,$radius);
if ($num%2 != 0) {
ONO::Lib::PDF::Draw->circle($canvas,$x+$size/2,$y+$size/2,$dotsize,1,$dotcolor1,$dotcolor2);
}
if ($num%2 == 0 || $num == 5) {
ONO::Lib::PDF::Draw->circle($canvas,$x+$size/4,$y+$size/4,$dotsize,1,$dotcolor1,$dotcolor2);
ONO::Lib::PDF::Draw->circle($canvas,$x+$size/4*3,$y+$size/4*3,$dotsize,1,$dotcolor1,$dotcolor2);
}
if ($num > 2) {
ONO::Lib::PDF::Draw->circle($canvas,$x+$size/4*3,$y+$size/4,$dotsize,1,$dotcolor1,$dotcolor2);
ONO::Lib::PDF::Draw->circle($canvas,$x+$size/4,$y+$size/4*3,$dotsize,1,$dotcolor1,$dotcolor2);
}
if ($num > 5) {
ONO::Lib::PDF::Draw->circle($canvas,$x+$size/4,$y+$size/2,$dotsize,1,$dotcolor1,$dotcolor2);
ONO::Lib::PDF::Draw->circle($canvas,$x+$size/4*3,$y+$size/2,$dotsize,1,$dotcolor1,$dotcolor2);
}
} else {
ONO::Lib::PDF::Draw->rect($canvas,$x,$y,$x+$size,$y+$size,1,"0:22:22:22","0:244:244:244",$radius);
}
}
}
###############################################################################
# end of script
###############################################################################
1;
__END__