Commit ee1d3e51 authored by santiaago's avatar santiaago
Browse files

isogrids/random-mirror now supports numcolors #18

parent 985e5106
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -12,9 +12,13 @@ import (

func RandomMirror(w http.ResponseWriter, r *http.Request) {

	theme := extract.Theme(r)
	colorMap := colors.MapOfColorThemes()
	var err error

	colorMap := colors.MapOfColorThemes()
	size := extract.Size(r)
	theme := extract.Theme(r)
	numColors := extract.NumColors(r)

	var bg, fg color.RGBA
	if bg, err = extract.Background(r); err != nil {
		bg = colorMap["base"][0]
@@ -28,7 +32,16 @@ func RandomMirror(w http.ResponseWriter, r *http.Request) {
		fg = val[1]
	}

	size := extract.Size(r)
	var colors []color.RGBA
	if theme != "base" {
		if _, ok := colorMap[theme]; ok {
			colors = append(colors, colorMap[theme][0:numColors]...)
		} else {
			colors = append(colors, colorMap["base"]...)
		}
	} else {
		colors = append(colors, bg, fg)
	}
	write.ImageSVG(w)
	draw.IsogridsRandomMirror(w, "", bg, fg, size)
	draw.IsogridsRandomMirror(w, "", colors, size)
}
+3 −3
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ func IsogridsRandom(w http.ResponseWriter, key string, colors []color.RGBA, size
}

// Isogrids builds an image with 10x10 grids of half diagonals
func IsogridsRandomMirror(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) {
func IsogridsRandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size int) {
	canvas := svg.New(w)
	canvas.Start(size, size)

@@ -92,7 +92,7 @@ func IsogridsRandomMirror(w http.ResponseWriter, key string, color1, color2 colo
			}
			xs := []int{x1, x2, x3}
			ys := []int{y1, y2, y3}
			fill1 := fillFromRGBA(randomColor(color1, color2))
			fill1 := fillFromRGBA(randomColorFromArray(colors))
			canvas.Polygon(xs, ys, fmt.Sprintf("stroke:black;stroke-width:2; %s", fill1))
			var x11, x12, x13, y11, y12, y13 int
			if (xL % 2) == 0 {
@@ -112,7 +112,7 @@ func IsogridsRandomMirror(w http.ResponseWriter, key string, color1, color2 colo
			}
			xs1 := []int{x11, x12, x13}
			ys1 := []int{y11, y12, y13}
			fill2 := fillFromRGBA(randomColor(color1, color2))
			fill2 := fillFromRGBA(randomColorFromArray(colors))
			canvas.Polygon(xs1, ys1, fmt.Sprintf("stroke:black;stroke-width:2; %s", fill2))
			// apply mirror:
			xs[0] = (lines * fringeSize) - xs[0]