ONO::Lib::PDF::Elements::Abacus

package ONO::Lib::PDF::Elements::Abacus;
################################################################################
# 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 abacus {

my (
$self,
$canvas,
$x,
$y,
$mode,
$op,
$num1,
$num2,
$switches,
) = @_;

#: This generates an abacus image.
#:
#: Switches:
#:
#: -C correction mode (BW)

my $count;

for (my $i = 0; $i < 10; $i++) {
my $c1 = 175+int(rand(25));
ONO::Lib::PDF::Draw->line($canvas,$x+1,$y+2+$i*3,$x+44,$y+2+$i*3,1,"0:$c1:$c1:$c1");
for (my $b = 0; $b < 10; $b++) {
$count++;
my $off_x;
my $c1 = 200+int(rand(40));
my $COL = "0:$c1:0:0";
if (($i < 5 && $b > 4) || ($i > 4 && $b < 5)) {
$COL = ONO::Lib::PDF::Draw->color_calc("0:0:0:$c1",20);
}
if ($mode eq "draw") {
$COL = "0:244:244:244";
} else {
if ((!$op || $op eq "count") && $num1 ne "") {
if ($count > $num1) {
$off_x = 11;
$COL = ONO::Lib::PDF::Draw->color_calc($COL,200);
}
}
}
if ($mode eq "write") {
if ($op eq "add") {
if ($count > $num1) {
$off_x = 8.25;
$COL = ONO::Lib::PDF::Draw->color_calc($COL,100);
}
if ($count > $num1+$num2) {
$COL = "0:244:244:244";
$off_x = 11;
}
}
if ($op eq "sub") {
if ($count > $num1-$num2) {
$off_x = 2.75;
$COL = ONO::Lib::PDF::Draw->color_calc($COL,175);
}
if ($count > $num1) {
$COL = "0:244:244:244";
$off_x = 11;
}
}
}

if ($switches =~ /C/ && $COL !~ /244:244:244/) {
$COL = "0:111:111:111";
if ($off_x) {
$COL = "0:188:188:188";
}
}

my $COL_DARK = ONO::Lib::PDF::Draw->color_calc($COL,-50);
ONO::Lib::PDF::Draw->circle($canvas,$x+4.5+$b*2.75+$off_x,$y+2+$i*3,1.15,0.75,$COL,$COL_DARK);
}
}

my ($c1,$c2,$c3) = (180+int(rand(40)),130+int(rand(40)),int(40));

if ($switches =~ /C/) {
($c1,$c2,$c3) = (222,222,222);
}

my $dark_wood = ONO::Lib::PDF::Draw->color_calc("0:$c1:$c2:$c3",-15);

ONO::Lib::PDF::Draw->rect($canvas,$x,$y,$x+2,$y+32,1,$dark_wood,"0:$c1:$c2:$c3",1);
ONO::Lib::PDF::Draw->rect($canvas,$x+43,$y,$x+45,$y+32,1,$dark_wood,"0:$c1:$c2:$c3",1);

}

###############################################################################
# end of script
###############################################################################

1;

__END__