-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.go
39 lines (34 loc) · 908 Bytes
/
rules.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
package gol
// Colour values
type Colour struct {
R, G, B float32
}
// Rule with alive status and transitions which
// represent what the rule changes to based on
// amount of adjacent alive cells (0-8)
type Rule struct {
Alive bool
Transitions [9]uint8
Colour Colour
}
// Randomize a single Rule
func (ru *Rule) Randomize(RuleAmount int) {
ru.Alive = randInt(2) == 0
ru.Colour.R = float32(float32(randInt(255)) / 255.0)
ru.Colour.G = float32(float32(randInt(255)) / 255.0)
ru.Colour.B = float32(float32(randInt(255)) / 255.0)
for idx := range ru.Transitions {
ru.Transitions[idx] = uint8(randInt(RuleAmount))
}
}
// Rules is an ordered array of Rule structs
type Rules struct {
Array []Rule
}
// Randomize an array of Rules
func (rs *Rules) Randomize(RuleAmount int) {
rs.Array = make([]Rule, RuleAmount)
for idx := range rs.Array {
rs.Array[idx].Randomize(RuleAmount)
}
}