/
draw.go
44 lines (37 loc) · 971 Bytes
/
draw.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
// Drawing the simulation
package main
import (
"image"
"image/color"
"math"
)
func GenGridImage(s *Sim) image.Image {
width, height := s.humanGrid.width, s.humanGrid.height
img := image.NewRGBA(image.Rect(0, 0, width, height))
maxPop := s.humanGrid.biggestPopCell.population
for i, cell := range s.humanGrid.area {
var landValue byte = 0
if s.mapGrid.area[i].isLand {
landValue = 255
}
pop := cell.population
popRange := float64(pop) / float64(maxPop)
if cell.population != 0 { //To see places where there is ANY population
popRange += 0.1
}
red := byte(0xff * (math.Min(1.0, popRange)))
col := color.RGBA{
R: red,
G: landValue - red,
B: 100 - landValue,
A: 0xff,
}
//Fancy coordinates from index of 1d slice, probably slow though
img.Set(i%width, i/width, col)
}
return img
}
//lint:ignore U1000 might be useful for snapshots later
func (a *Anaxim) updateMapImage() {
a.mapImage = GenGridImage(a.simulation)
}