-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (56 loc) · 1.43 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"image"
"image/color"
"image/png"
"math/rand"
"os"
)
func main() {
// Generate a grass image and save it to a PNG file
grassImg := generateGrass()
grassFile, _ := os.Create("grass.png")
defer grassFile.Close()
png.Encode(grassFile, grassImg)
// Generate a dirt image and save it to a PNG file
dirtImg := generateDirt()
dirtFile, _ := os.Create("dirt.png")
defer dirtFile.Close()
png.Encode(dirtFile, dirtImg)
}
func generateGrass() *image.RGBA {
width, height := 32, 32
img := image.NewRGBA(image.Rect(0, 0, width, height))
// Fill the image with a random shade of green
green := color.RGBA{0, uint8(rand.Intn(200)), 0, 255}
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
img.Set(x, y, green)
}
}
// Randomly generate grass blades
for i := 0; i < 50; i++ {
x := rand.Intn(width)
y := rand.Intn(height-5) + 5
length := rand.Intn(4) + 1
for j := 0; j < length; j++ {
img.Set(x, y-j, color.RGBA{0, 255, 0, 255})
}
}
return img
}
func generateDirt() *image.RGBA {
width, height := 32, 32
img := image.NewRGBA(image.Rect(0, 0, width, height))
// Fill the image with a random shade of brown
brown := color.RGBA{139, 69, 19, 255}
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
r := uint8(rand.Intn(40)) + brown.R
g := uint8(rand.Intn(20)) + brown.G
b := uint8(rand.Intn(20)) + brown.B
img.Set(x, y, color.RGBA{r, g, b, 255})
}
}
return img
}