This commit is contained in:
Dawid Wysokiński 2020-12-30 16:51:44 +01:00
parent 6cc9aafa59
commit e4f2a95161
5 changed files with 13 additions and 33 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 586 KiB

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -11,8 +11,8 @@ import (
)
func main() {
villages := generateVillages(10)
villages2 := generateVillages(0.01)
villages := generateVillages(1)
villages2 := generateVillages(1)
t1 := time.Now()
f, _ := os.Create("image.jpeg")
defer f.Close()
@ -22,14 +22,16 @@ func main() {
Scale: 1,
ContinentGrid: true,
ContinentNumbers: true,
Quality: 100,
BackgroundColor: "#000",
Markers: []*generator.Marker{
&generator.Marker{
{
Color: "#f00",
Villages: villages,
Larger: false,
},
&generator.Marker{
Color: "#fff",
{
Color: "#0f0",
Villages: villages2,
Larger: true,
},

View File

@ -18,7 +18,7 @@ const (
defaultGridLineColor = "#fff"
defaultContinentNumberColor = "#fff"
defaultMapSize = 1000
defaultQuality = 80
defaultQuality = 100
)
type Marker struct {
@ -93,39 +93,22 @@ func Generate(cfg Config) error {
return errors.Wrap(err, "map-generator")
}
// Background.
for y := 0; y < cfg.MapSize; y++ {
for x := 0; x < cfg.MapSize; x++ {
img.Set(x, y, backgroundColor)
}
}
draw.Draw(img, img.Bounds(), &image.Uniform{backgroundColor}, image.Point{}, draw.Src)
}
// Markers
for _, marker := range cfg.Markers {
m := marker
parsedColor, err := parseHexColorFast(m.Color)
if err != nil {
return err
return errors.Wrap(err, "map-generator")
}
for _, village := range m.Villages {
limit := 1
if m.Larger {
limit = 4
limit = 3
}
for y := 1; y <= limit; y++ {
for x := 1; x <= limit; x++ {
img.Set(village.X+x, village.Y, parsedColor)
img.Set(village.X-x, village.Y, parsedColor)
img.Set(village.X, village.Y+y, parsedColor)
img.Set(village.X, village.Y-y, parsedColor)
img.Set(village.X+x, village.Y-y, parsedColor)
img.Set(village.X-x, village.Y-y, parsedColor)
img.Set(village.X+x, village.Y+y, parsedColor)
img.Set(village.X-x, village.Y+y, parsedColor)
}
}
img.Set(village.X, village.Y, parsedColor)
rect := image.Rect(village.X-limit, village.Y-limit, village.X+limit, village.Y+limit)
draw.Draw(img, rect, &image.Uniform{parsedColor}, image.Point{}, draw.Src)
}
}

1
go.mod
View File

@ -7,5 +7,4 @@ require (
github.com/pkg/errors v0.9.1
github.com/tribalwarshelp/shared v0.0.0-20201225112152-d1d8bc92fc33
golang.org/x/image v0.0.0-20200618115811-c13761719519
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
)

4
go.sum
View File

@ -12,15 +12,11 @@ github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tribalwarshelp/shared v0.0.0-20200622084436-3a768c8bf574 h1:y2EoH6zRK9Uc0AeswnJRYUUIQYcSLZB5VDFuxPCKxNM=
github.com/tribalwarshelp/shared v0.0.0-20200622084436-3a768c8bf574/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/tribalwarshelp/shared v0.0.0-20201225112152-d1d8bc92fc33 h1:ItFd9kzpvO69r3Ta7S8+3OT6Wc56Ga5MEGBYW7DotUE=
github.com/tribalwarshelp/shared v0.0.0-20201225112152-d1d8bc92fc33/go.mod h1:Lxk6zaQhPTPrgz9ksMgg51m8XgflrCo/kRBx2cM3yfk=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200618115811-c13761719519 h1:1e2ufUJNM3lCHEY5jIgac/7UTjd6cgJNdatjPdFWf34=
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=