/
wave.go
147 lines (121 loc) · 2.92 KB
/
wave.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package random
import (
//"fmt"
"github.com/jphsd/texture"
"math/rand"
)
func MakeWave() texture.Wave {
if rand.Intn(2) > 0 {
return MakePatternWave()
}
return MakeNLWave()
}
// MakePatternWave
func MakePatternWave() texture.Wave {
nl := rand.Intn(5) + 1
lambdas := make([]float64, nl)
patterns := make([][]float64, nl)
for i := 0; i < nl; i++ {
lambdas[i] = PickLambda()
patterns[i] = MakePattern(5)
}
return texture.NewPatternWave(lambdas, patterns, rand.Intn(2) > 0, false)
}
func MakePattern(n int) []float64 {
pat := make([]float64, n)
for i := 0; i < n; i++ {
pat[i] = rand.Float64()*2 - 1
}
return pat
}
// MakeNLWave creates a new NLWave
func MakeNLWave() texture.Wave {
nl := rand.Intn(5) + 1
lambdas := make([]float64, nl)
nlfs := make([]*texture.NonLinear, nl)
for i := 0; i < nl; i++ {
lambdas[i] = PickLambda()
nlfs[i] = MakeNL()
}
return texture.NewNLWave(lambdas, nlfs, rand.Intn(2) > 0, false)
}
type NLFunc struct {
Name string
Make func() *texture.NonLinear
}
var NLFOptions = []NLFunc{
{"Linear", MakeNLLinear},
{"Square", MakeNLSquare},
{"Cube", MakeNLCube},
{"Exponential", MakeNLExponential},
{"Logarithmic", MakeNLLogarithmic},
{"Sin", MakeNLSin},
{"Sin1", MakeNLSin1},
{"Sin2", MakeNLSin2},
{"Circle1", MakeNLCircle1},
{"Circle2", MakeNLCircle2},
{"Catenary", MakeNLCatenary},
{"Gauss", MakeNLGauss},
{"Logistic", MakeNLLogistic},
{"NLP3", MakeNLP3},
{"NLP5", MakeNLP5},
{"NLRand", MakeNLRand},
}
func MakeNL() *texture.NonLinear {
res := NLFOptions[rand.Intn(len(NLFOptions))]
return res.Make()
}
func MakeNLLinear() *texture.NonLinear {
return texture.NewNLLinear()
}
func MakeNLSquare() *texture.NonLinear {
return texture.NewNLSquare()
}
func MakeNLCube() *texture.NonLinear {
return texture.NewNLCube()
}
func MakeNLExponential() *texture.NonLinear {
return texture.NewNLExponential(10)
}
func MakeNLLogarithmic() *texture.NonLinear {
return texture.NewNLLogarithmic(10)
}
func MakeNLSin() *texture.NonLinear {
return texture.NewNLSin()
}
func MakeNLSin1() *texture.NonLinear {
return texture.NewNLSin1()
}
func MakeNLSin2() *texture.NonLinear {
return texture.NewNLSin2()
}
func MakeNLCircle1() *texture.NonLinear {
return texture.NewNLCircle1()
}
func MakeNLCircle2() *texture.NonLinear {
return texture.NewNLCircle2()
}
func MakeNLCatenary() *texture.NonLinear {
return texture.NewNLCatenary()
}
func MakeNLGauss() *texture.NonLinear {
return texture.NewNLGauss(1)
}
func MakeNLLogistic() *texture.NonLinear {
return texture.NewNLLogistic(10, 0.5)
}
func MakeNLP3() *texture.NonLinear {
return texture.NewNLP3()
}
func MakeNLP5() *texture.NonLinear {
return texture.NewNLP5()
}
func MakeNLRand() *texture.NonLinear {
return texture.NewNLRand(0.1, 0.05, rand.Intn(2) == 0)
}
var Lambdas = []float64{
11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
}
func PickLambda() float64 {
return Lambdas[rand.Intn(len(Lambdas))]
}