Loading app-backend/main.go +3 −1 Original line number Diff line number Diff line Loading @@ -26,10 +26,12 @@ func main() { r.HandleFunc("/squares/[a-zA-Z0-9\\.]+/?", squares.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9\\.]+/?", squares.Color) // cached r.HandleFunc("/isogrids/grid/[a-zA-Z0-9]+/?", isogrids.Isogrids) r.HandleFunc("/isogrids/skeleton/[a-zA-Z0-9]+/?", isogrids.Skeleton) r.HandleFunc("/isogrids/diagonals/[a-zA-Z0-9]+/?", isogrids.Diagonals) r.HandleFunc("/isogrids/halfdiagonals/[a-zA-Z0-9]+/?", isogrids.HalfDiagonals) r.HandleFunc("/isogrids/color/[a-zA-Z0-9]+/?", isogrids.Color) r.HandleFunc("/isogrids/gridbw/[a-zA-Z0-9]+/?", isogrids.GridBW) r.HandleFunc("/isogrids/grid2colors/[a-zA-Z0-9]+/?", isogrids.Grid2Colors) r.HandleFunc("/isogrids/[a-zA-Z0-9]+/?", isogrids.Isogrids) r.AddStaticResource(root) Loading controllers/isogrids/isogrids.go +26 −2 Original line number Diff line number Diff line Loading @@ -114,7 +114,7 @@ func HalfDiagonals(w http.ResponseWriter, r *http.Request) { } } func Color(w http.ResponseWriter, r *http.Request) { func GridBW(w http.ResponseWriter, r *http.Request) { if id, err := misc.PermalinkString(r, 3); err != nil { log.Printf("error when extracting permalink id: %v", err) Loading @@ -134,6 +134,30 @@ func Color(w http.ResponseWriter, r *http.Request) { } size := extract.Size(r) write.ImageSVG(w) draw.IsogridsColor(w, key, bg, fg, size) draw.IsogridsBW(w, key, bg, fg, size) } } func Grid2Colors(w http.ResponseWriter, r *http.Request) { if id, err := misc.PermalinkString(r, 3); err != nil { log.Printf("error when extracting permalink id: %v", err) } else { h := md5.New() io.WriteString(h, id) key := fmt.Sprintf("%x", h.Sum(nil)[:]) colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { fg = colorMap[0][1] } size := extract.Size(r) write.ImageSVG(w) draw.Isogrids2Colors(w, key, bg, fg, size) } } draw/isogrids.go +118 −2 Original line number Diff line number Diff line Loading @@ -136,7 +136,7 @@ func IsogridsSkeleton(w http.ResponseWriter, key string, color1, color2 color.RG } // Isogrids builds an image with 10x10 grids of half diagonals func IsogridsColor(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { func IsogridsBW(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) size = 400 canvas.Start(size, size) Loading Loading @@ -178,6 +178,122 @@ func IsogridsColor(w http.ResponseWriter, key string, color1, color2 color.RGBA, } } // color here: // triangle grid here: for xL := 0; xL <= lines; xL++ { for yL := 0; yL <= lines; yL++ { var x1, x2, x3, y1, y2, y3 int if (xL % 2) == 0 { x1 = (xL) * fringeSize x2 = (xL + 1) * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } else { x1 = (xL + 1) * fringeSize x2 = xL * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } xs := []int{x1, x2, x3} ys := []int{y1, y2, y3} canvas.Polygon(xs, ys, fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2))) } } canvas.End() } // Isogrids builds an image with 10x10 grids of half diagonals func Isogrids2Colors(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 firstY := 0 lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) if (xL % 2) != 0 { lastY = lastY - fringeSize/2 firstY = fringeSize / 2 } canvas.Line(x, firstY, 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*2, 0, style) } } // x --> y down right for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize * 2 style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL*2) * fringeSize if yPrev > 0 { canvas.Line(x, 0, xPrev, yPrev/2, style) } } // triangle grid here: for xL := 0; xL <= lines; xL++ { for yL := 0; yL <= lines; yL++ { var x1, x2, x3, y1, y2, y3 int if (xL % 2) == 0 { x1 = (xL) * fringeSize x2 = (xL + 1) * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } else { x1 = (xL + 1) * fringeSize x2 = xL * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } xs := []int{x1, x2, x3} ys := []int{y1, y2, y3} canvas.Polygon(xs, ys, fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2))) var x11, x12, x13, y11, y12, y13 int if (xL % 2) == 0 { x11 = (xL + 1) * fringeSize x12 = (xL) * fringeSize x13 = x11 y11 = yL*fringeSize + fringeSize/2 y12 = y11 + fringeSize/2 y13 = (yL+1)*fringeSize + fringeSize/2 } else { x11 = (xL) * fringeSize x12 = (xL + 1) * fringeSize x13 = x11 y11 = yL*fringeSize + fringeSize/2 y12 = y1 + fringeSize y13 = (yL+1)*fringeSize + fringeSize/2 } xs1 := []int{x11, x12, x13} ys1 := []int{y11, y12, y13} canvas.Polygon(xs1, ys1, fmt.Sprintf("stroke:black;stroke-width:2; fill: rgb(31, 71, 176);")) //, fillFromRGBA(color2))) } } canvas.End() } Loading
app-backend/main.go +3 −1 Original line number Diff line number Diff line Loading @@ -26,10 +26,12 @@ func main() { r.HandleFunc("/squares/[a-zA-Z0-9\\.]+/?", squares.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9\\.]+/?", squares.Color) // cached r.HandleFunc("/isogrids/grid/[a-zA-Z0-9]+/?", isogrids.Isogrids) r.HandleFunc("/isogrids/skeleton/[a-zA-Z0-9]+/?", isogrids.Skeleton) r.HandleFunc("/isogrids/diagonals/[a-zA-Z0-9]+/?", isogrids.Diagonals) r.HandleFunc("/isogrids/halfdiagonals/[a-zA-Z0-9]+/?", isogrids.HalfDiagonals) r.HandleFunc("/isogrids/color/[a-zA-Z0-9]+/?", isogrids.Color) r.HandleFunc("/isogrids/gridbw/[a-zA-Z0-9]+/?", isogrids.GridBW) r.HandleFunc("/isogrids/grid2colors/[a-zA-Z0-9]+/?", isogrids.Grid2Colors) r.HandleFunc("/isogrids/[a-zA-Z0-9]+/?", isogrids.Isogrids) r.AddStaticResource(root) Loading
controllers/isogrids/isogrids.go +26 −2 Original line number Diff line number Diff line Loading @@ -114,7 +114,7 @@ func HalfDiagonals(w http.ResponseWriter, r *http.Request) { } } func Color(w http.ResponseWriter, r *http.Request) { func GridBW(w http.ResponseWriter, r *http.Request) { if id, err := misc.PermalinkString(r, 3); err != nil { log.Printf("error when extracting permalink id: %v", err) Loading @@ -134,6 +134,30 @@ func Color(w http.ResponseWriter, r *http.Request) { } size := extract.Size(r) write.ImageSVG(w) draw.IsogridsColor(w, key, bg, fg, size) draw.IsogridsBW(w, key, bg, fg, size) } } func Grid2Colors(w http.ResponseWriter, r *http.Request) { if id, err := misc.PermalinkString(r, 3); err != nil { log.Printf("error when extracting permalink id: %v", err) } else { h := md5.New() io.WriteString(h, id) key := fmt.Sprintf("%x", h.Sum(nil)[:]) colorMap := tgColors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { fg = colorMap[0][1] } size := extract.Size(r) write.ImageSVG(w) draw.Isogrids2Colors(w, key, bg, fg, size) } }
draw/isogrids.go +118 −2 Original line number Diff line number Diff line Loading @@ -136,7 +136,7 @@ func IsogridsSkeleton(w http.ResponseWriter, key string, color1, color2 color.RG } // Isogrids builds an image with 10x10 grids of half diagonals func IsogridsColor(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { func IsogridsBW(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) { canvas := svg.New(w) size = 400 canvas.Start(size, size) Loading Loading @@ -178,6 +178,122 @@ func IsogridsColor(w http.ResponseWriter, key string, color1, color2 color.RGBA, } } // color here: // triangle grid here: for xL := 0; xL <= lines; xL++ { for yL := 0; yL <= lines; yL++ { var x1, x2, x3, y1, y2, y3 int if (xL % 2) == 0 { x1 = (xL) * fringeSize x2 = (xL + 1) * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } else { x1 = (xL + 1) * fringeSize x2 = xL * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } xs := []int{x1, x2, x3} ys := []int{y1, y2, y3} canvas.Polygon(xs, ys, fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2))) } } canvas.End() } // Isogrids builds an image with 10x10 grids of half diagonals func Isogrids2Colors(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 firstY := 0 lastY := (lines) * fringeSize style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) if (xL % 2) != 0 { lastY = lastY - fringeSize/2 firstY = fringeSize / 2 } canvas.Line(x, firstY, 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*2, 0, style) } } // x --> y down right for xL := -2 * lines; xL <= 2*lines; xL++ { x := xL * fringeSize * 2 style := fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2)) xPrev := lines * fringeSize yPrev := (lines - xL*2) * fringeSize if yPrev > 0 { canvas.Line(x, 0, xPrev, yPrev/2, style) } } // triangle grid here: for xL := 0; xL <= lines; xL++ { for yL := 0; yL <= lines; yL++ { var x1, x2, x3, y1, y2, y3 int if (xL % 2) == 0 { x1 = (xL) * fringeSize x2 = (xL + 1) * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } else { x1 = (xL + 1) * fringeSize x2 = xL * fringeSize x3 = x1 y1 = yL * fringeSize y2 = y1 + fringeSize/2 y3 = (yL + 1) * fringeSize } xs := []int{x1, x2, x3} ys := []int{y1, y2, y3} canvas.Polygon(xs, ys, fmt.Sprintf("stroke:black;stroke-width:2; %s", fillFromRGBA(color2))) var x11, x12, x13, y11, y12, y13 int if (xL % 2) == 0 { x11 = (xL + 1) * fringeSize x12 = (xL) * fringeSize x13 = x11 y11 = yL*fringeSize + fringeSize/2 y12 = y11 + fringeSize/2 y13 = (yL+1)*fringeSize + fringeSize/2 } else { x11 = (xL) * fringeSize x12 = (xL + 1) * fringeSize x13 = x11 y11 = yL*fringeSize + fringeSize/2 y12 = y1 + fringeSize y13 = (yL+1)*fringeSize + fringeSize/2 } xs1 := []int{x11, x12, x13} ys1 := []int{y11, y12, y13} canvas.Polygon(xs1, ys1, fmt.Sprintf("stroke:black;stroke-width:2; fill: rgb(31, 71, 176);")) //, fillFromRGBA(color2))) } } canvas.End() }