Loading draw/isogrids/gradient.go +5 −14 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) percentage := uint8(100 / len(gColors)) percentage := uint8(0) step := uint8(100 / len(gColors)) for i, c := range gColors { Loading Loading @@ -47,7 +47,6 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colorIndex = make(map[int]int) 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 { Loading @@ -59,14 +58,10 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colorIndex[yL] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[yL]) if colorIndex[yL] == 0 { canvas.Polygon(xs, ys, 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) Loading @@ -85,13 +80,9 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colorIndex[yL] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[yL]) if colorIndex[yL] == 0 { canvas.Polygon(xs1, ys1, draw.FillFromRGBA(colorMap[yL])) } canvas.Polygon(xs1, ys1, fill) } } canvas.End() Loading draw/isogrids/labs.go +22 −22 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import ( "github.com/taironas/tinygraphs/draw" ) // Diagonals builds an image with 10x10 grids of half diagonals // Diagonals builds an image with 10x10 grids of diagonals. func Diagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) canvas.Start(size, size) Loading @@ -17,33 +17,33 @@ func Diagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, siz lines := 10 fringeSize := size / lines style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Gstyle(style) for xL := 0; xL <= lines; xL++ { x := xL * fringeSize lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Line(x, 0, x, lastY, style) canvas.Line(x, 0, x, lastY) } for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := 0 yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) canvas.Line(xPrev, yPrev, x, 0) } } for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) canvas.Line(xPrev, yPrev, x, 0) } } canvas.Gend() canvas.End() } Loading @@ -55,33 +55,33 @@ func HalfDiagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, lines := 10 fringeSize := size / lines style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Gstyle(style) for xL := 0; xL <= lines; xL++ { x := xL * fringeSize lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Line(x, 0, x, lastY, style) canvas.Line(x, 0, x, lastY) } for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := 0 yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x*2, 0, style) canvas.Line(xPrev, yPrev, x*2, 0) } } for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize * 2 style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL*2) * fringeSize if yPrev > 0 { canvas.Line(x, 0, xPrev, yPrev/2, style) canvas.Line(x, 0, xPrev, yPrev/2) } } canvas.Gend() canvas.End() } Loading @@ -93,37 +93,37 @@ func Skeleton(w http.ResponseWriter, key string, color1, color2 color.RGBA, size lines := 10 fringeSize := size / lines style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Gstyle(style) for xL := 0; xL <= lines; xL++ { x := xL * fringeSize firstY := 0 lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) if (xL % 2) != 0 { lastY = lastY - fringeSize/2 firstY = fringeSize / 2 } canvas.Line(x, firstY, x, lastY, style) canvas.Line(x, firstY, x, lastY) } for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := 0 yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x*2, 0, style) canvas.Line(xPrev, yPrev, x*2, 0) } } for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize * 2 style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL*2) * fringeSize if yPrev > 0 { canvas.Line(x, 0, xPrev, yPrev/2, style) canvas.Line(x, 0, xPrev, yPrev/2) } } canvas.Gend() canvas.End() } draw/spaceinvaders/spaceinvaders.go +11 −3 Original line number Diff line number Diff line Loading @@ -21,13 +21,17 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size quadrantSize := size / squares middle := math.Ceil(float64(squares) / float64(2)) colorMap := make(map[int]color.RGBA) // style of space invader background canvas.Gstyle(draw.FillFromRGBA(colors[0])) for yQ := 0; yQ < squares; yQ++ { y := yQ * quadrantSize colorMap = make(map[int]color.RGBA) for xQ := 0; xQ < squares; xQ++ { x := xQ * quadrantSize fill := draw.FillFromRGBA(colors[0]) fill := "" if _, ok := colorMap[xQ]; !ok { colorMap[xQ] = selectColor(colorMap, key, colors, middle, xQ, yQ, squares) } Loading Loading @@ -65,10 +69,14 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if hasLegOrFoot(invader, lowBodyIndex, xQ, yQ) { fill = draw.FillFromRGBA(colorMap[xQ]) } if len(fill) > 0 { canvas.Rect(x, y, quadrantSize, quadrantSize, fill) } else { canvas.Rect(x, y, quadrantSize, quadrantSize) } } } canvas.Gend() canvas.End() } Loading draw/spaceinvaders/spaceinvaders_test.go +1554 −1501 File changed.Preview size limit exceeded, changes collapsed. Show changes draw/squares/gradient.go +5 −9 Original line number Diff line number Diff line Loading @@ -15,8 +15,7 @@ func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) percentage := uint8(100 / len(gColors)) percentage := uint8(0) step := uint8(100 / len(gColors)) for i, c := range gColors { gradientColors[i] = svg.Offcolor{ Loading Loading @@ -44,19 +43,16 @@ func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, colorIndex = make(map[int]int) for xQ := 0; xQ <= squares+1; xQ++ { x := xQ * quadrantSize fill := "" if _, ok := colorMap[xQ]; !ok { colorIndex[xQ] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[xQ] = colors[colorIndex[xQ]] } if colorIndex[xQ] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[xQ]) } if colorIndex[xQ] == 0 { fill := draw.FillFromRGBA(colorMap[xQ]) canvas.Rect(x, y, quadrantSize, quadrantSize, fill) } } } canvas.End() } Loading
draw/isogrids/gradient.go +5 −14 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) percentage := uint8(100 / len(gColors)) percentage := uint8(0) step := uint8(100 / len(gColors)) for i, c := range gColors { Loading Loading @@ -47,7 +47,6 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colorIndex = make(map[int]int) 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 { Loading @@ -59,14 +58,10 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colorIndex[yL] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[yL]) if colorIndex[yL] == 0 { canvas.Polygon(xs, ys, 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) Loading @@ -85,13 +80,9 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colorIndex[yL] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[yL]) if colorIndex[yL] == 0 { canvas.Polygon(xs1, ys1, draw.FillFromRGBA(colorMap[yL])) } canvas.Polygon(xs1, ys1, fill) } } canvas.End() Loading
draw/isogrids/labs.go +22 −22 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import ( "github.com/taironas/tinygraphs/draw" ) // Diagonals builds an image with 10x10 grids of half diagonals // Diagonals builds an image with 10x10 grids of diagonals. func Diagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) canvas.Start(size, size) Loading @@ -17,33 +17,33 @@ func Diagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, siz lines := 10 fringeSize := size / lines style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Gstyle(style) for xL := 0; xL <= lines; xL++ { x := xL * fringeSize lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Line(x, 0, x, lastY, style) canvas.Line(x, 0, x, lastY) } for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := 0 yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) canvas.Line(xPrev, yPrev, x, 0) } } for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) canvas.Line(xPrev, yPrev, x, 0) } } canvas.Gend() canvas.End() } Loading @@ -55,33 +55,33 @@ func HalfDiagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, lines := 10 fringeSize := size / lines style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Gstyle(style) for xL := 0; xL <= lines; xL++ { x := xL * fringeSize lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Line(x, 0, x, lastY, style) canvas.Line(x, 0, x, lastY) } for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := 0 yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x*2, 0, style) canvas.Line(xPrev, yPrev, x*2, 0) } } for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize * 2 style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL*2) * fringeSize if yPrev > 0 { canvas.Line(x, 0, xPrev, yPrev/2, style) canvas.Line(x, 0, xPrev, yPrev/2) } } canvas.Gend() canvas.End() } Loading @@ -93,37 +93,37 @@ func Skeleton(w http.ResponseWriter, key string, color1, color2 color.RGBA, size lines := 10 fringeSize := size / lines style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) canvas.Gstyle(style) for xL := 0; xL <= lines; xL++ { x := xL * fringeSize firstY := 0 lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) if (xL % 2) != 0 { lastY = lastY - fringeSize/2 firstY = fringeSize / 2 } canvas.Line(x, firstY, x, lastY, style) canvas.Line(x, firstY, x, lastY) } for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := 0 yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x*2, 0, style) canvas.Line(xPrev, yPrev, x*2, 0) } } for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize * 2 style := fmt.Sprintf("stroke:black;stroke-width:2; %s", draw.FillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL*2) * fringeSize if yPrev > 0 { canvas.Line(x, 0, xPrev, yPrev/2, style) canvas.Line(x, 0, xPrev, yPrev/2) } } canvas.Gend() canvas.End() }
draw/spaceinvaders/spaceinvaders.go +11 −3 Original line number Diff line number Diff line Loading @@ -21,13 +21,17 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size quadrantSize := size / squares middle := math.Ceil(float64(squares) / float64(2)) colorMap := make(map[int]color.RGBA) // style of space invader background canvas.Gstyle(draw.FillFromRGBA(colors[0])) for yQ := 0; yQ < squares; yQ++ { y := yQ * quadrantSize colorMap = make(map[int]color.RGBA) for xQ := 0; xQ < squares; xQ++ { x := xQ * quadrantSize fill := draw.FillFromRGBA(colors[0]) fill := "" if _, ok := colorMap[xQ]; !ok { colorMap[xQ] = selectColor(colorMap, key, colors, middle, xQ, yQ, squares) } Loading Loading @@ -65,10 +69,14 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if hasLegOrFoot(invader, lowBodyIndex, xQ, yQ) { fill = draw.FillFromRGBA(colorMap[xQ]) } if len(fill) > 0 { canvas.Rect(x, y, quadrantSize, quadrantSize, fill) } else { canvas.Rect(x, y, quadrantSize, quadrantSize) } } } canvas.Gend() canvas.End() } Loading
draw/spaceinvaders/spaceinvaders_test.go +1554 −1501 File changed.Preview size limit exceeded, changes collapsed. Show changes
draw/squares/gradient.go +5 −9 Original line number Diff line number Diff line Loading @@ -15,8 +15,7 @@ func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) percentage := uint8(100 / len(gColors)) percentage := uint8(0) step := uint8(100 / len(gColors)) for i, c := range gColors { gradientColors[i] = svg.Offcolor{ Loading Loading @@ -44,19 +43,16 @@ func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, colorIndex = make(map[int]int) for xQ := 0; xQ <= squares+1; xQ++ { x := xQ * quadrantSize fill := "" if _, ok := colorMap[xQ]; !ok { colorIndex[xQ] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[xQ] = colors[colorIndex[xQ]] } if colorIndex[xQ] != 0 { fill = "fill:none" } else { fill = draw.FillFromRGBA(colorMap[xQ]) } if colorIndex[xQ] == 0 { fill := draw.FillFromRGBA(colorMap[xQ]) canvas.Rect(x, y, quadrantSize, quadrantSize, fill) } } } canvas.End() }