Loading controllers/checkerboard/checkerboard.go +33 −22 Original line number Diff line number Diff line Loading @@ -15,13 +15,25 @@ import ( "github.com/taironas/tinygraphs/write" ) func init() { log.SetFlags(log.Lshortfile) } // Color is the handler for /checkerboard/:colorId // build a 6x6 checkerboard with alternate colors based on the number passed in the url func Color(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") if colorId, err := strconv.ParseInt(id, 0, 64); err != nil { log.Printf("error when extracting permalink id: %v", err) } else { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'key' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } size := extract.Size(r) colorMap := colors.MapOfColorPatterns() var c1, c2 color.RGBA Loading @@ -43,7 +55,6 @@ func Color(w http.ResponseWriter, r *http.Request) { draw.Grid6X6SVG(w, c1, c2, size) } } } // Checkerboard is the handler for /checkerboard // build a 6x6 checkerboard with alternate black and white colors. Loading controllers/isogrids/isogrids.go +81 −50 Original line number Diff line number Diff line Loading @@ -3,34 +3,43 @@ package isogrids import ( "crypto/md5" "fmt" "strconv" "image/color" "io" "log" "net/http" "strconv" "github.com/taironas/route" tgColors "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" "github.com/taironas/tinygraphs/write" ) func init() { log.SetFlags(log.Lshortfile) } // Isogrids is the handler for /isogrids/:key // builds a 10x10 grid with alternate colors based on the string passed in the url. func Isogrids(w http.ResponseWriter, r *http.Request) { key, _ := route.Context.Get(r, "key") var err error var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -41,27 +50,37 @@ func Isogrids(w http.ResponseWriter, r *http.Request) { // Color is the handler for /isogrids/:colorId/:key // builds a 10x10 grid with alternate colors based on the string passed in the url. func Color(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } colorId, err := strconv.ParseInt(id, 0, 64) if err != nil { var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } key, _ := route.Context.Get(r, "key") var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[int(colorId)][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[int(colorId)][1] } size := extract.Size(r) write.ImageSVG(w) draw.Isogrids(w, key, bg, fg, size) Loading @@ -70,12 +89,12 @@ func Color(w http.ResponseWriter, r *http.Request) { func Skeleton(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -86,12 +105,12 @@ func Skeleton(w http.ResponseWriter, r *http.Request) { func Diagonals(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -102,12 +121,12 @@ func Diagonals(w http.ResponseWriter, r *http.Request) { func HalfDiagonals(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -118,12 +137,12 @@ func HalfDiagonals(w http.ResponseWriter, r *http.Request) { func GridBW(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -134,12 +153,12 @@ func GridBW(w http.ResponseWriter, r *http.Request) { func Grid2Colors(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -150,12 +169,12 @@ func Grid2Colors(w http.ResponseWriter, r *http.Request) { func Random(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -164,11 +183,18 @@ func Random(w http.ResponseWriter, r *http.Request) { } func RandomColor(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") colorId, err := strconv.ParseInt(id, 0, 64) if err != nil { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { Loading Loading @@ -199,18 +225,23 @@ func RandomMirror(w http.ResponseWriter, r *http.Request) { } func RandomMirrorColor(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") colorId, err := strconv.ParseInt(id, 0, 64) if err != nil { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[int(colorId)][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[int(colorId)][1] } size := extract.Size(r) Loading controllers/squares/random.go +30 −22 Original line number Diff line number Diff line Loading @@ -42,10 +42,19 @@ func Random(w http.ResponseWriter, r *http.Request) { // handler for "/squares/random/:colorId" // generates a grid random image with a specific color based on the colorMap func RandomColor(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") if colorId, err := strconv.ParseInt(id, 0, 64); err != nil { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { log.Printf("error when extracting permalink id: %v", err) } else { colorId = 0 } size := extract.Size(r) colorMap := colors.MapOfColorPatterns() Loading @@ -68,4 +77,3 @@ func RandomColor(w http.ResponseWriter, r *http.Request) { draw.RandomGrid6X6SVG(w, c1, c2, size) } } } controllers/squares/square.go +33 −9 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ import ( "crypto/md5" "fmt" "image" "image/color" "io" "log" "net/http" "strconv" "strings" Loading @@ -17,10 +19,20 @@ import ( "github.com/taironas/tinygraphs/write" ) func init() { log.SetFlags(log.Lshortfile) } // Square is the handler for /squares/:key // builds a 6x6 grid with alternate colors based on the number passed in the url. func Square(w http.ResponseWriter, r *http.Request) { key, _ := route.Context.Get(r, "key") var err error var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) Loading @@ -37,14 +49,15 @@ func Square(w http.ResponseWriter, r *http.Request) { } colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) if f := extract.Format(r); f == format.JPEG { m := image.NewRGBA(image.Rect(0, 0, size, size)) Loading @@ -61,13 +74,24 @@ func Square(w http.ResponseWriter, r *http.Request) { // build a 6x6 grid with alternate colors based on the number passed in the url func Color(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") colorId, err := strconv.ParseInt(id, 0, 64) if err != nil { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } key, _ := route.Context.Get(r, "key") var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) Loading Loading
controllers/checkerboard/checkerboard.go +33 −22 Original line number Diff line number Diff line Loading @@ -15,13 +15,25 @@ import ( "github.com/taironas/tinygraphs/write" ) func init() { log.SetFlags(log.Lshortfile) } // Color is the handler for /checkerboard/:colorId // build a 6x6 checkerboard with alternate colors based on the number passed in the url func Color(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") if colorId, err := strconv.ParseInt(id, 0, 64); err != nil { log.Printf("error when extracting permalink id: %v", err) } else { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'key' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } size := extract.Size(r) colorMap := colors.MapOfColorPatterns() var c1, c2 color.RGBA Loading @@ -43,7 +55,6 @@ func Color(w http.ResponseWriter, r *http.Request) { draw.Grid6X6SVG(w, c1, c2, size) } } } // Checkerboard is the handler for /checkerboard // build a 6x6 checkerboard with alternate black and white colors. Loading
controllers/isogrids/isogrids.go +81 −50 Original line number Diff line number Diff line Loading @@ -3,34 +3,43 @@ package isogrids import ( "crypto/md5" "fmt" "strconv" "image/color" "io" "log" "net/http" "strconv" "github.com/taironas/route" tgColors "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" "github.com/taironas/tinygraphs/write" ) func init() { log.SetFlags(log.Lshortfile) } // Isogrids is the handler for /isogrids/:key // builds a 10x10 grid with alternate colors based on the string passed in the url. func Isogrids(w http.ResponseWriter, r *http.Request) { key, _ := route.Context.Get(r, "key") var err error var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -41,27 +50,37 @@ func Isogrids(w http.ResponseWriter, r *http.Request) { // Color is the handler for /isogrids/:colorId/:key // builds a 10x10 grid with alternate colors based on the string passed in the url. func Color(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } colorId, err := strconv.ParseInt(id, 0, 64) if err != nil { var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } key, _ := route.Context.Get(r, "key") var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[int(colorId)][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[int(colorId)][1] } size := extract.Size(r) write.ImageSVG(w) draw.Isogrids(w, key, bg, fg, size) Loading @@ -70,12 +89,12 @@ func Color(w http.ResponseWriter, r *http.Request) { func Skeleton(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -86,12 +105,12 @@ func Skeleton(w http.ResponseWriter, r *http.Request) { func Diagonals(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -102,12 +121,12 @@ func Diagonals(w http.ResponseWriter, r *http.Request) { func HalfDiagonals(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -118,12 +137,12 @@ func HalfDiagonals(w http.ResponseWriter, r *http.Request) { func GridBW(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -134,12 +153,12 @@ func GridBW(w http.ResponseWriter, r *http.Request) { func Grid2Colors(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -150,12 +169,12 @@ func Grid2Colors(w http.ResponseWriter, r *http.Request) { func Random(w http.ResponseWriter, r *http.Request) { colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var err error var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) Loading @@ -164,11 +183,18 @@ func Random(w http.ResponseWriter, r *http.Request) { } func RandomColor(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") colorId, err := strconv.ParseInt(id, 0, 64) if err != nil { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { Loading Loading @@ -199,18 +225,23 @@ func RandomMirror(w http.ResponseWriter, r *http.Request) { } func RandomMirrorColor(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") colorId, err := strconv.ParseInt(id, 0, 64) if err != nil { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[int(colorId)][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[int(colorId)][1] } size := extract.Size(r) Loading
controllers/squares/random.go +30 −22 Original line number Diff line number Diff line Loading @@ -42,10 +42,19 @@ func Random(w http.ResponseWriter, r *http.Request) { // handler for "/squares/random/:colorId" // generates a grid random image with a specific color based on the colorMap func RandomColor(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") if colorId, err := strconv.ParseInt(id, 0, 64); err != nil { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { log.Printf("error when extracting permalink id: %v", err) } else { colorId = 0 } size := extract.Size(r) colorMap := colors.MapOfColorPatterns() Loading @@ -68,4 +77,3 @@ func RandomColor(w http.ResponseWriter, r *http.Request) { draw.RandomGrid6X6SVG(w, c1, c2, size) } } }
controllers/squares/square.go +33 −9 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ import ( "crypto/md5" "fmt" "image" "image/color" "io" "log" "net/http" "strconv" "strings" Loading @@ -17,10 +19,20 @@ import ( "github.com/taironas/tinygraphs/write" ) func init() { log.SetFlags(log.Lshortfile) } // Square is the handler for /squares/:key // builds a 6x6 grid with alternate colors based on the number passed in the url. func Square(w http.ResponseWriter, r *http.Request) { key, _ := route.Context.Get(r, "key") var err error var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) Loading @@ -37,14 +49,15 @@ func Square(w http.ResponseWriter, r *http.Request) { } colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { var bg, fg color.RGBA if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] } size := extract.Size(r) if f := extract.Format(r); f == format.JPEG { m := image.NewRGBA(image.Rect(0, 0, size, size)) Loading @@ -61,13 +74,24 @@ func Square(w http.ResponseWriter, r *http.Request) { // build a 6x6 grid with alternate colors based on the number passed in the url func Color(w http.ResponseWriter, r *http.Request) { id, _ := route.Context.Get(r, "colorId") colorId, err := strconv.ParseInt(id, 0, 64) if err != nil { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } key, _ := route.Context.Get(r, "key") var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) Loading