Commit 63108621 authored by santiaago's avatar santiaago
Browse files

isogrids now have a default value of 6 lines

This can be specified using lines parameter in an isogrid image.
Fixes #37' -a
parent f531a9b3
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -81,6 +81,13 @@ You can set the HTML source of the image to point directly to **tinygraphs.com**

    ![theme](http://tinygraphs.com/squares/random?theme=frogideas&size=120&fmt=svg&numcolors=4)

* **lines**
You can specify the number of lines that an isogrid can have using the `lines`parameter. **Default** parameter is **6**

`tinygraphs.com/isogrids/hello?lines=4`

![number of lines in isogrid image.](http://tinygraphs.com/isogrids/hello?lines=4&size=120&fmt=svg)

Organization
=====

+5 −4
Original line number Diff line number Diff line
@@ -30,10 +30,7 @@ func Isogrids(w http.ResponseWriter, r *http.Request) {
	key = fmt.Sprintf("%x", h.Sum(nil)[:])

	colorMap := colors.MapOfColorThemes()
	size := extract.Size(r)
	numColors := extract.NumColors(r)
	bg, fg := extract.ExtraColors(r, colorMap)

	theme := extract.Theme(r)
	if val, ok := colorMap[theme]; ok {
		bg = val[0]
@@ -43,6 +40,7 @@ func Isogrids(w http.ResponseWriter, r *http.Request) {
	var colors []color.RGBA
	if theme != "base" {
		if _, ok := colorMap[theme]; ok {
			numColors := extract.NumColors(r)
			colors = append(colors, colorMap[theme][0:numColors]...)
		} else {
			colors = append(colors, colorMap["base"]...)
@@ -51,6 +49,9 @@ func Isogrids(w http.ResponseWriter, r *http.Request) {
		colors = append(colors, bg, fg)
	}

	size := extract.Size(r)
	lines := extract.Lines(r)

	write.ImageSVG(w)
	isogrids.Isogrids(w, key, colors, size)
	isogrids.Isogrids(w, key, colors, size, lines)
}
+1 −2
Original line number Diff line number Diff line
@@ -130,11 +130,10 @@ func RandomMirror(w http.ResponseWriter, key string, colors []color.RGBA, size i
}

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

	lines := 10
	fringeSize := size / lines

	// triangle grid here:
+14 −0
Original line number Diff line number Diff line
@@ -130,3 +130,17 @@ func Hexalines(r *http.Request) int64 {
	}
	return 6
}

// Lines return the value of the lines parameter in the http.Request.
// Default value is 6
func Lines(r *http.Request) int {
	s := strings.ToLower(r.FormValue("lines"))
	if len(s) > 0 {
		if n, err := strconv.ParseInt(s, 0, 64); err == nil {
			if n > 0 {
				return int(n)
			}
		}
	}
	return 6
}