Loading draw/isogrids/gradient.go +3 −3 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ import ( // RandomGradientColor builds a isogrid image with with x colors selected at random for each quadrant. // the background color stays the same the other colors get mixed in a gradient color from the first one to the last one. func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, lines int) { func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, lines int, prob float64) { var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) Loading Loading @@ -52,7 +52,7 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv xs := []int{x2, x1, x2} ys := []int{y1, y2, y3} colorIndex[yL] = draw.RandomIndexFromArray(colors) colorIndex[yL] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { Loading @@ -78,7 +78,7 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv xs1 := []int{x12, x11, x12} ys1 := []int{y11, y12, y13} colorIndex[yL] = draw.RandomIndexFromArray(colors) colorIndex[yL] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { Loading draw/isogrids/random.go +6 −6 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ import ( "github.com/taironas/tinygraphs/draw" ) func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, height, lines int) { func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, height, lines int, prob float64) { canvas := svg.New(w) canvas.Start(width, height) Loading @@ -27,7 +27,7 @@ func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, heigh } xs := []int{x2, x1, x2} ys := []int{y1, y2, y3} canvas.Polygon(xs, ys, draw.FillFromRGBA(draw.RandomColorFromArray(colors))) canvas.Polygon(xs, ys, draw.FillFromRGBA(draw.RandomColorFromArrayWithFreq(colors, prob))) var x11, x12, y11, y12, y13 int if (xL % 2) == 0 { Loading @@ -43,7 +43,7 @@ func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, heigh } xs1 := []int{x12, x11, x12} ys1 := []int{y11, y12, y13} canvas.Polygon(xs1, ys1, draw.FillFromRGBA(draw.RandomColorFromArray(colors))) canvas.Polygon(xs1, ys1, draw.FillFromRGBA(draw.RandomColorFromArrayWithFreq(colors, prob))) } } canvas.End() Loading Loading @@ -94,7 +94,7 @@ func RandomGradient(w http.ResponseWriter, key string, colors []color.RGBA, widt } // RandomMirror builds an image with 10x10 grids of half diagonals func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size int) { func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size int, prob float64) { canvas := svg.New(w) canvas.Start(size, size) Loading @@ -115,7 +115,7 @@ func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size i xs := []int{x2, x1, x2} ys := []int{y1, y2, y3} fill1 := draw.FillFromRGBA(draw.RandomColorFromArray(colors)) fill1 := draw.FillFromRGBA(draw.RandomColorFromArrayWithFreq(colors, prob)) canvas.Polygon(xs, ys, fill1) xs = mirrorCoordinates(xs, lines, fringeSize, 0) Loading @@ -137,7 +137,7 @@ func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size i xs1 := []int{x12, x11, x12} ys1 := []int{y11, y12, y13} fill2 := draw.FillFromRGBA(draw.RandomColorFromArray(colors)) fill2 := draw.FillFromRGBA(draw.RandomColorFromArrayWithFreq(colors, prob)) canvas.Polygon(xs1, ys1, fill2) xs1 = mirrorCoordinates(xs1, lines, fringeSize, 0) Loading draw/squares/gradient.go +2 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ import ( // RandomGradientColorSVG builds a square image with with x colors selected at random for each quadrant. // the background color stays the same the other colors get mixed in a gradient color from the first one to the last one. func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, xsquares int) { func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, xsquares int, prob float64) { var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) Loading Loading @@ -42,7 +42,7 @@ func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, x := xQ * quadrantSize fill := "" if _, ok := colorMap[xQ]; !ok { colorIndex[xQ] = draw.RandomIndexFromArray(colors) colorIndex[xQ] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[xQ] = colors[colorIndex[xQ]] } if colorIndex[xQ] != 0 { Loading draw/squares/random.go +4 −4 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ import ( ) // RandomGrid builds a grid image with with x colors selected at random for each quadrant. func RandomGrid(m *image.RGBA, colors []color.RGBA, xSquares int) { func RandomGrid(m *image.RGBA, colors []color.RGBA, xSquares int, prob float64) { size := m.Bounds().Size() quad := size.X / xSquares colorMap := make(map[int]color.RGBA) Loading @@ -24,7 +24,7 @@ func RandomGrid(m *image.RGBA, colors []color.RGBA, xSquares int) { for y := 0; y < size.Y; y++ { yQuadrant := y / quad if _, ok := colorMap[yQuadrant]; !ok { colorMap[yQuadrant] = draw.RandomColorFromArray(colors) colorMap[yQuadrant] = draw.RandomColorFromArrayWithFreq(colors, prob) } m.Set(x, y, colorMap[yQuadrant]) } Loading @@ -32,7 +32,7 @@ func RandomGrid(m *image.RGBA, colors []color.RGBA, xSquares int) { } // RandomGridSVG builds a grid image with with x colors selected at random for each quadrant. func RandomGridSVG(w http.ResponseWriter, colors []color.RGBA, width, height, xSquares int) { func RandomGridSVG(w http.ResponseWriter, colors []color.RGBA, width, height, xSquares int, prob float64) { canvas := svg.New(w) canvas.Start(width, height) squares := xSquares Loading @@ -45,7 +45,7 @@ func RandomGridSVG(w http.ResponseWriter, colors []color.RGBA, width, height, xS for xQ := 0; xQ < squares; xQ++ { x := xQ * quadrantSize if _, ok := colorMap[xQ]; !ok { colorMap[xQ] = draw.RandomColorFromArray(colors) colorMap[xQ] = draw.RandomColorFromArrayWithFreq(colors, prob) } canvas.Rect(x, y, quadrantSize, quadrantSize, draw.FillFromRGBA(colorMap[xQ])) } Loading Loading
draw/isogrids/gradient.go +3 −3 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ import ( // RandomGradientColor builds a isogrid image with with x colors selected at random for each quadrant. // the background color stays the same the other colors get mixed in a gradient color from the first one to the last one. func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, lines int) { func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, lines int, prob float64) { var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) Loading Loading @@ -52,7 +52,7 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv xs := []int{x2, x1, x2} ys := []int{y1, y2, y3} colorIndex[yL] = draw.RandomIndexFromArray(colors) colorIndex[yL] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { Loading @@ -78,7 +78,7 @@ func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv xs1 := []int{x12, x11, x12} ys1 := []int{y11, y12, y13} colorIndex[yL] = draw.RandomIndexFromArray(colors) colorIndex[yL] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[yL] = colors[colorIndex[yL]] if colorIndex[yL] != 0 { Loading
draw/isogrids/random.go +6 −6 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ import ( "github.com/taironas/tinygraphs/draw" ) func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, height, lines int) { func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, height, lines int, prob float64) { canvas := svg.New(w) canvas.Start(width, height) Loading @@ -27,7 +27,7 @@ func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, heigh } xs := []int{x2, x1, x2} ys := []int{y1, y2, y3} canvas.Polygon(xs, ys, draw.FillFromRGBA(draw.RandomColorFromArray(colors))) canvas.Polygon(xs, ys, draw.FillFromRGBA(draw.RandomColorFromArrayWithFreq(colors, prob))) var x11, x12, y11, y12, y13 int if (xL % 2) == 0 { Loading @@ -43,7 +43,7 @@ func Random(w http.ResponseWriter, key string, colors []color.RGBA, width, heigh } xs1 := []int{x12, x11, x12} ys1 := []int{y11, y12, y13} canvas.Polygon(xs1, ys1, draw.FillFromRGBA(draw.RandomColorFromArray(colors))) canvas.Polygon(xs1, ys1, draw.FillFromRGBA(draw.RandomColorFromArrayWithFreq(colors, prob))) } } canvas.End() Loading Loading @@ -94,7 +94,7 @@ func RandomGradient(w http.ResponseWriter, key string, colors []color.RGBA, widt } // RandomMirror builds an image with 10x10 grids of half diagonals func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size int) { func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size int, prob float64) { canvas := svg.New(w) canvas.Start(size, size) Loading @@ -115,7 +115,7 @@ func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size i xs := []int{x2, x1, x2} ys := []int{y1, y2, y3} fill1 := draw.FillFromRGBA(draw.RandomColorFromArray(colors)) fill1 := draw.FillFromRGBA(draw.RandomColorFromArrayWithFreq(colors, prob)) canvas.Polygon(xs, ys, fill1) xs = mirrorCoordinates(xs, lines, fringeSize, 0) Loading @@ -137,7 +137,7 @@ func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size i xs1 := []int{x12, x11, x12} ys1 := []int{y11, y12, y13} fill2 := draw.FillFromRGBA(draw.RandomColorFromArray(colors)) fill2 := draw.FillFromRGBA(draw.RandomColorFromArrayWithFreq(colors, prob)) canvas.Polygon(xs1, ys1, fill2) xs1 = mirrorCoordinates(xs1, lines, fringeSize, 0) Loading
draw/squares/gradient.go +2 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ import ( // RandomGradientColorSVG builds a square image with with x colors selected at random for each quadrant. // the background color stays the same the other colors get mixed in a gradient color from the first one to the last one. func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, xsquares int) { func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, xsquares int, prob float64) { var gradientColors []svg.Offcolor gradientColors = make([]svg.Offcolor, len(gColors)) Loading Loading @@ -42,7 +42,7 @@ func RandomGradientColorSVG(w http.ResponseWriter, colors, gColors []color.RGBA, x := xQ * quadrantSize fill := "" if _, ok := colorMap[xQ]; !ok { colorIndex[xQ] = draw.RandomIndexFromArray(colors) colorIndex[xQ] = draw.RandomIndexFromArrayWithFreq(colors, prob) colorMap[xQ] = colors[colorIndex[xQ]] } if colorIndex[xQ] != 0 { Loading
draw/squares/random.go +4 −4 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ import ( ) // RandomGrid builds a grid image with with x colors selected at random for each quadrant. func RandomGrid(m *image.RGBA, colors []color.RGBA, xSquares int) { func RandomGrid(m *image.RGBA, colors []color.RGBA, xSquares int, prob float64) { size := m.Bounds().Size() quad := size.X / xSquares colorMap := make(map[int]color.RGBA) Loading @@ -24,7 +24,7 @@ func RandomGrid(m *image.RGBA, colors []color.RGBA, xSquares int) { for y := 0; y < size.Y; y++ { yQuadrant := y / quad if _, ok := colorMap[yQuadrant]; !ok { colorMap[yQuadrant] = draw.RandomColorFromArray(colors) colorMap[yQuadrant] = draw.RandomColorFromArrayWithFreq(colors, prob) } m.Set(x, y, colorMap[yQuadrant]) } Loading @@ -32,7 +32,7 @@ func RandomGrid(m *image.RGBA, colors []color.RGBA, xSquares int) { } // RandomGridSVG builds a grid image with with x colors selected at random for each quadrant. func RandomGridSVG(w http.ResponseWriter, colors []color.RGBA, width, height, xSquares int) { func RandomGridSVG(w http.ResponseWriter, colors []color.RGBA, width, height, xSquares int, prob float64) { canvas := svg.New(w) canvas.Start(width, height) squares := xSquares Loading @@ -45,7 +45,7 @@ func RandomGridSVG(w http.ResponseWriter, colors []color.RGBA, width, height, xS for xQ := 0; xQ < squares; xQ++ { x := xQ * quadrantSize if _, ok := colorMap[xQ]; !ok { colorMap[xQ] = draw.RandomColorFromArray(colors) colorMap[xQ] = draw.RandomColorFromArrayWithFreq(colors, prob) } canvas.Rect(x, y, quadrantSize, quadrantSize, draw.FillFromRGBA(colorMap[xQ])) } Loading