Loading controllers/isogrids/gradient.go +1 −1 Original line number Diff line number Diff line Loading @@ -40,5 +40,5 @@ func BannerGradient(w http.ResponseWriter, r *http.Request) { } write.ImageSVG(w) isogrids.RandomGradientSVG(w, colors, gColors, gv, width, height, xtriangles) isogrids.RandomGradientColor(w, colors, gColors, gv, width, height, xtriangles) } draw/isogrids/gradient.go +50 −25 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ package isogrids import ( "image/color" "math" "net/http" "github.com/ajstarks/svgo" Loading @@ -10,8 +9,7 @@ import ( "github.com/taironas/tinygraphs/draw" ) // RandomGradientSVG builds an image. func RandomGradientSVG(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, xsquares int) { func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, lines int) { var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) Loading @@ -30,37 +28,64 @@ func RandomGradientSVG(w http.ResponseWriter, colors, gColors []color.RGBA, gv c canvas.DefEnd() canvas.Rect(0, 0, width, height, "fill:url(#gradientColors)") squares := xsquares quadrantSize := width / squares middle := math.Ceil(float64(squares) / float64(2)) fringeSize := width / lines distance := distanceTo3rdPoint(fringeSize) fringeSize = distance lines = width / fringeSize colorMap := make(map[int]color.RGBA) colorIndex := make(map[int]int) for yQ := 0; yQ < squares; yQ++ { y := yQ * quadrantSize for xL := 0; xL <= lines; xL++ { colorMap = make(map[int]color.RGBA) colorIndex = make(map[int]int) for xQ := 0; xQ < squares; xQ++ { x := xQ * quadrantSize fill := "" if _, ok := colorMap[xQ]; !ok { if float64(xQ) < middle { colorIndex[xQ] = draw.RandomIndexFromArray(colors) colorMap[xQ] = colors[colorIndex[xQ]] } else if xQ < squares { colorIndex[xQ] = colorIndex[squares-xQ-1] colorMap[xQ] = colorMap[squares-xQ-1] for yL := -1; yL <= lines; yL++ { var x1, x2, y1, y2, y3 int var fill string = "" if (xL % 2) == 0 { x1, y1, x2, y2, _, y3 = right1stTriangle(xL, yL, fringeSize, distance) } else { colorIndex[xQ] = colorIndex[0] colorMap[xQ] = colorMap[0] x1, y1, x2, y2, _, y3 = left1stTriangle(xL, yL, fringeSize, distance) } } if colorIndex[xQ] != 0 { xs := []int{x2, x1, x2} ys := []int{y1, y2, y3} colorIndex[yL] = draw.RandomIndexFromArray(colors) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[xQ]) fill = draw.FillFromRGBA(colorMap[yL]) } canvas.Polygon(xs, ys, fill) var x11, x12, y11, y12, y13 int if (xL % 2) == 0 { x11, y11, x12, y12, _, y13 = left2ndTriangle(xL, yL, fringeSize, distance) // we make sure that the previous triangle and this one touch each other in this point. y12 = y3 } else { x11, y11, x12, y12, _, y13 = right2ndTriangle(xL, yL, fringeSize, distance) // we make sure that the previous triangle and this one touch each other in this point. y12 = y1 + fringeSize } xs1 := []int{x12, x11, x12} ys1 := []int{y11, y12, y13} colorIndex[yL] = draw.RandomIndexFromArray(colors) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[yL]) } canvas.Rect(x, y, quadrantSize, quadrantSize, fill) canvas.Polygon(xs1, ys1, fill) } } canvas.End() Loading Loading
controllers/isogrids/gradient.go +1 −1 Original line number Diff line number Diff line Loading @@ -40,5 +40,5 @@ func BannerGradient(w http.ResponseWriter, r *http.Request) { } write.ImageSVG(w) isogrids.RandomGradientSVG(w, colors, gColors, gv, width, height, xtriangles) isogrids.RandomGradientColor(w, colors, gColors, gv, width, height, xtriangles) }
draw/isogrids/gradient.go +50 −25 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ package isogrids import ( "image/color" "math" "net/http" "github.com/ajstarks/svgo" Loading @@ -10,8 +9,7 @@ import ( "github.com/taironas/tinygraphs/draw" ) // RandomGradientSVG builds an image. func RandomGradientSVG(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, xsquares int) { func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, lines int) { var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) Loading @@ -30,37 +28,64 @@ func RandomGradientSVG(w http.ResponseWriter, colors, gColors []color.RGBA, gv c canvas.DefEnd() canvas.Rect(0, 0, width, height, "fill:url(#gradientColors)") squares := xsquares quadrantSize := width / squares middle := math.Ceil(float64(squares) / float64(2)) fringeSize := width / lines distance := distanceTo3rdPoint(fringeSize) fringeSize = distance lines = width / fringeSize colorMap := make(map[int]color.RGBA) colorIndex := make(map[int]int) for yQ := 0; yQ < squares; yQ++ { y := yQ * quadrantSize for xL := 0; xL <= lines; xL++ { colorMap = make(map[int]color.RGBA) colorIndex = make(map[int]int) for xQ := 0; xQ < squares; xQ++ { x := xQ * quadrantSize fill := "" if _, ok := colorMap[xQ]; !ok { if float64(xQ) < middle { colorIndex[xQ] = draw.RandomIndexFromArray(colors) colorMap[xQ] = colors[colorIndex[xQ]] } else if xQ < squares { colorIndex[xQ] = colorIndex[squares-xQ-1] colorMap[xQ] = colorMap[squares-xQ-1] for yL := -1; yL <= lines; yL++ { var x1, x2, y1, y2, y3 int var fill string = "" if (xL % 2) == 0 { x1, y1, x2, y2, _, y3 = right1stTriangle(xL, yL, fringeSize, distance) } else { colorIndex[xQ] = colorIndex[0] colorMap[xQ] = colorMap[0] x1, y1, x2, y2, _, y3 = left1stTriangle(xL, yL, fringeSize, distance) } } if colorIndex[xQ] != 0 { xs := []int{x2, x1, x2} ys := []int{y1, y2, y3} colorIndex[yL] = draw.RandomIndexFromArray(colors) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[xQ]) fill = draw.FillFromRGBA(colorMap[yL]) } canvas.Polygon(xs, ys, fill) var x11, x12, y11, y12, y13 int if (xL % 2) == 0 { x11, y11, x12, y12, _, y13 = left2ndTriangle(xL, yL, fringeSize, distance) // we make sure that the previous triangle and this one touch each other in this point. y12 = y3 } else { x11, y11, x12, y12, _, y13 = right2ndTriangle(xL, yL, fringeSize, distance) // we make sure that the previous triangle and this one touch each other in this point. y12 = y1 + fringeSize } xs1 := []int{x12, x11, x12} ys1 := []int{y11, y12, y13} colorIndex[yL] = draw.RandomIndexFromArray(colors) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[yL]) } canvas.Rect(x, y, quadrantSize, quadrantSize, fill) canvas.Polygon(xs1, ys1, fill) } } canvas.End() Loading