Skip to content

The Drawing Primitives

Saif Ahmed edited this page Dec 17, 2022 · 12 revisions

Taking advantage to the pseudo-pixel graphics capability, there are several commands available and a Turtle/Logo Graphics scripting.

Pixel level operations

$canvas->unset($x,$y, $value) Sets the pixel value at $x,$y if the $value is a ture value. If it is a colour then the pixel adopts the colour...BUT this colour bleeds into subsequent characters in the row....unless steps are taken to avoid this. It may be possible to address this at the cost of a reduced performance. For now Term::Graille does not do this

$canvas->unset($x,$y) Sets the pixel value at $x,$y to blank

$canvas->pixel($x,$y) Gets the pixel value at $x,$y

Shape primitives

$canvas->line($x1,$y1,$x2,$y2,$value) Uses Algorithm::Line::Bresenham to draw a line from $x1,$y1 to $x2,$y2. The optional value $value sets or unsets the pixels. If $value is a valid colour (see below) the line will be drawn with that colour.

$canvas->circle($x1,$y1,$radius,$value)
Uses Algorithm::Line::Bresenham to draw a circle centered at $x1,$y1 with radius $radius to $x2,$y2. The optional value $value sets or unsets the pixels. If $value is a valid colour (see below) the line will be drawn with that colour.

$canvas->ellipse_rect($x1,$y1,$x2,$y2,$value)
Uses Algorithm::Line::Bresenham to draw a rectangular ellipse, (an ellipse bounded by a rectangle defined by $x1,$y1,$x2,$y2). The optional value C<$value> sets or unsets the pixels. If $value is a valid colour (see below) the line will be drawn with that colour.

$canvas->quad_bezier($x1,$y1,$x2,$y2,$x3,$y3,$value)
Uses Algorithm::Line::Bresenham to draw a quadratic bezier, defined by end points $x1,$y1,$x3,$y3) and control point $x2,$y2. The optional value C<$value> sets or unsets the pixels. If C<$value> is a valid colour (see below) the line will be drawn with that colour.

$canvas->thick_line($x1,$y1,$x2,$y2,$thickness,$value)
Uses Algorithm::Line::Bresenham to draw a thick line, defined by end points $x1,$y1,$x2,$y2) and thickness $thickness. The optional value $value sets or unsets the pixels. If $value is a valid colour (see below) the line will be drawn with that colour.

$canvas->varthick_line($x0,$y0, $x1,$y1, $left,$argL, $right,$argR, $value); Uses Algorithm::Line::Bresenham to draw a variable thickness, defined by end points $x0,$y0,$x1,$y1) and thickness defined by two user defined functions, each function taking as arguments arg<L|R>, $pos, $len and returning thickness of the left and right sides of the line. The optional value $value sets or unsets the pixels. If C<$value> is a valid colour (see below) the line will be drawn with that colour.

$canvas->polyline($x1,$y1,....,$xn,$yn,$value) Uses Algorithm::Line::Bresenham to draw a poly line, form a sequences of points. The optional value $value sets or unsets the pixels. If $value is a valid colour (see below) the line will be drawn with that colour.

$canvas<blockBlit($block,$gridX, $gridY)> Allows blitting a 2d arrays to a grid location in the canvas. Useful for printing using a Graille font.