Loading app-backend/main.go +2 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ func main() { r.HandleFunc("/squares/:key", squares.Square) //cached r.HandleFunc("/isogrids/banner/random", isogrids.BannerRandom) r.HandleFunc("/isogrids/banner/random/gradient", isogrids.BannerRandomGradient) r.HandleFunc("/isogrids/:key", isogrids.Isogrids) r.HandleFunc("/spaceinvaders/:key", spaceinvaders.SpaceInvaders) Loading controllers/isogrids/banner.go +31 −0 Original line number Diff line number Diff line Loading @@ -40,3 +40,34 @@ func BannerRandom(w http.ResponseWriter, r *http.Request) { write.ImageSVG(w) isogrids.Random(w, "", colors, width, height, xt) } // BannerRandomGradinet handler for /isogrids/banner/random/gradient. // Generates a random gradient banner isogrid image. func BannerRandomGradient(w http.ResponseWriter, r *http.Request) { width := extract.Width(r) height := extract.Height(r) colorMap := colors.MapOfColorThemes() bg, fg := extract.ExtraColors(r, colorMap) theme := extract.Theme(r) if val, ok := colorMap[theme]; ok { bg = val[0] fg = val[1] } var colors []color.RGBA if theme != "base" { if _, ok := colorMap[theme]; ok { numColors := extract.NumColors(r) colors = append(colors, colorMap[theme][0:numColors]...) } else { colors = append(colors, colorMap["base"]...) } } else { colors = append(colors, bg, fg) } xt := extract.XTriangles(r) write.ImageSVG(w) isogrids.RandomGradient(w, "", colors, width, height, xt) } draw/isogrids/isogrids.go +55 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,61 @@ func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, heigh canvas.End() } // Random creates an isogrids svg image with half diagonals. func RandomGradient(w http.ResponseWriter, key string, colors []color.RGBA, width, height, lines int) { canvas := svg.New(w) canvas.Start(width, height) fringeSize := width / lines // triangle grid here: for xL := -1; xL <= lines; xL++ { percentage := int(float64(xL) / float64(lines) * 100) for yL := -1; yL <= lines; yL++ { var x1, x2, x3, y1, y2, y3 int if (xL % 2) == 0 { x1 = (xL) * fringeSize x2 = (xL + 1) * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } else { x1 = (xL + 1) * fringeSize x2 = xL * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } xs := []int{x1, x2, x3} ys := []int{y1, y2, y3} canvas.Polygon(xs, ys, draw.FillFromRGBA(draw.ColorByPercentage(colors, percentage))) //draw.RandomColorFromArray(colors))) var x11, x12, x13, y11, y12, y13 int if (xL % 2) == 0 { x11 = (xL + 1) * fringeSize x12 = (xL) * fringeSize x13 = x11 y11 = yL*fringeSize + fringeSize/2 y12 = y11 + fringeSize/2 y13 = (yL+1)*fringeSize + fringeSize/2 } else { x11 = (xL) * fringeSize x12 = (xL + 1) * fringeSize x13 = x11 y11 = yL*fringeSize + fringeSize/2 y12 = y1 + fringeSize y13 = (yL+1)*fringeSize + fringeSize/2 } xs1 := []int{x11, x12, x13} ys1 := []int{y11, y12, y13} canvas.Polygon(xs1, ys1, draw.FillFromRGBA(draw.ColorByPercentage(colors, percentage))) //draw.RandomColorFromArray(colors))) } } canvas.End() } // RandomMirror builds an image with 10x10 grids of half diagonals func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size int) { canvas := svg.New(w) Loading Loading
app-backend/main.go +2 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ func main() { r.HandleFunc("/squares/:key", squares.Square) //cached r.HandleFunc("/isogrids/banner/random", isogrids.BannerRandom) r.HandleFunc("/isogrids/banner/random/gradient", isogrids.BannerRandomGradient) r.HandleFunc("/isogrids/:key", isogrids.Isogrids) r.HandleFunc("/spaceinvaders/:key", spaceinvaders.SpaceInvaders) Loading
controllers/isogrids/banner.go +31 −0 Original line number Diff line number Diff line Loading @@ -40,3 +40,34 @@ func BannerRandom(w http.ResponseWriter, r *http.Request) { write.ImageSVG(w) isogrids.Random(w, "", colors, width, height, xt) } // BannerRandomGradinet handler for /isogrids/banner/random/gradient. // Generates a random gradient banner isogrid image. func BannerRandomGradient(w http.ResponseWriter, r *http.Request) { width := extract.Width(r) height := extract.Height(r) colorMap := colors.MapOfColorThemes() bg, fg := extract.ExtraColors(r, colorMap) theme := extract.Theme(r) if val, ok := colorMap[theme]; ok { bg = val[0] fg = val[1] } var colors []color.RGBA if theme != "base" { if _, ok := colorMap[theme]; ok { numColors := extract.NumColors(r) colors = append(colors, colorMap[theme][0:numColors]...) } else { colors = append(colors, colorMap["base"]...) } } else { colors = append(colors, bg, fg) } xt := extract.XTriangles(r) write.ImageSVG(w) isogrids.RandomGradient(w, "", colors, width, height, xt) }
draw/isogrids/isogrids.go +55 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,61 @@ func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, heigh canvas.End() } // Random creates an isogrids svg image with half diagonals. func RandomGradient(w http.ResponseWriter, key string, colors []color.RGBA, width, height, lines int) { canvas := svg.New(w) canvas.Start(width, height) fringeSize := width / lines // triangle grid here: for xL := -1; xL <= lines; xL++ { percentage := int(float64(xL) / float64(lines) * 100) for yL := -1; yL <= lines; yL++ { var x1, x2, x3, y1, y2, y3 int if (xL % 2) == 0 { x1 = (xL) * fringeSize x2 = (xL + 1) * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } else { x1 = (xL + 1) * fringeSize x2 = xL * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } xs := []int{x1, x2, x3} ys := []int{y1, y2, y3} canvas.Polygon(xs, ys, draw.FillFromRGBA(draw.ColorByPercentage(colors, percentage))) //draw.RandomColorFromArray(colors))) var x11, x12, x13, y11, y12, y13 int if (xL % 2) == 0 { x11 = (xL + 1) * fringeSize x12 = (xL) * fringeSize x13 = x11 y11 = yL*fringeSize + fringeSize/2 y12 = y11 + fringeSize/2 y13 = (yL+1)*fringeSize + fringeSize/2 } else { x11 = (xL) * fringeSize x12 = (xL + 1) * fringeSize x13 = x11 y11 = yL*fringeSize + fringeSize/2 y12 = y1 + fringeSize y13 = (yL+1)*fringeSize + fringeSize/2 } xs1 := []int{x11, x12, x13} ys1 := []int{y11, y12, y13} canvas.Polygon(xs1, ys1, draw.FillFromRGBA(draw.ColorByPercentage(colors, percentage))) //draw.RandomColorFromArray(colors))) } } canvas.End() } // RandomMirror builds an image with 10x10 grids of half diagonals func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size int) { canvas := svg.New(w) Loading