代码拉取完成,页面将自动刷新
package supply_point
import (
"image"
"image/color"
"image/draw"
"image/png"
"os"
)
type Putpixel func(x, y int)
// 求绝对值
func abs(x int) int {
if x >= 0 {
return x
}
return -x
}
func drawLine(x0, y0, x1, y1 int, brush Putpixel) {
dx := abs(x1 - x0)
dy := abs(y1 - y0)
sx, sy := 1, 1
if x0 >= x1 {
sx = -1
}
if y0 >= y1 {
sy = -1
}
err := dx - dy
for {
brush(x0, y0)
if x0 == x1 && y0 == y1 {
break
}
e2 := 2 * err
if e2 > -dy {
err -= dy
x0 += sx
}
if e2 < dx {
err += dx
y0 += sy
}
}
}
func drawPathPoint(pp []*PathPoint, corners []*PathPoint, name string) {
m := image.NewRGBA(image.Rect(0, 0, 1000, 2000))
for i := 1; i < len(pp); i++ {
drawLine(pp[i-1].X, pp[i-1].Y, pp[i].X, pp[i].Y, func(x, y int) {
m.Set(x, y, color.RGBA{R: 255, A: 255})
})
drawPoint(m, pp[i-1].X, pp[i-1].Y, color.RGBA{G: 255, A: 255})
}
for i := 0; i < len(corners); i++ {
//fmt.Println(cornersint[i-1][0], cornersint[i-1][1])
drawPoint(m, corners[i].X, corners[i].Y, color.White)
}
//point := image.Point{
// X: ljint[0][0],
// Y: ljint[0][1],
//}
drawPoint(m, pp[0].X, pp[0].Y, color.RGBA{B: 255, A: 255})
f, _ := os.Create("res/" + name)
png.Encode(f, m)
f.Close()
}
func drawPathPointXy(pp []*PathPoint, corners []int, name string) {
m := image.NewRGBA(image.Rect(0, 0, 1000, 2000))
for i := 1; i < len(pp); i++ {
drawLine(pp[i-1].X, pp[i-1].Y, pp[i].X, pp[i].Y, func(x, y int) {
m.Set(x, y, color.RGBA{R: 255, A: 255})
})
drawPoint(m, pp[i-1].X, pp[i-1].Y, color.RGBA{G: 255, A: 255})
}
for i := 0; i < len(corners); i++ {
//fmt.Println(cornersint[i-1][0], cornersint[i-1][1])
drawPoint(m, pp[corners[i]].X, pp[corners[i]].Y, color.White)
}
//point := image.Point{
// X: ljint[0][0],
// Y: ljint[0][1],
//}
drawPoint(m, pp[0].X, pp[0].Y, color.RGBA{B: 255, A: 255})
f, _ := os.Create("res/" + name)
png.Encode(f, m)
f.Close()
}
func drawPoint(dst draw.Image, x, y int, c color.Color) {
r := image.Rectangle{
Min: image.Point{
X: x,
Y: y,
},
Max: image.Point{
X: x + 10,
Y: y + 10,
},
}
draw.Draw(dst, r, &image.Uniform{c}, image.ZP, draw.Src)
}
func drawSupplyPoint(pp []*PathPoint, corners [][]int) {
m := image.NewRGBA(image.Rect(0, 0, 1000, 2000))
for i := 1; i < len(pp); i++ {
drawLine(pp[i-1].X, pp[i-1].Y, pp[i].X, pp[i].Y, func(x, y int) {
m.Set(x, y, color.RGBA{R: 255, A: 255})
})
drawPoint(m, pp[i-1].X, pp[i-1].Y, color.RGBA{G: 255, A: 255})
}
for i := 0; i < len(corners); i++ {
for j := 0; j < len(corners[i]); j++ {
drawPoint(m, pp[corners[i][j]].X, pp[corners[i][j]].Y, color.White)
}
}
drawPoint(m, pp[0].X, pp[0].Y, color.RGBA{B: 255, A: 255})
f, _ := os.Create("test.png")
png.Encode(f, m)
f.Close()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。