The document introduces SVGo, a Go library for generating SVG drawings programmatically. It demonstrates how to use SVGo to create basic shapes like rectangles and lines, add attributes, apply transformations, and script interactions. The goal of SVGo is to allow generating consistent SVG views from standardized data.
5. 0. Install Go
1. goinstall github.com/ajstarks/svgo
2. Make pictures
geKng started with
6. ‣ interfaces
‣ variadic arguments
‣ composite literals and types
‣ format, string, xml, flag libraries
‣ fast compiles
‣ goinstall
‣ goplay
‣ func@ons as the unit of graphics work
Go Language features in
10. New(w io.Writer) Specify the des@na@on for the generated code
Start(w, h int, op@ons ...string) Begin the SVG document, with op@ons
Startview(w, h, minx, miny, vw, vh int) Begin the document with a viewport
Gid(id string)/Gend() Begin/end a group with an id
Gstyle(s string)/Gend() Begin/end a group style
Def(s string)/DefEnd() Begin/end defini@on block
Title(s string) Specify the document @tle
Desc(s string) Specify the document descrip@on
Link(href, @tle string)/LinkEnd() Link to content between Link and LinkEnd
Use(x, y int, link string, style ...string) Use previously defined content
End() End the SVG document
Structure, Metadata, Links
11. Line(x1, y1, x2, y2 int, s ...string) Polyline(x, y []int, s ...string)
Qbez(sx, sy, cx, cy, ex, ey int, s ...string) Bezier(sx, sy, cx, cy, px, py, ex, ey int, s ...string)
Arc(sx sy, ax, ay, r int, large, sweep bool, ex ey int, s ...string) Path(d string, s ...string)
Lines, Curves, and Path
12. Scale(n float64) ScaleXY(dx, dy float64)
SkewX(a float64)
SkewY(a float64) SkewXY(ax, ay float64)
Gtransform(s string)
TranslateRotate(x, y int, r float64)
RotateTranslate(x, y int, r float64)
Translate(x, y int)
Rotate(r float64)
Transforms
13. Text(x, y int, t string, s ...string) Image(x, y, w, h int, link string, s ...string)
Textlines(x, y int, s []string, size, spacing int, fill, align string) Textpath(t, pathid string, s ...string)
Text and Image
15. ⟶ ⟶
44 77 232 44 77 232 .33
RGB(r, g, b int) RGBA(r, g, b int, alpha float64)
Grid(x, y, w, h, n int, s ...string)
Colors, Grid
16. 1 canvas.Start(500, 500, `onload="Startup()"`)
2 canvas.Script("application/javascript", "http://example.com/myscript.js")
3 canvas.Rect(10, 10, 100, 200)
4 canvas.End()
example.com/myscript.js
function StartUp()
1 Begin the document, load your func@on
{
... 2 specify the script, by reference
}
3 specify SVG elements, operate on these
function doStuff(element)
{ 4 end the SVG document
...
}
Scrip@ng
25. imports, constants, flags
main func@on; use the
circle func@on to handle
the URL
in the circle func@on,
write the generated SVG
to the web client
if the URL contains a
color, use it
drawing in a web server
26. define the input data structures
read the input
parse the input into the structures
draw
read/parse/draw paZern