| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | Term::Graille - Graphical Display in the terminal using UTF8 Braille characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | my $canvas = Term::Graille->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | width => 72, # pixel width | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | height => 64, # pixel height | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | top=>3, # row position in terminal (optional,defaults to 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | left=>10, # column position (optional,defaults to 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | borderStyle => "double", # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | Inspired by Drawille by asciimoo, which has many variants (including | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | a perl variant Term::Drawille by RHOELZ), this is a clone with a few | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | extras. The goal is to achieve performance and features. with built-in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | turtle-like graphics, line and curve drawing (Algorithm::Line::Bresenham), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | scrolling, border setting, and more in development. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =begin html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | <img src="https://user-images.githubusercontent.com/34284663/177032294-55dfda02-c24d-45c8-92ab-8c07ad39df66.gif"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | =end html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | package Term::Graille; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | use strict;use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | our $VERSION="0.04"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | use open ":std", ":encoding(UTF-8)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use lib "../"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | our @EXPORT_OK = qw/colour paint printAt clearScreen border/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | use Algorithm::Line::Bresenham 0.13; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use Time::HiRes "sleep"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | =head2 C<my $canvas=Term::Graille-E<gt>new(%params)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | Creates a new canavas; params are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | C<width> The pixel width, required C<height> the pixel height, required, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | C<top> terminal row (optional,default 1) C<left> terminal column ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | optional,default 1) C<borderStyle> border type (optional,one of 'simple', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 'double', 'thin', 'thick' or 'shadow') C<borderColour> border colour ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | optional), C<title> Title text for top border,(optional) C<titleColour> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | Title colour (optional) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | sub new{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | my ( $class, %params ) = @_; # params are width and height in pixels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $self={width=>$params{width},height=>$params{height}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | for my $key (qw/borderStyle borderColour title titleColour top left/){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $self->{ $key}=$params{$key} if exists $params{$key} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $self->{top}//=1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"top"} //= 1
MC/DC0%0/1
$self->{"top"} //= 1
$self->{"top"}
Truth table0%0/2
A
A= $self->{"top"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | $self->{left}//=1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"left"} //= 1
MC/DC0%0/1
$self->{"left"} //= 1
$self->{"left"}
Truth table0%0/2
A
A= $self->{"left"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $self->{setPix}=[['⡀','⠄','⠂','⠁'],['⢀','⠠','⠐','⠈']]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $self->{unsetPix}=[['⢿','⣻','⣽','⣾'],['⡿','⣟','⣯','⣷']]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | $self->{logoVars}={x=>$self->{width}/2, # integrated Turtle Graphics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | y=>$self->{height}/2, # initial variables x, y and direction | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | d=>0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | p=>1}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | bless $self,$class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $self->clear; # initiallises canvas to blank | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | =head2 C<$canvas-E<gt>draw()> , C<$canvas-E<gt>draw($row, $column)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | Draws the canvas to the terminal window. Optional row and column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | parameters may be passed to position the displayed canvas. If | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | borderStyle is specified, the border is drawn, If title is specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | this is added to the top border | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | sub draw{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my ($self,$top,$left)=@_; # the location on the screen can be overridden by passing row coloum position | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
draw: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | $top//=$self->{top};$left//=$self->{left}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$top //= $self->{"top"}
$left //= $self->{"left"}
MC/DC0%0/2
$top //= $self->{"top"}
$top
$self->{"top"}
MC/DC0%0/2
$left //= $self->{"left"}
$left
$self->{"left"}
Truth table0%0/3
A //= B
A= $topB= $self->{"top"}
Truth table0%0/3
A //= B
A= $leftB= $self->{"left"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | border($top-1,$left-1,$top+@{$self->{grid}}-1,$left+@{$self->{grid}->[0]},$self->{borderStyle},$self->{borderColour}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if defined $self->{borderStyle}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | printAt($top-1,$left+3,paint($self->{title},$self->{titleColour})) if defined $self->{title}; ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | printAt($top,$left, [reverse @{$self->{grid}}]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | =head2 C<$canvas-E<gt>as_string()> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | Returns the string containing the canvas of utf8 braille symbols, rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | being separated by newline. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | sub as_string{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $str=""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $str.=join("",@$_)."\n" foreach (reverse @{$self->{grid}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =head2 C<$canvas-E<gt>set($x,$y,$pixelValue)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | Sets a particular pixel on (default if C<$pixelValue> not sent) or off. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | sub set{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | use integer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | push @_, 1 if @_ == 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=7 SCAR=40.3
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ($self,$x,$y,$value)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | #exit if out of bounds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return unless(($x<=$self->{width})&&($x>=0)&&($y<$self->{height})&&($y>=0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$x <= $self->{"width"} and $x >= 0 and $y < $self->{"height"} and $y >= 0
$x <= $self->{"width"} and $x >= 0 and $y < $self->{"height"}
$x <= $self->{"width"} and $x >= 0
MC/DC0%0/4
$x <= $self->{"width"} and $x >= 0 and $y < $self->{"height"} and $y >= 0
$x <= $self->{"width"}
$x >= 0
$y < $self->{"height"}
$y >= 0
Truth table0%0/5
A and B and C and D
A= $x <= $self->{"width"}B= $x >= 0C= $y < $self->{"height"}D= $y >= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | #convert coordinates to character / pixel offset position | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $chrX=$x/2;my $xOffset=$x- $chrX*2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $chrY=$y/4;my $yOffset=$y- $chrY*4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | $self->{grid}->[$chrY]->[$chrX]=$value? # if $value is false, unset, or else set pixel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | (chr( ord($self->{setPix} -> [$xOffset]->[$yOffset]) | ord($self->{grid}->[$chrY]->[$chrX]) ) ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | (chr( ord($self->{unsetPix}-> [$xOffset]->[$yOffset]) & ord($self->{grid}->[$chrY]->[$chrX]))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =head2 C<$canvas-E<gt>set($x,$y)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | Sets the pixel value at C<$x,$y> to blank | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | sub unset{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | my ($self,$x,$y)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $self->set($x,$y,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sub charOffset{ # gets the character grid position and offset within that character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # give the pixel position | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my ($self,$x,$y)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
charOffset: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | return undef unless(($x<$self->{width})&&($x>=0)&&($y<$self->{height})&&($x>=0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$x < $self->{"width"} and $x >= 0 and $y < $self->{"height"} and $x >= 0
$x < $self->{"width"} and $x >= 0 and $y < $self->{"height"}
$x < $self->{"width"} and $x >= 0
MC/DC0%0/4
$x < $self->{"width"} and $x >= 0 and $y < $self->{"height"} and $x >= 0
$x < $self->{"width"}
$x >= 0
$y < $self->{"height"}
$x >= 0
Truth table0%0/5
A and B and C and D
A= $x < $self->{"width"}B= $x >= 0C= $y < $self->{"height"}D= $x >= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $chrX=$x/2;my $xOffset=$x- $chrX*2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $chrY=$y/4;my $yOffset=$y- $chrY*4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | return ($chrX,$chrY,$xOffset,$yOffset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | =head2 C<$canvas-E<gt>pixel($x,$y)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | Gets the pixel value at C<$x,$y> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | sub pixel{ #get pixel value at coordinates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my ($self,$x,$y,$value)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pixel: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | #exit if out of bounds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return unless(($x<($self->{width}-1))&&($x>=0)&&($y<($self->{height}-1))&&($x>=0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$x < $self->{"width"} - 1 and $x >= 0 and $y < $self->{"height"} - 1 and $x >= 0
$x < $self->{"width"} - 1 and $x >= 0 and $y < $self->{"height"} - 1
$x < $self->{"width"} - 1 and $x >= 0
MC/DC0%0/4
$x < $self->{"width"} - 1 and $x >= 0 and $y < $self->{"height"} - 1 and $x >= 0
$x < $self->{"width"} - 1
$x >= 0
$y < $self->{"height"} - 1
$x >= 0
Truth table0%0/5
A and B and C and D
A= $x < $self->{"width"} - 1B= $x >= 0C= $y < $self->{"height"} - 1D= $x >= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | #convert coordinates to character / pixel offset position | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $chrX=$x/2;my $xOffset=$x- $chrX*2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $chrY=$y/4;my $yOffset=$y- $chrY*4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $orOp=ord($self->{setPix}-> [$xOffset]->[$yOffset]) & ord($self->{grid}->[$chrY]->[$chrX]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return $orOp == ord('⠀')?0:1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | =head2 C<$canvas-E<gt>clear()> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | Re-initialises the canvas with blank braille characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | sub clear{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | $self->{grid}=[map {[('⠀')x ($self->{width}/2+($self->{width}%2?1:0))]}(0..($self->{height}/4+($self->{height}%4?1:0)))]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # Pixel plotting primitives for shapes using Bresenham (Algorithm::Line::Bresenham) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | =head2 C<$canvas-E<gt>line($x1,$y1,$x2,$y2,$value)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | Uses Algorithm::Line::Bresenham to draw a line from C<$x1,$y1> to C<$x2,$y2>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | The optional value C<$value> sets or unsets the pixels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | sub line{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | push @_, 1 if @_ == 5; # final optional parameter is set to one if not given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my ($self,$x1,$y1,$x2,$y2,$value)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my @points=Algorithm::Line::Bresenham::line($x1,$y1,$x2,$y2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $self->set(@$_,$value) foreach (@points); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | =head2 C<$canvas-E<gt>circle($x1,$y1,$radius,$value)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | Uses Algorithm::Line::Bresenham to draw a circle centered at C<$x1,$y1> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | with radius C<$radius> to C<$x2,$y2>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | The optional value C<$value> sets or unsets the pixels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | sub circle{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | push @_, 1 if @_ == 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
circle: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my ($self,$x1,$y1,$radius,$value)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my @points=Algorithm::Line::Bresenham::circle($x1,$y1,$radius); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self->set(@$_,$value) foreach (@points); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | =head2 C<$canvas-E<gt>ellipse_rect($x1,$y1,$x2,$y2,$value)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | Uses Algorithm::Line::Bresenham to draw a rectangular ellipse, (an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ellipse bounded by a rectangle defined by C<$x1,$y1,$x2,$y2>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | The optional value C<$value> sets or unsets the pixels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | sub ellipse_rect{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | push @_, 1 if @_ == 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ellipse_rect: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my ($self,$x1,$y1,$x2,$y2,$value)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my @points=Algorithm::Line::Bresenham::ellipse_rect($x1,$y1,$x2,$y2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $self->set(@$_,$value) foreach (@points); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | =head2 C<$canvas-E<gt>quad_bezier($x1,$y1,$x2,$y2,$x3,$y3,$value)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | Uses Algorithm::Line::Bresenham to draw a quadratic bezier, defined by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | end points C<$x1,$y1,$x3,$y3>) and control point C<$x2,$y2>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | The optional value C<$value> sets or unsets the pixels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | sub quad_bezier{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | push @_, 1 if @_ == 7; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quad_bezier: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my ($self,$x1,$y1,$x2,$y2,$x3,$y3,$value)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my @points=Algorithm::Line::Bresenham::quad_bezier($x1,$y1,$x2,$y2,$x3,$y3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $self->set(@$_,$value) foreach (@points); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | =head2 C<$canvas-E<gt>polyline($x1,$y1,....,$xn,$yn,$value)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | Uses Algorithm::Line::Bresenham to draw a poly line, form a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | sequences of points. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | The optional value C<$value> sets or unsets the pixels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | sub polyline{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
polyline: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my @vertices=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | my $value= pop @vertices unless (@vertices & 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | $value//=1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$value //= 1
MC/DC0%0/1
$value //= 1
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my @points=Algorithm::Line::Bresenham::polyline(@vertices); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $self->set(@$_,$value) foreach (@points); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | sub degToRad{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | return 3.14159267*$_[0]/180 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
degToRad: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | =head2 C<$canvas-E<gt>scroll($direction,$wrap)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | Scrolls in C<$direction>. $direction may be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | "l", "left", "r","right", "u","up","d", "down". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | Beacuse of the use of Braille characters, up/down scrolling is 4 pixels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | at a time, whereas left right scrolling is 2 pixels at a time. If | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | C<$wrap> is a true value, the screen wraps around. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | sub scroll{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | my ($self,$direction,$wrap,$numberOfChar)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scroll: not called CC=16 SCAR=56.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | $numberOfChar//=1;$wrap//=0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$numberOfChar //= 1
$wrap //= 0
MC/DC0%0/1
$numberOfChar //= 1
$numberOfChar
MC/DC0%0/1
$wrap //= 0
$wrap
Truth table0%0/2
A
A= $numberOfChar
Truth table0%0/2
A
A= $wrap
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | for($direction){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | /^r/i && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | foreach my $row (0..$#{$self->{grid}}){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my @r=@{$self->{grid}->[$row]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $end=pop(@r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | unshift(@r,$wrap?$end:'⠀'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $self->{grid}->[$row]=\@r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | /^l/i && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | foreach my $row (0..$#{$self->{grid}}){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my @r=@{$self->{grid}->[$row]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $end=shift(@r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | push(@r,$wrap?$end:'⠀'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $self->{grid}->[$row]=\@r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | /^d/i && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my @r=@{$self->{grid}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $end=shift(@r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | push(@r,$wrap?$end:[('⠀')x ($self->{width}/2+($self->{width}%2?1:0))]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $self->{grid}=\@r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | /^u/i && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my @r=@{$self->{grid}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $end=pop(@r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | unshift(@r,$wrap?$end:[('⠀')x ($self->{width}/2+($self->{width}%2?1:0))]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $self->{grid}=\@r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | =head2 C<$canvas-E<gt>logo($script)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | Interface to Graille's built in Turtle interpreter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | A string is taken and split by senicolons or newlines into intsructions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | The instructions are trimmed, and split by the first space character into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | command and parameters. Very simple in other words. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | C<"fd distance"> pen moves forward a certain distance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | C<"lt angle">, C<"rt angle"> turns left or right. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | C<"bk distance"> pen moves back a certain distance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | C<"pu">, C<"pd"> Pen is up or down, up means no drawing takes place, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | and down means the turtle draws as it moves. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | C<"dir"> set the direction at a specific angle in dgrees, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | with 0 being directly left. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | C<"mv">moves pen to specific coordinates without drawing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | C<"ce"> centers the turtle in the middle of a canvas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | C<"sp"> allows animated drawing by specifiying the the number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | of centiseconds between instructions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | sub logo{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | my ($self,$script)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logo: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my @commands= map{s/^\s+|\s+$//g; $_}split(/[\n;]+/,$script); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | foreach my $instr (@commands){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | next if ($instr=~/#/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my ($c,$p)=split(/[\s]+/,$instr,2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | my @pars=split(/,/,$p) if $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | for ($c){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | /^fd/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my $x=$self->{logoVars}->{x}+$pars[0]*cos(degToRad($self->{logoVars}->{d})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $y=$self->{logoVars}->{y}+$pars[0]*sin(degToRad($self->{logoVars}->{d})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ($self->{logoVars}->{p}){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $self->line($self->{logoVars}->{x},$self->{logoVars}->{y},$x,$y) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $self->{logoVars}->{y}=$y; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $self->{logoVars}->{x}=$x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | /^lt/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $self->{logoVars}->{d}+=$pars[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | $self->{logoVars}->{d}-=360 while($self->{logoVars}->{d}>360); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | /^rt/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $self->{logoVars}->{d}-=$pars[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $self->{logoVars}->{d}+=360 while($self->{logoVars}->{d}<360); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | /^bk/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $pars[0]=-$pars[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $_="fd"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | redo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | /^pu/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $self->{logoVars}->{p}=0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | /^pd/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $self->{logoVars}->{p}=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | /^dir/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $self->{logoVars}->{d}=$pars[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | /^mv/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $self->{logoVars}->{x}=$pars[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $self->{logoVars}->{y}=$pars[1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | /^ce/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $self->{logoVars}->{x}=$self->{width}/2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | $self->{logoVars}->{y}=$self->{height}/2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | /^sp/ && do{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->{logoVars}->{sp}=$pars[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | if (defined $self->{logoVars}->{sp}){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | sleep $self->{logoVars}->{sp}/100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $self->draw(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | our %borders=( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | simple=>{tl=>"+", t=>"-", tr=>"+", l=>"|", r=>"|", bl=>"+", b=>"-", br=>"+",}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | double=>{tl=>"╔", t=>"═", tr=>"╗", l=>"║", r=>"║", bl=>"╚", b=>"═", br=>"╝",}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | shadow=>{tl=>"┌", t=>"─", tr=>"╖", l=>"│", r=>"║", bl=>"╘", b=>"═", br=>"╝",}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | thin =>{tl=>"┌", t=>"─", tr=>"┐", l=>"│", r=>"│", bl=>"└", b=>"─", br=>"┘",}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | thick =>{tl=>"┏", t=>"━", tr=>"┓", l=>"┃", r=>"┃", bl=>"┗", b=>"━", br=>"┛",}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | our %colours=(black =>30,red =>31,green =>32,yellow =>33,blue =>34,magenta =>35,cyan =>36,white =>37, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | on_black=>40,on_red=>41,on_green=>42,on_yellow=>43,on_blue=>44,on_magenta=>4,on_cyan=>46,on_white=>47, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | reset=>0, bold=>1, italic=>3, underline=>4, strikethrough=>9,); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | sub printAt{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | my ($row,$column,@textRows)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
printAt: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | @textRows = @{$textRows[0]} if ref $textRows[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my $blit="\033[?25l"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | $blit.= "\033[".$row++.";".$column."H".(ref $_?join("",@$_):$_) foreach (@textRows) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | print $blit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | print "\n"; # seems to flush the STDOUT buffer...if not then set $| to 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | sub border{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | my ($top,$left,$bottom,$right,$style,$colour)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
border: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | $style//="simple"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$style //= "simple"
MC/DC0%0/1
$style //= "simple"
$style
Truth table0%0/2
A
A= $style
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | return unless exists $borders{$style}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my @box=(colour($colour).$borders{$style}{tl}.($borders{$style}{t}x($right-$left)).$borders{$style}{tr}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | push @box,($borders{$style}{l}.(" "x($right-$left)).$borders{$style}{r})x($bottom-$top);; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | push @box,($borders{$style}{bl}.($borders{$style}{b}x($right-$left)).$borders{$style}{br}.colour("reset")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | printAt($top,$left,\@box); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | sub paint{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | my ($txt,$fmt)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paint: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | return $txt unless $fmt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | return colour($fmt).$txt.colour("reset") unless ref $txt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | return [map {colour($fmt).$_.colour("reset");} @$txt] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | sub clearScreen{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | system($^O eq 'MSWin32'?'cls':'clear'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clearScreen: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | sub colour{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | my ($fmts)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
colour: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | return "" unless $fmts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my @formats=map {lc $_} split / +/,$fmts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | return join "",map {defined $colours{$_}?"\033[$colours{$_}m":""} @formats; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||