ImageTools:-Draw Line Primitive
Line( image, x1, y1, x2, y2, color, thickness, round, pattern )
(optional) see description
(optional) numeric := 1.0
(optional) truefalse := false
(optional) identical("none", "solid", "dash", "dot", "dashdot", "dashdotdot") := "solid"
After first creating an image using ImageTools:-Create, or loading an image with ImageTools:-Read, drawing operations can be performed on it using a number of primitives (functions that draw one kind of object). The first argument to each primitive is the image itself, as returned by Create or Read.
The Line primitive draws a straight line between two specified points. The same result can be achieved using the Poly primitive with a list of two points, except that the line primitive also has the ability to draw tapered lines.
The x1, y1, x2, and y2 arguments give the coordinates of the end-points, (x1,y1) and (x2,y2).
The color argument can be specified in one of several forms:
A numeric value between 0 and 1 specifying a shade of gray. The value 0 corresponds to black, and 1 to white.
A list of three numeric values between 0 and 1 specifying the red, green, and blue components separately.
A list of four numeric values between 0 and 1 specifying the red, green, blue, and opacity (alpha) separately. When the opacity is less than 1, the color will be blended with the existing content of the image.
A value of type ColorTools:-Color.
Any form accepted by the ColorTools:-Color constructor, such as a string giving a color name (e.g. "red", palette and color name (e.g. "Niagara DarkOrchid"), or palette and color number (e.g. "Nautical 1"). Two argument forms are accepted as well, but then it is necessary to always use the keyword form of the color argument, since otherwise the two arguments will be interpreted as two separate arguments to the drawing primitive. For example, color=("HSV",[0.5,0.6,0.6]).
The thickness argument specifies the apparent thickness of the line, measured in pixels. Because of anti-aliasing, the number of pixels used to render the line at any point may be more than this, but the line will appear to be of the specified thickness.
Instead of a single thickness, a list of two separate thicknesses for the start and end of the line can be specified, producing a tapered line
By default, the line ends exactly at the specified coordinates, and for a line with thickness noticeably larger than 1, the ends of the line will be perpendicular to the line itself. If the round argument is specified as true, then the line ends will be rounded, and the specified end-points will be the centers of those rounded ends, i.e., the line will extend by half its thickness in all directions from the end-points
The pattern argument can be used to draw lines with one of a fixed number of patterns. The default pattern, solid, draws solid lines. The other available patterns are:
The options beginning with color are best provided as keyword equations, but can also be provided as positional arguments starting in the 6th position as declared in the calling sequence above.
This function is part of the ImageTools:-Draw package, so it can be used in the short form Line(..) only after executing the command with(ImageTools:-Draw). However, it can always be accessed through the long form of the command by using ImageTools:-Draw:-Line(..).
Lines of different thicknesses.
Round vs. square line ends.
Supporting Functions for the Examples
Draw a red crosshair centered at (x*scale,y*scale).
crossHair := proc( img :: Array, x :: numeric, y :: numeric, scale :: numeric )
Draw a background grid with specified interval.
gridFill := proc( img :: Array, interval :: numeric )
local x, y, w, h;
w, h := Width(img), Height(img);
for x from interval by interval while x < w do
for y from interval by interval while y < h do
Zoomed image of anti-aliased line with integer endpoints.
Zoomed image of anti-aliased line with non-integer endpoints.
Line pattern examples.
The ImageTools[Draw][Line] command was introduced in Maple 2018.
For more information on Maple 2018 changes, see Updates in Maple 2018.
Download Help Document
What kind of issue would you like to report? (Optional)