Commit 6bb18a6f authored by santiaago's avatar santiaago
Browse files

all random color generations now have a prob param

They call ...WithFreq with prob param #71
parent b9fc2a4b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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))
@@ -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 {
@@ -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 {
+6 −6
Original line number Diff line number Diff line
@@ -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)

@@ -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 {
@@ -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()
@@ -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)

@@ -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)
@@ -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)
+2 −2
Original line number Diff line number Diff line
@@ -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))
@@ -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 {
+4 −4
Original line number Diff line number Diff line
@@ -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)
@@ -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])
		}
@@ -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
@@ -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]))
		}