Skip to content

Commit

Permalink
Added decay waveform generation example
Browse files Browse the repository at this point in the history
  • Loading branch information
jphsd committed Sep 12, 2024
1 parent 5c79592 commit ba43f85
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions example_decay_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package texture_test

import (
"fmt"
"github.com/jphsd/graphics2d/image"
"github.com/jphsd/texture"
)

func Example_decay() {
// Original waveform
nl := texture.NewNLSin()
w := texture.NewNLWave([]float64{62}, []*texture.NonLinear{nl}, true, false)
w1 := texture.NewInvertWave(w)
f := texture.NewLinearGradient(w1)

// Decay factor
nl2 := texture.NewNLLinear()
w2 := texture.NewNLWave([]float64{600}, []*texture.NonLinear{nl2}, false, false)
w3 := texture.NewInvertWave(w2)
f2 := texture.NewLinearGradient(w3)

// Remap [-1,1] => [0,1]
f4 := texture.NewOffsScaleFilter(f2, 0.5, 1)

// Combine waves to get decay waveform
f3 := texture.NewMulCombiner(f, f4)

img := texture.NewTextureGray16(600, 600, f3, 0, 0, 1, 1, false)
image.SaveImage(img, "Example_decay")
fmt.Printf("Generated Example_decay")
// Output: Generated Example_decay
}

0 comments on commit ba43f85

Please sign in to comment.