Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 3e84b65

Browse files
committed
test.pl checkerboard calc from size not hardcode
1 parent c004a05 commit 3e84b65

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test.pl

+9-4
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,20 @@ sub ourBuildTextures
454454
# Build texture from scratch if OpenGL::Image not available
455455
else
456456
{
457-
my $hole_size = 3300; # ~ == 57.45 ^ 2.
457+
my $hole_size = int(($Tex_Width / 2.2) ** 2);
458+
my $hole_border = int($hole_size/30);
459+
my $w_2 = $Tex_Width/2;
460+
my $w_4 = $Tex_Width/4;
461+
my $w_16 = $Tex_Width/16;
462+
my $w_32 = $Tex_Width/32;
458463
# Iterate across the texture array.
459464
for(my $y=0; $y<$Tex_Height; $y++)
460465
{
461466
for(my $x=0; $x<$Tex_Width; $x++)
462467
{
463468
# A simple repeating squares pattern.
464469
# Dark blue on white.
465-
if ( ( ($x+4)%32 < 8 ) && ( ($y+4)%32 < 8))
470+
if ( ( ($x+$w_32)%$w_4 < $w_16 ) && ( ($y+$w_32)%$w_4 < $w_16))
466471
{
467472
$tex .= pack "C3", 0,0,120; # Dark blue
468473
}
@@ -473,13 +478,13 @@ sub ourBuildTextures
473478

474479
# Make a round dot in the texture's alpha-channel.
475480
# Calculate distance to center (squared).
476-
my $t = ($x-64)*($x-64) + ($y-64)*($y-64);
481+
my $t = ($x-$w_2)*($x-$w_2) + ($y-$w_2)*($y-$w_2);
477482

478483
if ( $t < $hole_size)
479484
{
480485
$tex .= pack "C", 255; # The dot itself is opaque.
481486
}
482-
elsif ($t < $hole_size + 100)
487+
elsif ($t < $hole_size + $hole_border)
483488
{
484489
$tex .= pack "C", 128; # Give our dot an anti-aliased edge.
485490
}

0 commit comments

Comments
 (0)