pl2 = Graphics.Add(pl, Element1, Element2, …, Options) returns a copy of the Graphics object pl with lines, curves, arcs, texts, bitmaps or other Graphics objects added to it; pl itself stays as it is. pl.Add(Element1, Element2, …, Options) adds them to pl itself and returns nothing.
A point is given as {x, y}, a fraction of the width and of the height of the page: (0,0) is the lower left and (1,1) the upper right corner. Widths of lines, radii and the height of texts are fractions of $\sqrt{\mathrm{width} \cdot \mathrm{height}}$ of the page, so that a circle stays round on a page of any shape.
Within one Graphics object the bitmaps are drawn first, then the lines, the curves, the arcs and the texts, each in the order in which they were added. The layers are drawn after that, so a bitmap that should lie on top of a line is put in a layer. A grey background below other bitmaps is a bitmap of one pixel, {“BitMap”, {0,0}, {1,1}, { {224} }}, added first.
A line, a filled triangle, a curve, a circle, a quarter of a disc, a bitmap, two texts and a layer on an A4 page.
-- an empty page, A4 in landscape; a point {x, y} is a fraction of the width and the height of the page pl = Graphics.New() -- a line through three points, 0.004 wide, blue pl.Add({ {0.05,0.55}, {0.15,0.9}, {0.25,0.55} }, {{"Line Width",0.004}, {"Color",0x0000C0}}) -- a closed triangle, filled with a half transparent red pl.Add({ {0.3,0.55}, {0.4,0.9}, {0.5,0.55} }, {{"Close",true}, {"Fill Color",0x80FF0000}}) -- a curve of two pieces; each point is {xL,yL, x,y, xR,yR}, with the control points before and after it pl.Add({ {0.55,0.55, 0.55,0.55, 0.55,0.9}, {0.65,0.9, 0.75,0.9, 0.85,0.9}, {0.95,0.55, 0.95,0.55, 0.95,0.55} }, {{"Line Width",0.004}, {"Color",0x00A000}}) -- a circle, and a quarter of a disc from 0 to 90 degrees, closed through its centre and filled pl.Add({"Arc", {0.15,0.25}, 0.1}) pl.Add({"Arc", {0.3,0.2}, 0.1, 0, Pi/2}, {{"Close",true}, {"Fill Color",0xFF8000}}) -- a bitmap of 3 by 2 pixels, the first row at the top, drawn with sharp pixels pl.Add({"BitMap", {0.45,0.1}, {0.6,0.35}, { {{255,0,0}, {0,160,0}, {0,0,255}}, {0, 128, 255} }}, {{"Pixelated",true}}) -- texts: centred, and turned by 90 degrees pl.Add("Graphics.Add", 0.5, 0.45, {{"Size",0.06}, {"Alignment","c"}}) pl.Add("turned", 0.68, 0.1, {{"Angle",Pi/2}, {"Color",0x0000C0}}) -- a layer: a small page of its own, 60 mm by 50 mm with its lower left corner at (220 mm, 15 mm) Inset = Graphics.New({{"Canvas.Size.X",60}, {"Canvas.Size.Y",50}, {"Canvas.Origin.X",220}, {"Canvas.Origin.Y",15}}) Inset.Add({ {0,0}, {1,0}, {1,1}, {0,1} }, {{"Close",true}, {"Fill Color",0xE0E0E0}}) pl.Add(Inset) -- the option Layer adds to layer 1, so (0.5, 0.5) is the middle of the inset pl.Add("inset", 0.5, 0.5, {{"Layer",1}, {"Alignment","c"}, {"Size",0.15}}) print("lines", pl.NLine, "curves", pl.NCurve, "arcs", pl.NArc, "texts", pl.NText, "bitmaps", pl.NBitMap, "layers", pl.NLayer) -- the function form returns a new Graphics object and leaves pl as it is pl2 = Graphics.Add(pl, "a third text", 0.05, 0.02) print("texts", pl.NText, pl2.NText) file = io.open("Add.svg", "w") file:write(Graphics.ToSVG(pl, {{"RelativeSize",true}})) file:close()
lines 2 curves 1 arcs 2 texts 2 bitmaps 1 layers 2 texts 2 3
The script writes Add.svg. The text “inset” is in the layer, so it is not counted among the texts of pl; pl.NLayer counts pl itself and its one layer. The circle is round although the page is not square, because its radius is a fraction of $\sqrt{\mathrm{width} \cdot \mathrm{height}}$.