I currently want to set pixel images on a loop
func ParseMap(path string) {
...
for _, h := range serverMap.Houses {
houseData := Houses.GetHouse(h.ID)
houseImage := image.NewRGBA(image.Rect(int(houseData.EntryX)-32, int(houseData.EntryY)-32, int(houseData.EntryX)+32, int(houseData.EntryY)+32))
draw.Draw(houseImage, houseImage.Bounds(), &image.Uniform{
backgroundColor,
}, image.ZP, draw.Src)
for _, tile := range h.Tiles {
pos := tile.Position()
if pos.Z != uint8(houseData.EntryZ) {
continue
}
drawSquare(houseImage, tileColor, 12, int(pos.X), int(pos.Y))
imgFile, _ := os.Create(fmt.Sprintf("%v/%v/%v.png", pigo.Config.String("template"), "public/houses", houseData.Name))
png.Encode(imgFile, houseImage)
imgFile.Close()
}
...
}
I loop on a slice of Tiles that contains X, Y, Z fields but since 1 pixel looks very small I want to be each pixel 6 pixel square with the given function
func drawSquare(img *image.RGBA, c color.Color, size int, x, y int) {
patch := image.NewRGBA(image.Rect(0, 0, size, size))
draw.Draw(patch, patch.Bounds(), &image.Uniform{
c,
}, image.ZP, draw.Src)
draw.Draw(img, image.Rect(x, y, x+size, y+size), patch, image.ZP, draw.Src)
}
However there is a problem with this function. If I want to paint one pixel this is how it will look
The red borders means how big the square will be BUT if I go to the next pixel the size will be overwritten
Instead of beeing what I am looking for
I hope it is clear enough what I want to achieve but I dont really know what type of algorithm I should use (if I even need one) or its just pure logic