Loading app-backend/main.go +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ func main() { r.HandleFunc("/squares", squares.Random) r.HandleFunc("/squares/banner/random", squares.BannerRandom) r.HandleFunc("/squares/banner/random/gradient", squares.BannerRandomGradient) r.HandleFunc("/squares/gradient", squares.Gradient) r.HandleFunc("/squares/:key", squares.Square) //cached r.HandleFunc("/isogrids/banner/random", isogrids.BannerRandom) Loading controllers/squares/gradient.go 0 → 100644 +60 −0 Original line number Diff line number Diff line package squares import ( "crypto/md5" "fmt" "image/color" "io" "log" "net/http" "github.com/taironas/route" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw/squares" "github.com/taironas/tinygraphs/extract" "github.com/taironas/tinygraphs/write" ) // Gradient handler for "/squares/gradient" // generates a color gradient random grid image. func Gradient(w http.ResponseWriter, r *http.Request) { 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 = "hello" } theme := extract.Theme(r) h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) numColors := extract.NumColors(r) colorMap := colors.MapOfColorThemes() bg, fg := extract.ExtraColors(r, colorMap) var colors []color.RGBA if theme != "base" { if _, ok := colorMap[theme]; ok { colors = append(colors, colorMap[theme][0:numColors]...) } else { colors = append(colors, colorMap["base"]...) } } else { colors = append(colors, bg, fg) } size := extract.Size(r) // if f := extract.Format(r); f == format.JPEG { // m := image.NewRGBA(image.Rect(0, 0, size, size)) // squares.Squares(m, key, colors) // var img image.Image = m // write.ImageJPEG(w, &img) // } else if f == format.SVG { write.ImageSVG(w) squares.GradientSVG(w, key, colors, size) // } } Loading
app-backend/main.go +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ func main() { r.HandleFunc("/squares", squares.Random) r.HandleFunc("/squares/banner/random", squares.BannerRandom) r.HandleFunc("/squares/banner/random/gradient", squares.BannerRandomGradient) r.HandleFunc("/squares/gradient", squares.Gradient) r.HandleFunc("/squares/:key", squares.Square) //cached r.HandleFunc("/isogrids/banner/random", isogrids.BannerRandom) Loading
controllers/squares/gradient.go 0 → 100644 +60 −0 Original line number Diff line number Diff line package squares import ( "crypto/md5" "fmt" "image/color" "io" "log" "net/http" "github.com/taironas/route" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw/squares" "github.com/taironas/tinygraphs/extract" "github.com/taironas/tinygraphs/write" ) // Gradient handler for "/squares/gradient" // generates a color gradient random grid image. func Gradient(w http.ResponseWriter, r *http.Request) { 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 = "hello" } theme := extract.Theme(r) h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) numColors := extract.NumColors(r) colorMap := colors.MapOfColorThemes() bg, fg := extract.ExtraColors(r, colorMap) var colors []color.RGBA if theme != "base" { if _, ok := colorMap[theme]; ok { colors = append(colors, colorMap[theme][0:numColors]...) } else { colors = append(colors, colorMap["base"]...) } } else { colors = append(colors, bg, fg) } size := extract.Size(r) // if f := extract.Format(r); f == format.JPEG { // m := image.NewRGBA(image.Rect(0, 0, size, size)) // squares.Squares(m, key, colors) // var img image.Image = m // write.ImageJPEG(w, &img) // } else if f == format.SVG { write.ImageSVG(w) squares.GradientSVG(w, key, colors, size) // } }