Commit 9902317a authored by santiaago's avatar santiaago
Browse files

random routes extract a probability and use it

Fixes #71
parent 6bb18a6f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -35,10 +35,11 @@ func BannerRandom(w http.ResponseWriter, r *http.Request) {
	} else {
		colors = append(colors, bg, fg)
	}
	prob := extract.Probability(r, 1/float64(len(colors)))

	xt := extract.XTriangles(r)
	write.ImageSVG(w)
	isogrids.Random(w, "", colors, width, height, xt)
	isogrids.Random(w, "", colors, width, height, xt, prob)
}

// BannerRandomGradinet handler for /isogrids/banner/random/gradient.
+2 −1
Original line number Diff line number Diff line
@@ -38,7 +38,8 @@ func BannerGradient(w http.ResponseWriter, r *http.Request) {
		colors = append(colors, bg, fg)
		gColors = []color.RGBA{bg, fg}
	}
	prob := extract.Probability(r, 1/float64(len(colors)))

	write.ImageSVG(w)
	isogrids.RandomGradientColor(w, colors, gColors, gv, width, height, xtriangles)
	isogrids.RandomGradientColor(w, colors, gColors, gv, width, height, xtriangles, prob)
}
+2 −1
Original line number Diff line number Diff line
@@ -33,9 +33,10 @@ func Random(w http.ResponseWriter, r *http.Request) {
	} else {
		colors = append(colors, bg, fg)
	}
	prob := extract.Probability(r, 1/float64(len(colors)))

	size := extract.Size(r)
	lines := extract.Lines(r)
	write.ImageSVG(w)
	isogrids.Random(w, "", colors, size, size, lines)
	isogrids.Random(w, "", colors, size, size, lines, prob)
}
+2 −1
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ func RandomMirror(w http.ResponseWriter, r *http.Request) {
	} else {
		colors = append(colors, bg, fg)
	}
	prob := extract.Probability(r, 1/float64(len(colors)))

	write.ImageSVG(w)
	isogrids.RandomMirror(w, "", colors, size)
	isogrids.RandomMirror(w, "", colors, size, prob)
}
+3 −3
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ func BannerRandom(w http.ResponseWriter, r *http.Request) {
	width := extract.Width(r)
	height := extract.Height(r)
	xsquares := extract.XSquares(r)

	numColors := extract.NumColors(r)

	colorMap := colors.MapOfColorThemes()
@@ -36,15 +35,16 @@ func BannerRandom(w http.ResponseWriter, r *http.Request) {
	} else {
		colors = append(colors, bg, fg)
	}
	prob := extract.Probability(r, 1/float64(len(colors)))

	if f := extract.Format(r); f == format.JPEG {
		m := image.NewRGBA(image.Rect(0, 0, width, height))
		squares.RandomGrid(m, colors, xsquares)
		squares.RandomGrid(m, colors, xsquares, prob)
		var img image.Image = m
		write.ImageJPEG(w, &img)
	} else if f == format.SVG {
		write.ImageSVG(w)
		squares.RandomGridSVG(w, colors, width, height, xsquares)
		squares.RandomGridSVG(w, colors, width, height, xsquares, prob)
	}
}

Loading