Loading draw/isogrids.go +29 −113 Original line number Diff line number Diff line Loading @@ -2,143 +2,59 @@ package draw import ( "fmt" "github.com/ajstarks/svgo" "image/color" "log" "net/http" "github.com/ajstarks/svgo" ) // IsogridsSVG builds an image with 10x10 grids of alternate colors. func IsogridsSVG(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { func Isogrids1(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) size = 440 size = 400 canvas.Start(size, size) lines := 11 lines := 10 fringeSize := size / lines // middle := math.Ceil(float64(lines) / float64(2)) // colorMap := make(map[int]color.RGBA) // log.Printf(style) // vertical lines for xL := 0; xL < lines; xL++ { // vertical lines OK for xL := 0; xL <= lines; xL++ { x := xL * fringeSize lastY := (lines - 1) * fringeSize lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) if (xL % 2) == 0 { //lastY = int(math.Ceil(float64(lastY) - float64(fringeSize)/float64(2))) lastY = lastY - fringeSize/2 canvas.Line(x, 0, x, lastY, style) } else { // yNext := int(math.Ceil(float64(fringeSize) / float64(2))) yNext := fringeSize / 2 canvas.Line(x, yNext, x, lastY, style) } } // horizontal lines for yL := 0; yL < lines; yL++ { y := yL * fringeSize lastX := (lines - 1) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) canvas.Line(0, y, lastX, y, style) } // diagonal lines, x --> y left down for xL := 0; xL < lines; xL++ { // diagonal lines, x --> y left down OK for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:orange;stroke-width:2; %s", fillFromRGBA(color2)) if (xL % 2) == 0 { style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := 0 yPrev := (xL / 2) * fringeSize log.Println(yPrev) yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) } } } // diagonal lines, x --> y right down for xL := 0; xL < lines; xL++ { for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:fuchsia;stroke-width:2; %s", fillFromRGBA(color2)) if (xL % 2) == 0 { xNext := (lines - 1) * fringeSize yNext := ((lines / 2) - (xL / 2)) * fringeSize if yNext > 0 { canvas.Line(x, 0, xNext, yNext, style) } } 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) } // // diagonal lines, x --> y left up // for xL := 0; xL < lines; xL++ { // x := xL * fringeSize // style := fmt.Sprintf("stroke:red;stroke-width:2; %s", fillFromRGBA(color2)) // if (xL % 2) != 0 { // xLast := x // yLast := (lines - 1) * fringeSize // yPrev := ((lines - 1 - xL) + xL/2) * fringeSize // if yPrev < (lines)*fringeSize { // canvas.Line(xLast, yLast, 0, yPrev, style) // } // } // } // diagonal lines, y --> x down xLast := (lines - 1) * fringeSize for yL := 0; yL < lines; yL++ { style := fmt.Sprintf("stroke:blue;stroke-width:2; %s", fillFromRGBA(color2)) y := yL * fringeSize yDiag := y + (5 * fringeSize) // if yDiag < ((lines - 1) * fringeSize) { canvas.Line(0, y, xLast, yDiag, style) //} } // // diagonal lines, y --> x up // for yL := 0; yL < lines; yL++ { // style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) // y := yL * fringeSize // yDiag := y - (5 * fringeSize) // if yDiag > 0 { // canvas.Line(0, y, xLast, yDiag, style) // } // } // diagonal lines, x --> y left for yL := 0; yL < lines; yL++ { style := fmt.Sprintf("stroke:green;stroke-width:2; %s", fillFromRGBA(color2)) y := yL * fringeSize yDiag := y - (lines / 2 * fringeSize) if yDiag > 0 { canvas.Line(0, y, xLast, yDiag, style) 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) } } // for yL := 0; yL < lines; yL++ { // y := yL * fringeSize // colorMap = make(map[int]color.RGBA) // // <line x1="10" x2="50" y1="110" y2="150" stroke="orange" fill="transparent" stroke-width="5"/> // for xL := 0; xL < lines; xL++ { // x := xL * fringeSize // // lastX := (lines-1)*fringeSize // lastY := (lines - 1) * fringeSize // canvas.Line(x, y, x, lastY) // // if _, ok := colorMap[xQ]; !ok { // // if float64(xQ) < middle { // // colorMap[xQ] = colorFromKey(key, color1, color2, xQ+3*yQ) // // } else if xQ < squares { // // colorMap[xQ] = colorMap[squares-xQ-1] // // } else { // // colorMap[xQ] = colorMap[0] // // } // // } // // canvas.Rect(x, y, quadrantSize, quadrantSize, fillFromRGBA(colorMap[xQ])) // } // } canvas.End() } Loading
draw/isogrids.go +29 −113 Original line number Diff line number Diff line Loading @@ -2,143 +2,59 @@ package draw import ( "fmt" "github.com/ajstarks/svgo" "image/color" "log" "net/http" "github.com/ajstarks/svgo" ) // IsogridsSVG builds an image with 10x10 grids of alternate colors. func IsogridsSVG(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { func Isogrids1(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) size = 440 size = 400 canvas.Start(size, size) lines := 11 lines := 10 fringeSize := size / lines // middle := math.Ceil(float64(lines) / float64(2)) // colorMap := make(map[int]color.RGBA) // log.Printf(style) // vertical lines for xL := 0; xL < lines; xL++ { // vertical lines OK for xL := 0; xL <= lines; xL++ { x := xL * fringeSize lastY := (lines - 1) * fringeSize lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) if (xL % 2) == 0 { //lastY = int(math.Ceil(float64(lastY) - float64(fringeSize)/float64(2))) lastY = lastY - fringeSize/2 canvas.Line(x, 0, x, lastY, style) } else { // yNext := int(math.Ceil(float64(fringeSize) / float64(2))) yNext := fringeSize / 2 canvas.Line(x, yNext, x, lastY, style) } } // horizontal lines for yL := 0; yL < lines; yL++ { y := yL * fringeSize lastX := (lines - 1) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) canvas.Line(0, y, lastX, y, style) } // diagonal lines, x --> y left down for xL := 0; xL < lines; xL++ { // diagonal lines, x --> y left down OK for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:orange;stroke-width:2; %s", fillFromRGBA(color2)) if (xL % 2) == 0 { style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := 0 yPrev := (xL / 2) * fringeSize log.Println(yPrev) yPrev := (xL) * fringeSize if yPrev > 0 { canvas.Line(xPrev, yPrev, x, 0, style) } } } // diagonal lines, x --> y right down for xL := 0; xL < lines; xL++ { for xL := 0; xL <= 2*lines; xL++ { x := xL * fringeSize style := fmt.Sprintf("stroke:fuchsia;stroke-width:2; %s", fillFromRGBA(color2)) if (xL % 2) == 0 { xNext := (lines - 1) * fringeSize yNext := ((lines / 2) - (xL / 2)) * fringeSize if yNext > 0 { canvas.Line(x, 0, xNext, yNext, style) } } 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) } // // diagonal lines, x --> y left up // for xL := 0; xL < lines; xL++ { // x := xL * fringeSize // style := fmt.Sprintf("stroke:red;stroke-width:2; %s", fillFromRGBA(color2)) // if (xL % 2) != 0 { // xLast := x // yLast := (lines - 1) * fringeSize // yPrev := ((lines - 1 - xL) + xL/2) * fringeSize // if yPrev < (lines)*fringeSize { // canvas.Line(xLast, yLast, 0, yPrev, style) // } // } // } // diagonal lines, y --> x down xLast := (lines - 1) * fringeSize for yL := 0; yL < lines; yL++ { style := fmt.Sprintf("stroke:blue;stroke-width:2; %s", fillFromRGBA(color2)) y := yL * fringeSize yDiag := y + (5 * fringeSize) // if yDiag < ((lines - 1) * fringeSize) { canvas.Line(0, y, xLast, yDiag, style) //} } // // diagonal lines, y --> x up // for yL := 0; yL < lines; yL++ { // style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) // y := yL * fringeSize // yDiag := y - (5 * fringeSize) // if yDiag > 0 { // canvas.Line(0, y, xLast, yDiag, style) // } // } // diagonal lines, x --> y left for yL := 0; yL < lines; yL++ { style := fmt.Sprintf("stroke:green;stroke-width:2; %s", fillFromRGBA(color2)) y := yL * fringeSize yDiag := y - (lines / 2 * fringeSize) if yDiag > 0 { canvas.Line(0, y, xLast, yDiag, style) 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) } } // for yL := 0; yL < lines; yL++ { // y := yL * fringeSize // colorMap = make(map[int]color.RGBA) // // <line x1="10" x2="50" y1="110" y2="150" stroke="orange" fill="transparent" stroke-width="5"/> // for xL := 0; xL < lines; xL++ { // x := xL * fringeSize // // lastX := (lines-1)*fringeSize // lastY := (lines - 1) * fringeSize // canvas.Line(x, y, x, lastY) // // if _, ok := colorMap[xQ]; !ok { // // if float64(xQ) < middle { // // colorMap[xQ] = colorFromKey(key, color1, color2, xQ+3*yQ) // // } else if xQ < squares { // // colorMap[xQ] = colorMap[squares-xQ-1] // // } else { // // colorMap[xQ] = colorMap[0] // // } // // } // // canvas.Rect(x, y, quadrantSize, quadrantSize, fillFromRGBA(colorMap[xQ])) // } // } canvas.End() }