Convex hull: Difference between revisions

675 bytes removed ,  9 years ago
→‎{{header|Go}}: Can't upload the resultant image so just omit the code that makes it.
(→‎{{header|Go}}: Can't upload the resultant image so just omit the code that makes it.)
Line 70:
hull := pts.ConvexHull()
fmt.Println("Convex Hull:", hull)
 
if err := writePNG("hull.png", mkimage(pts, hull)); err != nil {
log.Fatal(err)
}
}
 
func writePNG(filename string, im image.Image) error {
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
return png.Encode(f, im)
}
 
func mkimage(pts, hull points) image.Image {
const margin = 5
r := image.Rect(-margin, -margin, margin, margin)
for _, p := range pts {
r = r.Union(image.Rect(p.X-margin, p.Y-margin, p.X+margin, p.Y+margin))
}
im := image.NewRGBA(r)
c := color.RGBA{0, 0xff, 0, 0xff}
for _, p := range pts {
im.Set(p.X, p.Y, c)
}
c = color.RGBA{0xff, 0, 0, 0xff}
for _, p := range hull {
im.Set(p.X, p.Y, c)
}
return im
}</lang>
{{out}}
Line 106 ⟶ 75:
Convex Hull: [(-9,-3) (-3,-9) (19,-8) (17,5) (12,17) (5,19) (-3,15)]
</pre>
 
=={{header|J}}==
 
Anonymous user