Loading controllers/isogrids/isogrids.go +7 −3 Original line number Diff line number Diff line Loading @@ -3,15 +3,17 @@ package isogrids import ( "crypto/md5" "fmt" tgColors "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" // "github.com/taironas/tinygraphs/format" "github.com/taironas/tinygraphs/misc" "github.com/taironas/tinygraphs/write" "io" "log" "net/http" "github.com/taironas/tinygraphs/misc" "github.com/taironas/tinygraphs/write" // "strings" ) Loading Loading @@ -49,7 +51,9 @@ func Isogrids(w http.ResponseWriter, r *http.Request) { size := extract.Size(r) // if f := extract.Format(r); f == format.SVG { write.ImageSVG(w) draw.IsogridsSVG(w, key, bg, fg, size) // draw.Isogrids1(w, key, bg, fg, size) draw.HalfDiagonals(w, key, bg, fg, size) // } } } draw/isogrids.go +38 −8 Original line number Diff line number Diff line Loading @@ -8,8 +8,8 @@ import ( "github.com/ajstarks/svgo" ) // IsogridsSVG builds an image with 10x10 grids of alternate colors. func Isogrids1(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { // NormalDiagonals builds an image with 10x10 grids of normal diagonals. func NormalDiagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) size = 400 canvas.Start(size, size) Loading @@ -25,7 +25,6 @@ func Isogrids1(w http.ResponseWriter, key string, color1, color2 color.RGBA, siz canvas.Line(x, 0, x, lastY, style) } // diagonal lines, x --> y left down OK for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) Loading @@ -36,23 +35,54 @@ func Isogrids1(w http.ResponseWriter, key string, color1, color2 color.RGBA, siz } } for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) } } canvas.End() } // HalfDiagonals builds an image with 10x10 grids of half diagonals func HalfDiagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) size = 400 canvas.Start(size, size) lines := 10 fringeSize := size / lines // vertical lines for xL := 0; xL <= lines; xL++ { x := xL * fringeSize lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) canvas.Line(x, 0, x, lastY, style) } // y -- > x up right for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := 0 yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) canvas.Line(xPrev, yPrev, x*2, 0, style) } } // x --> y down right for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize x := xL * fringeSize * 2 style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL) * fringeSize yPrev := (lines - xL*2) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) canvas.Line(x, 0, xPrev, yPrev/2, style) } } Loading Loading
controllers/isogrids/isogrids.go +7 −3 Original line number Diff line number Diff line Loading @@ -3,15 +3,17 @@ package isogrids import ( "crypto/md5" "fmt" tgColors "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" // "github.com/taironas/tinygraphs/format" "github.com/taironas/tinygraphs/misc" "github.com/taironas/tinygraphs/write" "io" "log" "net/http" "github.com/taironas/tinygraphs/misc" "github.com/taironas/tinygraphs/write" // "strings" ) Loading Loading @@ -49,7 +51,9 @@ func Isogrids(w http.ResponseWriter, r *http.Request) { size := extract.Size(r) // if f := extract.Format(r); f == format.SVG { write.ImageSVG(w) draw.IsogridsSVG(w, key, bg, fg, size) // draw.Isogrids1(w, key, bg, fg, size) draw.HalfDiagonals(w, key, bg, fg, size) // } } }
draw/isogrids.go +38 −8 Original line number Diff line number Diff line Loading @@ -8,8 +8,8 @@ import ( "github.com/ajstarks/svgo" ) // IsogridsSVG builds an image with 10x10 grids of alternate colors. func Isogrids1(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { // NormalDiagonals builds an image with 10x10 grids of normal diagonals. func NormalDiagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) size = 400 canvas.Start(size, size) Loading @@ -25,7 +25,6 @@ func Isogrids1(w http.ResponseWriter, key string, color1, color2 color.RGBA, siz canvas.Line(x, 0, x, lastY, style) } // diagonal lines, x --> y left down OK for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) Loading @@ -36,23 +35,54 @@ func Isogrids1(w http.ResponseWriter, key string, color1, color2 color.RGBA, siz } } for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) } } canvas.End() } // HalfDiagonals builds an image with 10x10 grids of half diagonals func HalfDiagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) size = 400 canvas.Start(size, size) lines := 10 fringeSize := size / lines // vertical lines for xL := 0; xL <= lines; xL++ { x := xL * fringeSize lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) canvas.Line(x, 0, x, lastY, style) } // y -- > x up right for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := 0 yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) canvas.Line(xPrev, yPrev, x*2, 0, style) } } // x --> y down right for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize x := xL * fringeSize * 2 style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL) * fringeSize yPrev := (lines - xL*2) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) canvas.Line(x, 0, xPrev, yPrev/2, style) } } Loading