pax_global_header 0000666 0000000 0000000 00000000064 11714366324 0014521 g ustar 00root root 0000000 0000000 52 comment=d91d3105f1ea2fa04949d9af48d3e9e50073f371
svgo-go.weekly.2012-01-27/ 0000775 0000000 0000000 00000000000 11714366324 0014774 5 ustar 00root root 0000000 0000000 svgo-go.weekly.2012-01-27/LICENSE 0000664 0000000 0000000 00000000240 11714366324 0015775 0 ustar 00root root 0000000 0000000 The contents of this repository are Licensed under
the Creative Commons Attribution 3.0 license as described in
http://creativecommons.org/licenses/by/3.0/us/
svgo-go.weekly.2012-01-27/README.markdown 0000664 0000000 0000000 00000034436 11714366324 0017507 0 ustar 00root root 0000000 0000000 #SVGo: A Go library for SVG generation#
The library generates SVG as defined by the Scalable Vector Graphics 1.1 Specification ().
Output goes to the specified io.Writer.
## Supported SVG elements and functions ##
circle, ellipse, polygon, polyline, rect (including roundrects), paths (general, arc,
cubic and quadratic bezier paths), line, image, text, linearGradient, radialGradient,
transforms (translate, rotate, scale, skewX, skewY)
## Metadata elements ##
desc, defs, g (style, transform, id), mask, title, (a)ddress, link, script, use
## Building and Usage ##
See svgdef.[svg|png|pdf] for a graphical view of the function calls
Usage:
goinstall github.com/ajstarks/svgo
to install into your Go environment. To update the library you can use:
goinstall -clean -u -v github.com/ajstarks/svgo
a minimal program, to generate SVG to standard output.
package main
import (
"github.com/ajstarks/svgo"
"os"
)
func main() {
width := 500
height := 500
canvas := svg.New(os.Stdout)
canvas.Start(width, height)
canvas.Circle(width/2, height/2, 100)
canvas.Text(width/2, height/2, "Hello, SVG", "text-anchor:middle;font-size:30px;fill:white")
canvas.End()
}
Drawing in a web server: (http://localhost:2003/circle)
package main
import (
"log"
"github.com/ajstarks/svgo"
"net/http"
)
func main() {
http.Handle("/circle", http.HandlerFunc(circle))
err := http.ListenAndServe(":2003", nil)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
func circle(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "image/svg+xml")
s := svg.New(w)
s.Start(500, 500)
s.Circle(250, 250, 125, "fill:none;stroke:black")
s.End()
}
You may view the SVG output with a browser that supports SVG (tested on Chrome, Opera, Firefox and Safari), or any other SVG user-agent such as Batik Squiggle. The test-svgo script tries to use reasonable defaults based on the GOOS and GOARCH environment variables.
The command:
$ ./newsvg foo.go
creates Go source file ready for your code, using $EDITOR
To create browsable documentation:
$ godoc -path= -
and click on the "Package documentation for svg" link
### Tutorial Video ###
A video describing how to use the package can be seen on YouTube at
## Package contents ##
* svg.go: Library
* newsvg: Coding template command
* svgdef: Creates a SVG representation of the API
* android: The Android logo
* bubtrail: Bubble trails
* bulletgraph: Bullet Graphs (via Stephen Few)
* colortab: Display SVG named colors with RGB values
* compx: Component diagrams
* flower: Random "flowers"
* fontcompare: Compare two fonts
* f50: Get 50 photos from Flickr based on a query
* funnel: Funnel from transparent circles
* gradient: Linear and radial gradients
* html5logo: HTML5 logo with draggable elements
* imfade: Show image fading
* lewitt: Version of Sol Lewitt's Wall Drawing 91
* ltr: Layer Tennis Remixes
* paths Demonstrate SVG paths
* planets: Show the scale of the Solar system
* pmap: Proportion maps
* randcomp: Compare random number generators
* richter: Gerhard Richter's 256 colors
* rl: Random lines (port of a Processing demo)
* skewabc: Skew ABC
* stockproduct: Visualize product and stock prices
* svgopher: SVGo Mascot
* tsg: Twitter Search Grid
* vismem: Visualize data from files
* webfonts: "Hello, World" with Google Web Fonts
* websvg: Generate SVG as a web server
## Functions and types ##
Many functions use x, y to specify an object's location, and w, h to specify the object's width and height.
Where applicable, a final optional argument specifies the style to be applied to the object.
The style strings follow the SVG standard; name:value pairs delimited by semicolons, or a
series of name="value" pairs. For example: `"fill:none; opacity:0.3"` or `fill="none" opacity="0.3"` (see: )
The Offcolor type:
type Offcolor struct {
Offset uint8
Color string
Opacity float
}
is used to specify the offset, color, and opacity of stop colors in linear and radial gradients
### Structure, Scripting, Metadata, Transformation and Links ###
New(w io.Writer) *SVG
Constructor, Specify the output destination.
Start(w int, h int, attributes ...string)
begin the SVG document with the width w and height h. Optionally add additional elememts
(such as additional namespaces or scripting events)
Startview(w, h, minx, miny, vw, vh int)
begin the SVG document with the width w, height h, with a viewBox at minx, miny, vw, vh.
End()
end the SVG document
Script(scriptype string, data ...string)
Script defines a script with a specified type, (for example "application/javascript").
if the first variadic argument is a link, use only the link reference.
Otherwise, treat variadic arguments as the text of the script (marked up as CDATA).
if no data is specified, simply close the script element.
Group(s ...string)
begin a group, with arbitrary attributes
Gstyle(s string)
begin a group, with the specified style.
Gid(s string)
begin a group, with the specified id.
Gtransform(s string)
begin a group, with the specified transform, end with Gend().
Translate(x, y int)
begins coordinate translation to (x,y), end with Gend().
Scale(n float64)
scales the coordinate system by n, end with Gend().
ScaleXY(x, y float64)
scales the coordinate system by x, y. End with Gend().
SkewX(a float64)
SkewX skews the x coordinate system by angle a, end with Gend().
SkewY(a float64)
SkewY skews the y coordinate system by angle a, end with Gend().
SkewXY(ax, ay float64)
SkewXY skews x and y coordinate systems by ax, ay respectively, end with Gend().
Rotate(r float64)
rotates the coordinate system by r degrees, end with Gend().
TranslateRotate(x, y int, r float64)
translates the coordinate system to (x,y), then rotates to r degrees, end with Gend().
RotateTranslate(x, y int, r float64)
rotates the coordinate system r degrees, then translates to (x,y), end with Gend().
Gend()
end the group (must be paired with Gstyle, Gtransform, Gid).
ClipPath(s ...string)
Begin a ClipPath
ClipEnd()
End a ClipPath
Def()
begin a definition block.
DefEnd()
end a definition block.
Mask(string, x int, y int, w int, h int, s ...string)
creates a mask with a specified id, dimension, and optional style.
MaskEnd()
ends the Mask element.
Desc(s string)
specify the text of the description.
Title(s string)
specify the text of the title.
Link(href string, title string)
begin a link named "href", with the specified title.
LinkEnd()
end the link.
Use(x int, y int, link string, s ...string)
place the object referenced at link at the location x, y.
### Shapes ###
Circle(x int, y int, r int, s ...string)
draw a circle, centered at x,y with radius r.

Ellipse(x int, y int, w int, h int, s ...string)
draw an ellipse, centered at x,y with radii w, and h.

Polygon(x []int, y []int, s ...string)
draw a series of line segments using an array of x, y coordinates.

Rect(x int, y int, w int, h int, s ...string)
draw a rectangle with upper left-hand corner at x,y, with width w, and height h.

CenterRect(x int, y int, w int, h int, s ...string)
draw a rectangle with its center at x,y, with width w, and height h.
Roundrect(x int, y int, w int, h int, rx int, ry int, s ...string)
draw a rounded rectangle with upper the left-hand corner at x,y,
with width w, and height h. The radii for the rounded portion
is specified by rx (width), and ry (height).

Square(x int, y int, s int, style ...string)
draw a square with upper left corner at x,y with sides of length s.

### Paths ###
Path(p string, s ...style)
draw the arbitrary path as specified in p, according to the style specified in s.
Arc(sx int, sy int, ax int, ay int, r int, large bool, sweep bool, ex int, ey int, s ...string)
draw an elliptical arc beginning coordinate at sx,sy, ending coordinate at ex, ey
width and height of the arc are specified by ax, ay, the x axis rotation is r
if sweep is true, then the arc will be drawn in a "positive-angle" direction (clockwise),
if false, the arc is drawn counterclockwise.
if large is true, the arc sweep angle is greater than or equal to 180 degrees,
otherwise the arc sweep is less than 180 degrees.

Bezier(sx int, sy int, cx int, cy int, px int, py int, ex int, ey int, s ...string)
draw a cubic bezier curve, beginning at sx,sy, ending at ex,ey
with control points at cx,cy and px,py.

Qbezier(sx int, sy int, cx int, cy int, ex int, ey int, tx int, ty int, s ...string)
draw a quadratic bezier curve, beginning at sx, sy, ending at tx,ty
with control points are at cx,cy, ex,ey.

Qbez(sx int, sy int, cx int, cy int, ex int, ey int, s...string)
draws a quadratic bezier curver, with optional style beginning at sx,sy, ending at ex, sy
with the control point at cx, cy.

### Lines ###
Line(x1 int, y1 int, x2 int, y2 int, s ...string)
draw a line segment between x1,y1 and x2,y2.

Polyline(x []int, y []int, s ...string)
draw a polygon using coordinates specified in x,y arrays.

### Image and Text ###
Image(x int, y int, w int, h int, link string, s ...string)
place at x,y (upper left hand corner), the image with width w, and height h, referenced at link.

Text(x int, y int, t string, s ...string)
Place the specified text, t at x,y according to the style specified in s.
Textlines(x, y int, s []string, size, spacing int, fill, align string)
Places lines of text in s, starting at x,y, at the specified size, fill, and alignment, and spacing.
Textpath(t string, pathid string, s ...string)
places optionally styled text along a previously defined path.

### Color ###
RGB(r int, g int, b int) string
creates a style string for the fill color designated
by the (r)ed, g(reen), (b)lue components.
RGBA(r int, g int, b int, a float64) string
as above, but includes the color's opacity as a value
between 0.0 (fully transparent) and 1.0 (opaque).
### Gradients ###
LinearGradient(id string, x1, y1, x2, y2 uint8, sc []Offcolor)
constructs a linear color gradient identified by id,
along the vector defined by (x1,y1), and (x2,y2).
The stop color sequence defined in sc. Coordinates are expressed as percentages.

RadialGradient(id string, cx, cy, r, fx, fy uint8, sc []Offcolor)
constructs a radial color gradient identified by id,
centered at (cx,cy), with a radius of r.
(fx, fy) define the location of the focal point of the light source.
The stop color sequence defined in sc.
Coordinates are expressed as percentages.

### Utility ###
Grid(x int, y int, w int, h int, n int, s ...string)
draws a grid of straight lines starting at x,y, with a width w, and height h, and a size of n.

### Credits ###
Thanks to Jonathan Wright for the io.Writer update.
svgo-go.weekly.2012-01-27/android/ 0000775 0000000 0000000 00000000000 11714366324 0016414 5 ustar 00root root 0000000 0000000 svgo-go.weekly.2012-01-27/android/android.go 0000664 0000000 0000000 00000003131 11714366324 0020361 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"os"
"github.com/ajstarks/svgo"
)
var (
width = 500
height = 500
canvas = svg.New(os.Stdout)
)
const androidcolor = "rgb(164,198,57)"
func background(v int) { canvas.Rect(0, 0, width, height, canvas.RGB(v, v, v)) }
func android(x, y int, fill string, opacity float64) {
var linestyle = []string{`stroke="` + fill + `"`, `stroke-linecap="round"`, `stroke-width="5"`}
globalstyle := fmt.Sprintf("fill:%s;opacity:%.2f", fill, opacity)
canvas.Gstyle(globalstyle)
canvas.Arc(x+30, y+70, 35, 35, 0, false, true, x+130, y+70) // head
canvas.Line(x+60, y+25, x+50, y+10, linestyle[0], linestyle[1], linestyle[2]) // left antenna
canvas.Line(x+100, y+25, x+110, y+10, linestyle[0], linestyle[1], linestyle[2]) // right antenna
canvas.Circle(x+60, y+45, 5, "fill:white") // left eye
canvas.Circle(x+100, y+45, 5, `fill="white"`) // right eye
canvas.Roundrect(x+30, y+75, 100, 90, 10, 10) // body
canvas.Rect(x+30, y+75, 100, 80)
canvas.Roundrect(x+5, y+80, 20, 70, 10, 10) // left arm
canvas.Roundrect(x+135, y+80, 20, 70, 10, 10) // right arm
canvas.Roundrect(x+50, y+150, 20, 50, 10, 10) // left leg
canvas.Roundrect(x+90, y+150, 20, 50, 10, 10) // right leg
canvas.Gend()
}
func main() {
canvas.Start(width, height)
canvas.Title("Android")
background(255)
android(100, 100, androidcolor, 1.0)
canvas.Scale(3.0)
android(50, 50, "gray", 0.5)
canvas.Gend()
canvas.Scale(0.5)
android(100, 100, "red", 1.0)
canvas.Gend()
canvas.End()
}
svgo-go.weekly.2012-01-27/bubtrail/ 0000775 0000000 0000000 00000000000 11714366324 0016600 5 ustar 00root root 0000000 0000000 svgo-go.weekly.2012-01-27/bubtrail/bubtrail.go 0000664 0000000 0000000 00000002407 11714366324 0020736 0 ustar 00root root 0000000 0000000 package main
import (
"flag"
"fmt"
"math/rand"
"os"
"time"
"github.com/ajstarks/svgo"
)
var (
width = 1200
height = 600
opacity = 0.5
size = 40
niter = 200
canvas = svg.New(os.Stdout)
)
func init() {
flag.IntVar(&size, "s", 40, "bubble size")
flag.IntVar(&niter, "n", 200, "number of iterations")
flag.Float64Var(&opacity, "o", 0.5, "opacity")
flag.Parse()
rand.Seed(int64(time.Now().Nanosecond()) % 1e9)
}
func background(v int) { canvas.Rect(0, 0, width, height, canvas.RGB(v, v, v)) }
func random(howsmall, howbig int) int {
if howsmall >= howbig {
return howsmall
}
return rand.Intn(howbig-howsmall) + howsmall
}
func main() {
var style string
canvas.Start(width, height)
canvas.Title("Bubble Trail")
background(200)
canvas.Gstyle(fmt.Sprintf("fill-opacity:%.2f;stroke:none", opacity))
for i := 0; i < niter; i++ {
x := random(0, width)
y := random(height/3, (height*2)/3)
r := random(0, 10000)
switch {
case r >= 0 && r <= 2500:
style = "fill:rgb(255,255,255)"
case r > 2500 && r <= 5000:
style = "fill:rgb(127,0,0)"
case r > 5000 && r <= 7500:
style = "fill:rgb(127,127,127)"
case r > 7500 && r <= 10000:
style = "fill:rgb(0,0,0)"
}
canvas.Circle(x, y, size, style)
}
canvas.Gend()
canvas.End()
}
svgo-go.weekly.2012-01-27/bulletgraph/ 0000775 0000000 0000000 00000000000 11714366324 0017305 5 ustar 00root root 0000000 0000000 svgo-go.weekly.2012-01-27/bulletgraph/bulletgraph.go 0000664 0000000 0000000 00000015062 11714366324 0022151 0 ustar 00root root 0000000 0000000 // bulletgraph - bullet graphs
// Bullet Graph Design Specification, Steven Few
// http://www.perceptualedge.com/articles/misc/Bullet_Graph_Design_Spec.pdf
package main
import (
"encoding/xml"
"flag"
"fmt"
"io"
"os"
"strconv"
"strings"
"github.com/ajstarks/svgo"
)
var (
width, height, iscale, fontsize, barheight, gutter int
bgcolor, barcolor, datacolor, compcolor, title string
showtitle, circlemark bool
gstyle = "font-family:Calibri;font-size:%dpx"
)
// a Bulletgraph Defintion
//
// This is a note
// More expository text
//
//
//
//
//
//
type Bulletgraph struct {
Top int `xml:"top,attr"`
Left int `xml:"left,attr"`
Right int `xml:"right,attr"`
Title string `xml:"title,attr"`
Bdata []bdata `xml:"bdata"`
Note []note `xml:"note"`
}
type bdata struct {
Title string `xml:"title,attr"`
Subtitle string `xml:"subtitle,attr"`
Scale string `xml:"scale,attr"`
Qmeasure string `xml:"qmeasure,attr"`
Cmeasure float64 `xml:"cmeasure,attr"`
Measure float64 `xml:"measure,attr"`
}
type note struct {
Text string `xml:",chardata"`
}
// dobg does file i/o
func dobg(location string, s *svg.SVG) {
var f *os.File
var err error
if len(location) > 0 {
f, err = os.Open(location)
} else {
f = os.Stdin
}
if err == nil {
readbg(f, s)
f.Close()
} else {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
}
// readbg reads and parses the XML specification
func readbg(r io.Reader, s *svg.SVG) {
var bg Bulletgraph
if err := xml.NewDecoder(r).Decode(&bg); err == nil {
drawbg(bg, s)
} else {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
}
// drawbg draws the bullet graph
func drawbg(bg Bulletgraph, canvas *svg.SVG) {
qmheight := barheight / 3
if bg.Left == 0 {
bg.Left = 250
}
if bg.Right == 0 {
bg.Right = 50
}
if bg.Top == 0 {
bg.Top = 50
}
if len(title) > 0 {
bg.Title = title
}
maxwidth := width - (bg.Left + bg.Right)
x := bg.Left
y := bg.Top
scalesep := 4
tx := x - fontsize
canvas.Title(bg.Title)
// for each bdata element...
for _, v := range bg.Bdata {
// extract the data from the XML attributes
sc := strings.Split(v.Scale, ",")
qm := strings.Split(v.Qmeasure, ",")
// you must have min,max,increment for the scale, at least one qualitative measure
if len(sc) != 3 || len(qm) < 1 {
continue
}
// get the qualitative measures
qmeasures := make([]float64, len(qm))
for i, q := range qm {
qmeasures[i], _ = strconv.ParseFloat(q, 64)
}
scalemin, _ := strconv.ParseFloat(sc[0], 64)
scalemax, _ := strconv.ParseFloat(sc[1], 64)
scaleincr, _ := strconv.ParseFloat(sc[2], 64)
// label the graph
canvas.Text(tx, y+barheight/3, fmt.Sprintf("%s (%g)", v.Title, v.Measure), "text-anchor:end;font-weight:bold")
canvas.Text(tx, y+(barheight/3)+fontsize, v.Subtitle, "text-anchor:end;font-size:75%")
// draw the scale
scfmt := "%g"
if fraction(scaleincr) > 0 {
scfmt = "%.1f"
}
canvas.Gstyle("text-anchor:middle;font-size:75%")
for sc := scalemin; sc <= scalemax; sc += scaleincr {
scx := vmap(sc, scalemin, scalemax, 0, float64(maxwidth))
canvas.Text(x+int(scx), y+scalesep+barheight+fontsize/2, fmt.Sprintf(scfmt, sc))
}
canvas.Gend()
// draw the qualitative measures
canvas.Gstyle("fill-opacity:0.5;fill:" + barcolor)
canvas.Rect(x, y, maxwidth, barheight)
for _, q := range qmeasures {
qbarlength := vmap(q, scalemin, scalemax, 0, float64(maxwidth))
canvas.Rect(x, y, int(qbarlength), barheight)
}
canvas.Gend()
// draw the measure and the comparative measure
barlength := int(vmap(v.Measure, scalemin, scalemax, 0, float64(maxwidth)))
canvas.Rect(x, y+qmheight, barlength, qmheight, "fill:"+datacolor)
cmx := int(vmap(v.Cmeasure, scalemin, scalemax, 0, float64(maxwidth)))
if circlemark {
canvas.Circle(x+cmx, y+barheight/2, barheight/6, "fill-opacity:0.3;fill:"+compcolor)
} else {
cbh := barheight / 4
canvas.Line(x+cmx, y+cbh, x+cmx, y+barheight-cbh, "stroke-width:3;stroke:"+compcolor)
}
y += barheight + gutter // adjust vertical position for the next iteration
}
// if requested, place the title below the last bar
if showtitle && len(bg.Title) > 0 {
y += fontsize * 2
canvas.Text(bg.Left, y, bg.Title, "text-anchor:start;font-size:200%")
}
if len(bg.Note) > 0 {
canvas.Gstyle("font-size:100%;text-anchor:start")
y += fontsize * 2
leading := 3
for _, note := range bg.Note {
canvas.Text(bg.Left, y, note.Text)
y += fontsize + leading
}
canvas.Gend()
}
}
//vmap maps one interval to another
func vmap(value float64, low1 float64, high1 float64, low2 float64, high2 float64) float64 {
return low2 + (high2-low2)*(value-low1)/(high1-low1)
}
// fraction returns the fractions portion of a floating point number
func fraction(n float64) float64 {
i := int(n)
return n - float64(i)
}
// init sets up the command flags
func init() {
flag.StringVar(&bgcolor, "bg", "white", "background color")
flag.StringVar(&barcolor, "bc", "rgb(200,200,200)", "bar color")
flag.StringVar(&datacolor, "dc", "darkgray", "data color")
flag.StringVar(&compcolor, "cc", "black", "comparative color")
flag.IntVar(&width, "w", 1024, "width")
flag.IntVar(&height, "h", 800, "height")
flag.IntVar(&barheight, "bh", 48, "bar height")
flag.IntVar(&gutter, "g", 30, "gutter")
flag.IntVar(&fontsize, "f", 18, "fontsize (px)")
flag.BoolVar(&circlemark, "circle", false, "circle mark")
flag.BoolVar(&showtitle, "showtitle", false, "show title")
flag.StringVar(&title, "t", "", "title")
flag.Parse()
}
// for every input file (or stdin), draw a bullet graph
// as specified by command flags
func main() {
canvas := svg.New(os.Stdout)
canvas.Start(width, height)
canvas.Rect(0, 0, width, height, "fill:"+bgcolor)
canvas.Gstyle(fmt.Sprintf(gstyle, fontsize))
if len(flag.Args()) == 0 {
dobg("", canvas)
} else {
for _, f := range flag.Args() {
dobg(f, canvas)
}
}
canvas.Gend()
canvas.End()
}
svgo-go.weekly.2012-01-27/codepic/ 0000775 0000000 0000000 00000000000 11714366324 0016402 5 ustar 00root root 0000000 0000000 svgo-go.weekly.2012-01-27/codepic/codepic.go 0000664 0000000 0000000 00000012746 11714366324 0020351 0 ustar 00root root 0000000 0000000 // codepic -- produce code+output sample suitable for slides
package main
import (
"bufio"
"encoding/xml"
"flag"
"fmt"
"io"
"os"
"strings"
"github.com/ajstarks/svgo"
)
var (
canvas = svg.New(os.Stdout)
font string
codeframe, picframe, syntax bool
linespacing, fontsize, top, left, boxwidth, width, height int
)
const (
framestyle = "stroke:gray;stroke-dasharray:1,1;fill:none"
labelstyle = "text-anchor:middle"
codefmt = "font-family:%s;font-size:%dpx"
labelfmt = "text-anchor:middle;" + codefmt
kwfmt = `%s`
commentfmt = `%s`
textfmt = "%s\n"
svgofmt = `font-weight="bold" fill="rgb(0,0,127)"`
gokwfmt = `font-style="italic" fill="rgb(127,0,0)"`
)
// incoming SVG file, capture everything into between and
// in the Doc string. This code will be translated to form the "picture" portion
type SVG struct {
Width int `xml:"width,attr"`
Height int `xml:"height,attr"`
Doc string `xml:",innerxml"`
}
var gokw = []string{
"defer ", "go ", "range ", "chan ", " continue", "if ", "for ", "func ",
"uint8", "uint", "uint16", "uint32", "complex64", "complex128", " byte", "int8", "int16", "int32",
"int64", " int", "float64", "float32", " string", "import ", "const ",
"package ", "return", "var ", "type ", "switch ", "case ", "default:",
}
var svgokw = []string{
".Start", ".Startview,", ".End", ".Script", ".Gstyle", ".Gtransform", ".Scale", ".Offcolor",
".ScaleXY", ".SkewX", ".SkewY", ".SkewXY,", ".Rotate", ".TranslateRotate", ".RotateTranslate", ".Translate",
".Group", ".Gid", ".Gend", ".ClipPath", ".ClipEnd", ".DefEnd", ".Def", ".Desc", ".Title", ".Linkf",
".LinkEnd", ".Use", ".Mask", ".MaskEnd", ".Circle", ".Ellipse", ".Polygon", ".Rect", ".CenterRect",
".Roundrect", ".Square", ".Path", ".Arc", ".Bezier", ".Qbez", ".Qbezier", ".Line", ".Polyline", ".Image",
".Textpath", ".Textlines,", ".Text", ".RGBA", ".RGB", ".LinearGradient", ".RadialGradient", ".Grid",
}
// codepic makes a code+picture SVG file, given a go source file
// and conventionally named output -- given .go, .svg
func codepic(filename string) {
var basename string
bn := strings.Split(filename, ".")
if len(bn) > 0 {
basename = bn[0]
} else {
fmt.Fprintf(os.Stderr, "cannot get the basename for %s\n", filename)
return
}
canvas.Start(width, height)
canvas.Title(basename)
canvas.Rect(0, 0, width, height, "fill:white")
placepic(width/2, top, basename)
canvas.Gstyle(fmt.Sprintf(codefmt, font, fontsize))
placecode(left+fontsize, top+fontsize*2, filename)
canvas.Gend()
canvas.End()
}
// placecode places the code section on the left
func placecode(x, y int, filename string) {
var rerr error
var line string
var ic bool
f, err := os.Open(filename)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return
}
defer f.Close()
in := bufio.NewReader(f)
for xp := left + fontsize; rerr == nil; y += linespacing {
line, rerr = in.ReadString('\n')
if len(line) > 0 {
line, ic = svgtext(xp, y, line[0:len(line)-1])
if !ic && syntax {
line = keyword(line, gokwfmt, gokw)
line = keyword(line, svgofmt, svgokw)
}
io.WriteString(canvas.Writer, line)
}
}
if codeframe {
canvas.Rect(top, left, left+boxwidth, y, framestyle)
}
}
// keyword styles keywords in a line of code
func keyword(line string, style string, kw []string) string {
for _, k := range kw {
line = strings.Replace(line, k, fmt.Sprintf(kwfmt, style, k), 1)
}
return line
}
// svgtext
func svgtext(x, y int, s string) (string, bool) {
var iscomment = false
s = strings.Replace(s, "&", "&", -1)
s = strings.Replace(s, "<", "<", -1)
s = strings.Replace(s, ">", ">", -1)
if syntax {
i := strings.Index(s, "// ")
if i >= 0 {
iscomment = true
s = strings.Replace(s, s[i:], fmt.Sprintf(commentfmt, s[i:]), 1)
}
}
return fmt.Sprintf(textfmt, x, y, s), iscomment
}
// placepic places the picture on the right
func placepic(x, y int, basename string) {
var s SVG
f, err := os.Open(basename + ".svg")
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return
}
defer f.Close()
if err := xml.NewDecoder(f).Decode(&s); err != nil {
fmt.Fprintf(os.Stderr, "Unable to parse (%v)\n", err)
return
}
canvas.Text(x, height-10, basename+".go", fmt.Sprintf(labelfmt, font, fontsize*2))
canvas.Group(`clip-path="url(#pic)"`, fmt.Sprintf(`transform="translate(%d,%d)"`, x, y))
canvas.ClipPath(`id="pic"`)
canvas.Rect(0, 0, s.Width, s.Height)
canvas.ClipEnd()
io.WriteString(canvas.Writer, s.Doc)
canvas.Gend()
if picframe {
canvas.Rect(x, y, s.Width, s.Height, framestyle)
}
}
// init initializes flags
func init() {
flag.BoolVar(&codeframe, "codeframe", false, "frame the code")
flag.BoolVar(&picframe, "picframe", false, "frame the picture")
flag.BoolVar(&syntax, "syntax", false, "syntax coloring")
flag.IntVar(&width, "w", 1024, "width")
flag.IntVar(&height, "h", 768, "height")
flag.IntVar(&linespacing, "ls", 16, "linespacing")
flag.IntVar(&fontsize, "fs", 14, "fontsize")
flag.IntVar(&top, "top", 20, "top")
flag.IntVar(&left, "left", 20, "left")
flag.IntVar(&boxwidth, "boxwidth", 450, "boxwidth")
flag.StringVar(&font, "font", "Inconsolata", "font name")
flag.Parse()
}
// for every file, make a code+pic SVG file
func main() {
for _, f := range flag.Args() {
codepic(f)
}
}
svgo-go.weekly.2012-01-27/colortab/ 0000775 0000000 0000000 00000000000 11714366324 0016601 5 ustar 00root root 0000000 0000000 svgo-go.weekly.2012-01-27/colortab/colortab.go 0000664 0000000 0000000 00000004767 11714366324 0020753 0 ustar 00root root 0000000 0000000 // colortab -- make a color/code placemat
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
"github.com/ajstarks/svgo"
)
func main() {
var (
canvas = svg.New(os.Stdout)
filename = flag.String("f", "svgcolors.txt", "input file")
fontname = flag.String("font", "Calibri,sans-serif", "fontname")
outline = flag.Bool("o", false, "outline")
neg = flag.Bool("n", false, "negative")
showrgb = flag.Bool("rgb", true, "show RGB")
showcode = flag.Bool("showcode", true, "only show colors")
circsw = flag.Bool("circle", true, "circle swatch")
fontsize = flag.Int("fs", 12, "fontsize")
width = flag.Int("w", 1600, "width")
height = flag.Int("h", 900, "height")
rowsize = flag.Int("r", 32, "rowsize")
colw = flag.Int("c", 320, "column size")
swatch = flag.Int("s", 16, "swatch size")
gutter = flag.Int("g", 11, "gutter")
err error = nil
colorfmt, tcolor, line string
)
flag.Parse()
f, oerr := os.Open(*filename)
if oerr != nil {
fmt.Fprintf(os.Stderr, "%v\n", oerr)
return
}
canvas.Start(*width, *height)
if *neg {
canvas.Rect(0, 0, *width, *height, "fill:black")
tcolor = "white"
} else {
canvas.Rect(0, 0, *width, *height, "fill:white")
tcolor = "black"
}
top := 32
left := 32
in := bufio.NewReader(f)
canvas.Gstyle(fmt.Sprintf("font-family:%s;font-size:%dpt;fill:%s",
*fontname, *fontsize, tcolor))
for x, y, nr := left, top, 0; err == nil; nr++ {
line, err = in.ReadString('\n')
fields := strings.Split(strings.TrimSpace(line), "\t")
if nr%*rowsize == 0 && nr > 0 {
x += *colw
y = top
}
if len(fields) == 3 {
colorfmt = "fill:" + fields[1]
if *outline {
colorfmt = colorfmt + ";stroke-width:1;stroke:" + tcolor
}
if *circsw {
canvas.Circle(x, y, *swatch/2, colorfmt)
} else {
canvas.CenterRect(x, y, *swatch, *swatch, colorfmt)
}
canvas.Text(x+*swatch+*fontsize/2, y+(*swatch/4), fields[0], "stroke:none")
var label string
if *showcode {
if *showrgb {
label = fields[2]
} else {
label = fields[1]
}
canvas.Text(x+((*colw*4)/5), y+(*swatch/4), label, "text-anchor:end;fill:gray")
}
}
y += (*swatch + *gutter)
}
canvas.Gend()
canvas.End()
}
svgo-go.weekly.2012-01-27/colortab/svgcolors.txt 0000775 0000000 0000000 00000010455 11714366324 0021373 0 ustar 00root root 0000000 0000000 aliceblue #F0F8FF 240,248,255
antiquewhite #FAEBD7 250,235,215
aqua #00FFFF 0,255,255
aquamarine #7FFFD4 127,255,212
azure #F0FFFF 240,255,255
beige #F5F5DC 245,245,220
bisque #FFE4C4 255,228,196
black #000000 0,0,0
blanchedalmond #FFEBCD 255,235,205
blue #0000FF 0,0,255
blueviolet #8A2BE2 138,43,226
brown #A52A2A 165,42,42
burlywood #DEB887 222,184,135
cadetblue #5F9EA0 95,158,160
chartreuse #7FFF00 127,255,0
chocolate #D2691E 210,105,30
coral #FF7F50 255,127,80
cornflowerblue #6495ED 100,149,237
cornsilk #FFF8DC 255,248,220
crimson #DC143C 220,20,60
cyan #00FFFF 0,255,255
darkblue #00008B 0,0,139
darkcyan #008B8B 0,139,139
darkgoldenrod #B8860B 184,134,11
darkgray #A9A9A9 169,169,169
darkgreen #006400 0,100,0
darkgrey #A9A9A9 169,169,169
darkkhaki #BDB76B 189,183,107
darkmagenta #8B008B 139,0,139
darkolivegreen #556B2F 85,107,47
darkorange #FF8C00 255,140,0
darkorchid #9932CC 153,50,204
darkred #8B0000 139,0,0
darksalmon #E9967A 233,150,122
darkseagreen #8FBC8F 143,188,143
darkslateblue #483D8B 72,61,139
darkslategray #2F4F4F 47,79,79
darkslategrey #2F4F4F 47,79,79
darkturquoise #00CED1 0,206,209
darkviolet #9400D3 148,0,211
deeppink #FF1493 255,20,147
deepskyblue #00BFFF 0,191,255
dimgray #696969 105,105,105
dimgrey #696969 105,105,105
dodgerblue #1E90FF 30,144,255
firebrick #B22222 178,34,34
floralwhite #FFFAF0 255,250,240
forestgreen #228B22 34,139,34
fuchsia #FF00FF 255,0,255
gainsboro #DCDCDC 220,220,220
ghostwhite #F8F8FF 248,248,255
gold #FFD700 255,215,0
goldenrod #DAA520 218,165,32
gray #808080 128,128,128
green #008000 0,128,0
greenyellow #ADFF2F 173,255,47
grey #808080 128,128,128
honeydew #F0FFF0 240,255,240
hotpink #FF69B4 255,105,180
indianred #CD5C5C 205,92,92
indigo #4B0082 75,0,130
ivory #FFFFF0 255,255,240
khaki #F0E68C 240,230,140
lavender #E6E6FA 230,230,250
lavenderblush #FFF0F5 255,240,245
lawngreen #7CFC00 124,252,0
lemonchiffon #FFFACD 255,250,205
lightblue #ADD8E6 173,216,230
lightcoral #F08080 240,128,128
lightcyan #E0FFFF 224,255,255
lightgoldenrodyellow #FAFAD2 250,250,210
lightgray #D3D3D3 211,211,211
lightgreen #90EE90 144,238,144
lightgrey #D3D3D3 211,211,211
lightpink #FFB6C1 255,182,193
lightsalmon #FFA07A 255,160,122
lightseagreen #20B2AA 32,178,170
lightskyblue #87CEFA 135,206,250
lightslategray #778899 119,136,153
lightslategrey #778899 119,136,153
lightsteelblue #B0C4DE 176,196,222
lightyellow #FFFFE0 255,255,224
lime #00FF00 0,255,0
limegreen #32CD32 50,205,50
linen #FAF0E6 250,240,230
magenta #FF00FF 255,0,255
maroon #800000 128,0,0
mediumaquamarine #66CDAA 102,205,170
mediumblue #0000CD 0,0,205
mediumorchid #BA55D3 186,85,211
mediumpurple #9370DB 147,112,219
mediumseagreen #3CB371 60,179,113
mediumslateblue #7B68EE 123,104,238
mediumspringgreen #00FA9A 0,250,154
mediumturquoise #48D1CC 72,209,204
mediumvioletred #C71585 199,21,133
midnightblue #191970 25,25,112
mintcream #F5FFFA 245,255,250
mistyrose #FFE4E1 255,228,225
moccasin #FFE4B5 255,228,181
navajowhite #FFDEAD 255,222,173
navy #000080 0,0,128
oldlace #FDF5E6 253,245,230
olive #808000 128,128,0
olivedrab #6B8E23 107,142,35
orange #FFA500 255,165,0
orangered #FF4500 255,69,0
orchid #DA70D6 218,112,214
palegoldenrod #EEE8AA 238,232,170
palegreen #98FB98 152,251,152
paleturquoise #AFEEEE 175,238,238
palevioletred #DB7093 219,112,147
papayawhip #FFEFD5 255,239,213
peachpuff #FFDAB9 255,218,185
peru #CD853F 205,133,63
pink #FFC0CB 255,192,203
plum #DDA0DD 221,160,221
powderblue #B0E0E6 176,224,230
purple #800080 128,0,128
red #FF0000 255,0,0
rosybrown #BC8F8F 188,143,143
royalblue #4169E1 65,105,225
saddlebrown #8B4513 139,69,19
salmon #FA8072 250,128,114
sandybrown #F4A460 244,164,96
seagreen #2E8B57 46,139,87
seashell #FFF5EE 255,245,238
sienna #A0522D 160,82,45
silver #C0C0C0 192,192,192
skyblue #87CEEB 135,206,235
slateblue #6A5ACD 106,90,205
slategray #708090 112,128,144
slategrey #708090 112,128,144
snow #FFFAFA 255,250,250
springgreen #00FF7F 0,255,127
steelblue #4682B4 70,130,180
tan #D2B48C 210,180,140
teal #008080 0,128,128
thistle #D8BFD8 216,191,216
tomato #FF6347 255,99,71
turquoise #40E0D0 64,224,208
violet #EE82EE 238,130,238
wheat #F5DEB3 245,222,179
white #FFFFFF 255,255,255
whitesmoke #F5F5F5 245,245,245
yellow #FFFF00 255,255,0
yellowgreen #9ACD32 154,205,50 svgo-go.weekly.2012-01-27/compx/ 0000775 0000000 0000000 00000000000 11714366324 0016122 5 ustar 00root root 0000000 0000000 svgo-go.weekly.2012-01-27/compx/comps.xml 0000775 0000000 0000000 00000002427 11714366324 0017775 0 ustar 00root root 0000000 0000000