-
Notifications
You must be signed in to change notification settings - Fork 1
/
binary.go
40 lines (34 loc) · 688 Bytes
/
binary.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
package texture
import "math/rand"
type Binary struct {
Name string
Seed int64
Perc float64
bits [][]bool
}
func NewBinary(width, height int, seed int64, perc float64) *Binary {
lr := rand.New(rand.NewSource(seed))
ba := make([][]bool, height)
for i := 0; i < height; i++ {
ba[i] = make([]bool, width)
for j := 0; j < width; j++ {
ba[i][j] = lr.Float64() < perc
}
}
return &Binary{"Binary", seed, perc, ba}
}
func (b *Binary) Eval2(x, y float64) float64 {
w, h := len(b.bits[0]), len(b.bits)
// Convert x and y into index into bits
ix, iy := int(x)%w, int(y)%h
if ix < 0 {
ix += w
}
if iy < 0 {
iy += h
}
if b.bits[iy][ix] {
return 1
}
return -1
}