-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamples_test.go
441 lines (334 loc) · 12.9 KB
/
examples_test.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
package texture_test
import (
"fmt"
"github.com/jphsd/graphics2d"
"github.com/jphsd/graphics2d/image"
"github.com/jphsd/texture"
"math"
)
func ExampleLinearGradient_saw() {
nl := texture.NewNLLinear()
w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, false, false)
f := texture.NewLinearGradient(w)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleLinearGradient_saw")
fmt.Printf("Generated ExampleLinearGradient_saw")
// Output: Generated ExampleLinearGradient_saw
}
func ExampleLinearGradient_triangle() {
nl := texture.NewNLLinear()
w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
f := texture.NewLinearGradient(w)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleLinearGradient_triangle")
fmt.Printf("Generated ExampleLinearGradient_triangle")
// Output: Generated ExampleLinearGradient_triangle
}
func ExampleLinearGradient_sine() {
nl := texture.NewNLSin()
w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
f := texture.NewLinearGradient(w)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleLinearGradient_sine")
fmt.Printf("Generated ExampleLinearGradient_sine")
// Output: Generated ExampleLinearGradient_sine
}
func ExampleMulCombiner() {
nl := texture.NewNLSin()
w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
f := texture.NewLinearGradient(w)
xfm := graphics2d.Rotate(graphics2d.HalfPi)
f2 := texture.NewTransform(f, xfm)
f3 := texture.NewMulCombiner(f, f2)
img := texture.NewTextureGray16(600, 600, f3, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleMulCombiner")
fmt.Printf("Generated ExampleMulCombiner")
// Output: Generated ExampleMulCombiner
}
func ExampleMaxCombiner() {
nl := texture.NewNLSin()
w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
f := texture.NewLinearGradient(w)
xfm := graphics2d.Rotate(graphics2d.HalfPi)
f2 := texture.NewTransform(f, xfm)
f3 := texture.NewMaxCombiner(f, f2)
img := texture.NewTextureGray16(600, 600, f3, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleMaxCombiner")
fmt.Printf("Generated ExampleMaxCombiner")
// Output: Generated ExampleMaxCombiner
}
func ExampleLinearGradient_circular() {
nl1 := texture.NewNLCircle1()
nl2 := texture.NewNLCircle2()
w := texture.NewDCWave([]float64{125}, []*texture.NonLinear{nl1, nl2}, false)
f := texture.NewLinearGradient(w)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleLinearGradient_circular")
fmt.Printf("Generated ExampleLinearGradient_circular")
// Output: Generated ExampleLinearGradient_circular
}
func ExampleRadialGradient_saw() {
nl := texture.NewNLLinear()
w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, false, false)
f := texture.NewRadialGradient(w)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleRadialGradient_saw")
fmt.Printf("Generated ExampleRadialGradient_saw")
// Output: Generated ExampleRadialGradient_saw
}
func ExampleRadialGradient_triangle() {
nl := texture.NewNLLinear()
w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
f := texture.NewRadialGradient(w)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleRadialGradient_triangle")
fmt.Printf("Generated ExampleRadialGradient_triangle")
// Output: Generated ExampleRadialGradient_triangle
}
func ExampleRadialGradient_sine() {
nl := texture.NewNLSin()
w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
f := texture.NewRadialGradient(w)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleRadialGradient_sine")
fmt.Printf("Generated ExampleRadialGradient_sine")
// Output: Generated ExampleRadialGradient_sine
}
func ExampleRadialGradient_circular() {
nl1 := texture.NewNLCircle1()
nl2 := texture.NewNLCircle2()
w := texture.NewDCWave([]float64{125}, []*texture.NonLinear{nl1, nl2}, false)
f := texture.NewRadialGradient(w)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleRadialGradient_circular")
fmt.Printf("Generated ExampleRadialGradient_circular")
// Output: Generated ExampleRadialGradient_circular
}
func ExampleConicGradient() {
nl := texture.NewNLSin()
w := texture.NewNLWave([]float64{125, 125, 125}, []*texture.NonLinear{nl, nl, nl}, true, false)
f := texture.NewConicGradient(w)
img := texture.NewTextureGray16(600, 600, f, -300, -300, 1, 1, false)
image.SaveImage(img, "ExampleConicGradient")
fmt.Printf("Generated ExampleConicGradient")
// Output: Generated ExampleConicGradient
}
func ExamplePerlin() {
f := texture.NewPerlin(12345)
img := texture.NewTextureGray16(600, 600, f, 0, 0, .015, .015, false)
image.SaveImage(img, "ExamplePerlin")
fmt.Printf("Generated ExamplePerlin")
// Output: Generated ExamplePerlin
}
func ExampleDisplace() {
f := texture.NewPerlin(12345)
fx := texture.NewPerlin(12346)
fy := texture.NewPerlin(12347)
f2 := texture.NewDisplace(f, fx, fy, 1)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
image.SaveImage(img, "ExampleDisplace")
fmt.Printf("Generated ExampleDisplace")
// Output: Generated ExampleDisplace
}
func ExampleTriangles() {
f := texture.NewTriangles(40)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleTriangles")
fmt.Printf("Generated ExampleTriangles")
// Output: Generated ExampleTriangles
}
func ExampleTransform() {
f := texture.NewTriangles(40)
// Apply a transform to convert to equilateral triangles
xfm := graphics2d.Rotate(-math.Pi / 4)
xfm.Scale(math.Sqrt2, 1)
f2 := texture.NewTransform(f, xfm)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleTransform")
fmt.Printf("Generated ExampleTransform")
// Output: Generated ExampleTransform
}
func ExampleSquares() {
f := texture.NewSquares(40)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleSquares")
fmt.Printf("Generated ExampleSquares")
// Output: Generated ExampleSquares
}
func ExampleHexagons() {
f := texture.NewHexagons(20)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleHexagons")
fmt.Printf("Generated ExampleHexagons")
// Output: Generated ExampleHexagons
}
func ExampleBlend() {
f := texture.NewHexagons(20)
f2 := texture.NewSquares(40)
nl := texture.NewNLLinear()
w := texture.NewNLWave([]float64{600}, []*texture.NonLinear{nl}, false, false)
f3 := texture.NewLinearGradient(w)
f4 := texture.NewBlend(f, f2, f3)
img := texture.NewTextureGray16(600, 600, f4, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleBlend")
fmt.Printf("Generated ExampleBlend")
// Output: Generated ExampleBlend
}
func ExampleShape() {
shape := graphics2d.NewShape(graphics2d.ReentrantPolygon([]float64{300, 300}, 300, 5, .65, 0))
f := texture.NewShape(shape, texture.BinaryStyle)
img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleShape")
fmt.Printf("Generated ExampleShape")
// Output: Generated ExampleShape
}
func ExampleShapeCombiner() {
nl := texture.NewNLSin()
w := texture.NewNLWave([]float64{32}, []*texture.NonLinear{nl}, true, false)
f := texture.NewRadialGradient(w)
xfm := graphics2d.Translate(-300, -300)
f2 := texture.NewTransform(f, xfm)
f3 := texture.NewSquares(40)
shape := graphics2d.NewShape(graphics2d.ReentrantPolygon([]float64{300, 300}, 300, 5, .65, 0))
f4 := texture.NewShapeCombiner(f2, f3, shape)
img := texture.NewTextureGray16(600, 600, f4, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleShapeCombiner")
fmt.Printf("Generated ExampleShapeCombiner")
// Output: Generated ExampleShapeCombiner
}
func ExampleWarp_radial() {
f := texture.NewSquares(40)
rwf := texture.NewRadialWF([]float64{300, 300}, 1, 1)
f2 := texture.NewWarp(f, rwf)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleWarp_radial")
fmt.Printf("Generated ExampleWarp_radial")
// Output: Generated ExampleWarp_radial
}
func ExampleWarp_radialnl1() {
f := texture.NewSquares(40)
rwf := texture.NewRadialNLWF([]float64{300, 300}, texture.NewNLExponential(3), 300)
f2 := texture.NewWarp(f, rwf)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleWarp_radialnl1")
fmt.Printf("Generated ExampleWarp_radialnl1")
// Output: Generated ExampleWarp_radialnl1
}
func ExampleWarp_radialnl2() {
f := texture.NewSquares(40)
rwf := texture.NewRadialNLWF([]float64{300, 300}, texture.NewNLLogarithmic(3), 300)
f2 := texture.NewWarp(f, rwf)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleWarp_radialnl2")
fmt.Printf("Generated ExampleWarp_radialnl2")
// Output: Generated ExampleWarp_radialnl2
}
func ExampleWarp_pinch() {
f := texture.NewSquares(40)
rwf := texture.NewPinchXWF([]float64{300, 300}, 0.3, 0.002, 2)
f2 := texture.NewWarp(f, rwf)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleWarp_pinch")
fmt.Printf("Generated ExampleWarp_pinch")
// Output: Generated ExampleWarp_pinch
}
func ExampleWarp_swirl() {
f := texture.NewSquares(40)
rwf := texture.NewSwirlWF([]float64{300, 300}, -0.05)
f2 := texture.NewWarp(f, rwf)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleWarp_swirl")
fmt.Printf("Generated ExampleWarp_swirl")
// Output: Generated ExampleWarp_swirl
}
func ExampleWarp_drain() {
f := texture.NewSquares(40)
rwf := texture.NewDrainWF([]float64{300, 300}, math.Pi, 250)
f2 := texture.NewWarp(f, rwf)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleWarp_drain")
fmt.Printf("Generated ExampleWarp_drain")
// Output: Generated ExampleWarp_drain
}
func ExampleWarp_ripple() {
f := texture.NewSquares(40)
rwf := texture.NewRippleXWF(100, 20, 12.5)
f2 := texture.NewWarp(f, rwf)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleWarp_ripple")
fmt.Printf("Generated ExampleWarp_ripple")
// Output: Generated ExampleWarp_ripple
}
func ExampleWarp_radialripple() {
f := texture.NewSquares(40)
rwf := texture.NewRadialRippleWF([]float64{300, 300}, 100, 10, 0)
f2 := texture.NewWarp(f, rwf)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleWarp_radialripple")
fmt.Printf("Generated ExampleWarp_radialripple")
// Output: Generated ExampleWarp_radialripple
}
func ExampleWarp_radialwriggle() {
f := texture.NewSquares(40)
rwf := texture.NewRadialWiggleWF([]float64{300, 300}, 100, 0.1, 0)
f2 := texture.NewWarp(f, rwf)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleWarp_radialwriggle")
fmt.Printf("Generated ExampleWarp_radialwriggle")
// Output: Generated ExampleWarp_radialwriggle
}
func ExampleTiler() {
nl := texture.NewNLCircle1()
w := texture.NewNLWave([]float64{47}, []*texture.NonLinear{nl}, false, true)
iw := texture.NewInvertWave(w)
f := texture.NewRadialGradient(iw)
xfm := graphics2d.Translate(-50, -50)
f2 := texture.NewTransform(f, xfm)
f3 := texture.NewTiler(f2, []float64{100, 100})
img := texture.NewTextureGray16(600, 600, f3, 0, 0, 1, 1, false)
image.SaveImage(img, "ExampleTiler")
fmt.Printf("Generated ExampleTiler")
// Output: Generated ExampleTiler
}
func ExampleReflect() {
f := texture.NewPerlin(12345)
f2 := texture.NewReflect(f, []float64{0, 9}, []float64{9, 0})
img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
image.SaveImage(img, "ExampleReflect")
fmt.Printf("Generated ExampleReflect")
// Output: Generated ExampleReflect
}
func ExampleDistort() {
f := texture.NewPerlin(12345)
f2 := texture.NewDistort(f, 10)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
image.SaveImage(img, "ExampleDistort")
fmt.Printf("Generated ExampleDistort")
// Output: Generated ExampleDistort
}
func ExampleFractal_fbm() {
f := texture.NewPerlin(12345)
lac := 2.0
hurst := 1.0
oct := 3.0
xfm := graphics2d.Scale(lac, lac)
fbm := texture.NewFBM(hurst, lac, int(oct+1))
f2 := texture.NewFractal(f, xfm, fbm, 3)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
image.SaveImage(img, "ExampleFractal_fbm")
fmt.Printf("Generated ExampleFractal_fbm")
// Output: Generated ExampleFractal_fbm
}
func ExampleFractal_mf() {
f := texture.NewPerlin(12345)
lac := 2.0
hurst := 1.0
oct := 3.0
xfm := graphics2d.Scale(lac, lac)
fbm := texture.NewMF(hurst, lac, 0.5, int(oct+1))
f2 := texture.NewFractal(f, xfm, fbm, 3)
img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
image.SaveImage(img, "ExampleFractal_mf")
fmt.Printf("Generated ExampleFractal_mf")
// Output: Generated ExampleFractal_mf
}