Created
July 11, 2013 01:43
-
-
Save kwmt/5971850 to your computer and use it in GitHub Desktop.
Draws a line between the coordinates in the xy list. Pythonの http://effbot.org/imagingbook/imagedraw.htm#tag-ImageDraw.Draw.line のようなことしたい
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/akavel/polyclip-go" | |
"github.com/akavel/polyclip-go/polyutil" | |
"image" | |
"image/color" | |
"image/draw" | |
"image/png" | |
"os" | |
) | |
var list []float64 = []float64{x0, y0, x1, y1,......} | |
func main() { | |
m := image.NewRGBA(image.Rect(0, 0, 500, 500)) | |
draw.Draw(m, m.Bounds(), &image.Uniform{color.RGBA{0, 0, 255, | |
255}}, image.ZP, draw.Src) | |
pts := list2points(list) | |
polyutil.DrawPolyline(pts, brush(m)) | |
w, _ := os.Create("new.png") | |
defer w.Close() | |
png.Encode(w, m) | |
} | |
func brush(im draw.Image) func(x, y int) { | |
return func(x, y int) { | |
im.Set(x, y, color.RGBA{255, 255, 255, 255}) | |
} | |
} | |
func list2points(l []float64) []polyclip.Point { | |
pts := make([]polyclip.Point, 0) | |
for i := 0; i < len(l); i = i + 2 { | |
p := polyclip.Point{l[i], l[i+1]} | |
pts = append(pts, p) | |
} | |
return pts | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment