Loading app-backend/main.go +2 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,8 @@ func main() { r.HandleFunc("/squares/?", squares.Random) r.HandleFunc("/squares/random/?", squares.Random) r.HandleFunc("/squares/random/[0-8]/?", squares.RandomColor) r.HandleFunc("/squares/[a-zA-Z0-9]+/?", squares.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9]+/?", squares.Color) // cached r.HandleFunc("/squares/[a-zA-Z0-9\\.]+/?", squares.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9\\.]+/?", squares.Color) // cached r.AddStaticResource(root) Loading controllers/checkerboard/checkerboard.go +4 −7 Original line number Diff line number Diff line package checkerboard import ( "github.com/ajstarks/svgo" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" Loading Loading @@ -29,9 +28,8 @@ func Color(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.Grid6X6SVG(canvas, colorMap[int(intID)][0], colorMap[int(intID)][1], size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.Grid6X6SVG(w, colorMap[int(intID)][0], colorMap[int(intID)][1], size) } } } Loading @@ -48,8 +46,7 @@ func Checkerboard(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.Grid6X6SVG(canvas, color1, color2, size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.Grid6X6SVG(w, color1, color2, size) } } controllers/squares/random.go +5 −7 Original line number Diff line number Diff line package squares import ( "github.com/ajstarks/svgo" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" Loading Loading @@ -32,9 +31,8 @@ func Random(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.RandomGrid6X6SVG(canvas, bg, fg, size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.RandomGrid6X6SVG(w, bg, fg, size) } } Loading @@ -53,9 +51,9 @@ func RandomColor(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.RandomGrid6X6SVG(canvas, colorMap[int(intID)][0], colorMap[int(intID)][1], size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.RandomGrid6X6SVG(w, colorMap[int(intID)][0], colorMap[int(intID)][1], size) } } } controllers/squares/square.go +4 −7 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ package squares import ( "crypto/md5" "fmt" "github.com/ajstarks/svgo" tgColors "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" Loading Loading @@ -57,9 +56,8 @@ func Square(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.SquaresSVG(canvas, key, bg, fg, size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.SquaresSVG(w, key, bg, fg, size) } } } Loading Loading @@ -97,9 +95,8 @@ func Color(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.SquaresSVG(canvas, key, colorMap[int(colorId)][0], colorMap[int(colorId)][1], size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.SquaresSVG(w, key, colorMap[int(colorId)][0], colorMap[int(colorId)][1], size) } } else { log.Printf("error when extracting permalink string: %v", err) Loading draw/draw.go +10 −3 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import ( "log" "math" "math/rand" "net/http" "strconv" ) Loading @@ -31,7 +32,8 @@ func Grid6X6(m *image.RGBA, color1, color2 color.RGBA) { } // Grid6X6SVG builds an image with 6X6 quadrants of alternate colors. func Grid6X6SVG(canvas *svg.SVG, color1, color2 color.RGBA, size int) { func Grid6X6SVG(w http.ResponseWriter, color1, color2 color.RGBA, size int) { canvas := svg.New(w) canvas.Start(size, size) squares := 6 quadrantSize := size / squares Loading @@ -52,6 +54,7 @@ func Grid6X6SVG(canvas *svg.SVG, color1, color2 color.RGBA, size int) { canvas.Rect(x, y, quadrantSize, quadrantSize, fillFromRGBA(colorMap[xQ])) } } canvas.End() } // RandomGrid6X6 builds a grid image with with 2 colors selected at random for each quadrant. Loading @@ -77,7 +80,8 @@ func RandomGrid6X6(m *image.RGBA, color1, color2 color.RGBA) { } // RandomGrid6X6SVG builds a grid image with with 2 colors selected at random for each quadrant. func RandomGrid6X6SVG(canvas *svg.SVG, color1, color2 color.RGBA, size int) { func RandomGrid6X6SVG(w http.ResponseWriter, color1, color2 color.RGBA, size int) { canvas := svg.New(w) canvas.Start(size, size) squares := 6 quadrantSize := size / squares Loading @@ -94,6 +98,7 @@ func RandomGrid6X6SVG(canvas *svg.SVG, color1, color2 color.RGBA, size int) { canvas.Rect(x, y, quadrantSize, quadrantSize, fillFromRGBA(colorMap[xQ])) } } canvas.End() } // getRandomColor returns a random color between c1 and c2 Loading Loading @@ -191,7 +196,8 @@ func Squares(m *image.RGBA, key string, color1, color2 color.RGBA) { } } func SquaresSVG(canvas *svg.SVG, key string, color1, color2 color.RGBA, size int) { func SquaresSVG(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) canvas.Start(size, size) squares := 6 Loading @@ -216,6 +222,7 @@ func SquaresSVG(canvas *svg.SVG, key string, color1, color2 color.RGBA, size int canvas.Rect(x, y, quadrantSize, quadrantSize, fillFromRGBA(colorMap[xQ])) } } canvas.End() } func fillFromRGBA(c color.RGBA) string { Loading Loading
app-backend/main.go +2 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,8 @@ func main() { r.HandleFunc("/squares/?", squares.Random) r.HandleFunc("/squares/random/?", squares.Random) r.HandleFunc("/squares/random/[0-8]/?", squares.RandomColor) r.HandleFunc("/squares/[a-zA-Z0-9]+/?", squares.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9]+/?", squares.Color) // cached r.HandleFunc("/squares/[a-zA-Z0-9\\.]+/?", squares.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9\\.]+/?", squares.Color) // cached r.AddStaticResource(root) Loading
controllers/checkerboard/checkerboard.go +4 −7 Original line number Diff line number Diff line package checkerboard import ( "github.com/ajstarks/svgo" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" Loading Loading @@ -29,9 +28,8 @@ func Color(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.Grid6X6SVG(canvas, colorMap[int(intID)][0], colorMap[int(intID)][1], size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.Grid6X6SVG(w, colorMap[int(intID)][0], colorMap[int(intID)][1], size) } } } Loading @@ -48,8 +46,7 @@ func Checkerboard(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.Grid6X6SVG(canvas, color1, color2, size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.Grid6X6SVG(w, color1, color2, size) } }
controllers/squares/random.go +5 −7 Original line number Diff line number Diff line package squares import ( "github.com/ajstarks/svgo" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" Loading Loading @@ -32,9 +31,8 @@ func Random(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.RandomGrid6X6SVG(canvas, bg, fg, size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.RandomGrid6X6SVG(w, bg, fg, size) } } Loading @@ -53,9 +51,9 @@ func RandomColor(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.RandomGrid6X6SVG(canvas, colorMap[int(intID)][0], colorMap[int(intID)][1], size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.RandomGrid6X6SVG(w, colorMap[int(intID)][0], colorMap[int(intID)][1], size) } } }
controllers/squares/square.go +4 −7 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ package squares import ( "crypto/md5" "fmt" "github.com/ajstarks/svgo" tgColors "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" Loading Loading @@ -57,9 +56,8 @@ func Square(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.SquaresSVG(canvas, key, bg, fg, size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.SquaresSVG(w, key, bg, fg, size) } } } Loading Loading @@ -97,9 +95,8 @@ func Color(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { canvas := svg.New(w) draw.SquaresSVG(canvas, key, colorMap[int(colorId)][0], colorMap[int(colorId)][1], size) write.ImageSVG(w, canvas) write.ImageSVG(w) draw.SquaresSVG(w, key, colorMap[int(colorId)][0], colorMap[int(colorId)][1], size) } } else { log.Printf("error when extracting permalink string: %v", err) Loading
draw/draw.go +10 −3 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import ( "log" "math" "math/rand" "net/http" "strconv" ) Loading @@ -31,7 +32,8 @@ func Grid6X6(m *image.RGBA, color1, color2 color.RGBA) { } // Grid6X6SVG builds an image with 6X6 quadrants of alternate colors. func Grid6X6SVG(canvas *svg.SVG, color1, color2 color.RGBA, size int) { func Grid6X6SVG(w http.ResponseWriter, color1, color2 color.RGBA, size int) { canvas := svg.New(w) canvas.Start(size, size) squares := 6 quadrantSize := size / squares Loading @@ -52,6 +54,7 @@ func Grid6X6SVG(canvas *svg.SVG, color1, color2 color.RGBA, size int) { canvas.Rect(x, y, quadrantSize, quadrantSize, fillFromRGBA(colorMap[xQ])) } } canvas.End() } // RandomGrid6X6 builds a grid image with with 2 colors selected at random for each quadrant. Loading @@ -77,7 +80,8 @@ func RandomGrid6X6(m *image.RGBA, color1, color2 color.RGBA) { } // RandomGrid6X6SVG builds a grid image with with 2 colors selected at random for each quadrant. func RandomGrid6X6SVG(canvas *svg.SVG, color1, color2 color.RGBA, size int) { func RandomGrid6X6SVG(w http.ResponseWriter, color1, color2 color.RGBA, size int) { canvas := svg.New(w) canvas.Start(size, size) squares := 6 quadrantSize := size / squares Loading @@ -94,6 +98,7 @@ func RandomGrid6X6SVG(canvas *svg.SVG, color1, color2 color.RGBA, size int) { canvas.Rect(x, y, quadrantSize, quadrantSize, fillFromRGBA(colorMap[xQ])) } } canvas.End() } // getRandomColor returns a random color between c1 and c2 Loading Loading @@ -191,7 +196,8 @@ func Squares(m *image.RGBA, key string, color1, color2 color.RGBA) { } } func SquaresSVG(canvas *svg.SVG, key string, color1, color2 color.RGBA, size int) { func SquaresSVG(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) canvas.Start(size, size) squares := 6 Loading @@ -216,6 +222,7 @@ func SquaresSVG(canvas *svg.SVG, key string, color1, color2 color.RGBA, size int canvas.Rect(x, y, quadrantSize, quadrantSize, fillFromRGBA(colorMap[xQ])) } } canvas.End() } func fillFromRGBA(c color.RGBA) string { Loading