-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerator_creative.go
More file actions
265 lines (222 loc) · 7.02 KB
/
Copy pathgenerator_creative.go
File metadata and controls
265 lines (222 loc) · 7.02 KB
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
package stmap
import (
"math"
)
func init() {
registerAnimatedGenerator(GeneratorInfo{
Name: "heat_shimmer",
Description: "Per-row sinusoidal vertical displacement simulating heat haze",
Type: "animated",
Params: map[string]ParamInfo{
"intensity": {Description: "Shimmer intensity", Default: 0.3, Min: 0, Max: 1},
"frequency": {Description: "Oscillation frequency (Hz)", Default: 2.0, Min: 0.5, Max: 10},
},
}, generateHeatShimmer)
registerAnimatedGenerator(GeneratorInfo{
Name: "dream",
Description: "Radial pull toward center with pulsing for a dreamy effect",
Type: "animated",
Params: map[string]ParamInfo{
"intensity": {Description: "Dream intensity", Default: 0.4, Min: 0, Max: 1},
},
}, generateDream)
registerAnimatedGenerator(GeneratorInfo{
Name: "ripple",
Description: "Concentric circular ripple displacement from a center point",
Type: "animated",
Params: map[string]ParamInfo{
"amplitude": {Description: "Ripple amplitude in pixels", Default: 8, Min: 1, Max: 30},
"wavelength": {Description: "Ripple wavelength in pixels", Default: 60, Min: 10, Max: 200},
"cx": {Description: "Center X (normalized 0-1)", Default: 0.5, Min: 0, Max: 1},
"cy": {Description: "Center Y (normalized 0-1)", Default: 0.5, Min: 0, Max: 1},
},
}, generateRipple)
registerAnimatedGenerator(GeneratorInfo{
Name: "lens_breathe",
Description: "Radial scale oscillation from center simulating breathing lens",
Type: "animated",
Params: map[string]ParamInfo{
"amplitude": {Description: "Scale amplitude", Default: 0.02, Min: 0, Max: 0.1},
"frequency": {Description: "Breathing frequency (Hz)", Default: 0.5, Min: 0.1, Max: 5},
},
}, generateLensBreathe)
registerAnimatedGenerator(GeneratorInfo{
Name: "vortex",
Description: "Angular displacement increasing with distance from center",
Type: "animated",
Params: map[string]ParamInfo{
"intensity": {Description: "Vortex intensity", Default: 0.3, Min: 0, Max: 1},
},
}, generateVortex)
}
// generateHeatShimmer produces per-row sinusoidal vertical displacement.
func generateHeatShimmer(params map[string]float64, w, h, frameCount int) (*AnimatedSTMap, error) {
intensity := params["intensity"]
frequency := params["frequency"]
identity := Identity(w, h)
twoPi := 2.0 * math.Pi
fh := float64(h)
frames := make([]*STMap, frameCount)
for f := 0; f < frameCount; f++ {
phase := twoPi * float64(f) / float64(frameCount)
s := make([]float32, w*h)
t := make([]float32, w*h)
// Copy identity S (no horizontal displacement).
copy(s, identity.S)
for y := 0; y < h; y++ {
displacement := intensity * 0.01 * math.Sin(twoPi*frequency*float64(y)/fh+phase)
dispF32 := float32(displacement)
row := y * w
for x := 0; x < w; x++ {
t[row+x] = identity.T[row+x] + dispF32
}
}
frames[f] = &STMap{
Name: "heat_shimmer",
Width: w,
Height: h,
S: s,
T: t,
}
}
return NewAnimatedSTMap("heat_shimmer", frames, 30), nil
}
// generateDream produces a radial pull toward center with pulsing.
func generateDream(params map[string]float64, w, h, frameCount int) (*AnimatedSTMap, error) {
intensity := params["intensity"]
identity := Identity(w, h)
twoPi := 2.0 * math.Pi
fw := float64(w)
fh := float64(h)
frames := make([]*STMap, frameCount)
for f := 0; f < frameCount; f++ {
pulse := 0.5 + 0.5*math.Sin(twoPi*float64(f)/float64(frameCount))
s := make([]float32, w*h)
t := make([]float32, w*h)
for y := 0; y < h; y++ {
row := y * w
dy := (float64(y)+0.5)/fh - 0.5
for x := 0; x < w; x++ {
idx := row + x
dx := (float64(x)+0.5)/fw - 0.5
r := math.Sqrt(dx*dx + dy*dy)
pull := intensity * 0.1 * pulse * r
rSafe := math.Max(r, 0.001)
s[idx] = identity.S[idx] - float32(pull*dx/rSafe)
t[idx] = identity.T[idx] - float32(pull*dy/rSafe)
}
}
frames[f] = &STMap{
Name: "dream",
Width: w,
Height: h,
S: s,
T: t,
}
}
return NewAnimatedSTMap("dream", frames, 30), nil
}
// generateRipple produces concentric circular displacement from a center point.
func generateRipple(params map[string]float64, w, h, frameCount int) (*AnimatedSTMap, error) {
amplitude := params["amplitude"]
wavelength := params["wavelength"]
cx := params["cx"]
cy := params["cy"]
identity := Identity(w, h)
twoPi := 2.0 * math.Pi
fw := float64(w)
fh := float64(h)
frames := make([]*STMap, frameCount)
for f := 0; f < frameCount; f++ {
phase := twoPi * float64(f) / float64(frameCount)
s := make([]float32, w*h)
t := make([]float32, w*h)
for y := 0; y < h; y++ {
row := y * w
dy := (float64(y) + 0.5) - cy*fh
for x := 0; x < w; x++ {
idx := row + x
dx := (float64(x) + 0.5) - cx*fw
r := math.Sqrt(dx*dx + dy*dy)
if r > 0 {
disp := amplitude * math.Sin(twoPi*r/wavelength+phase) / r
s[idx] = identity.S[idx] + float32(disp*dx/fw)
t[idx] = identity.T[idx] + float32(disp*dy/fh)
} else {
s[idx] = identity.S[idx]
t[idx] = identity.T[idx]
}
}
}
frames[f] = &STMap{
Name: "ripple",
Width: w,
Height: h,
S: s,
T: t,
}
}
return NewAnimatedSTMap("ripple", frames, 30), nil
}
// generateLensBreathe produces radial scale oscillation from center.
func generateLensBreathe(params map[string]float64, w, h, frameCount int) (*AnimatedSTMap, error) {
amplitude := params["amplitude"]
frequency := params["frequency"]
identity := Identity(w, h)
twoPi := 2.0 * math.Pi
frames := make([]*STMap, frameCount)
for f := 0; f < frameCount; f++ {
scale := 1.0 + amplitude*math.Sin(twoPi*frequency*float64(f)/float64(frameCount))
s := make([]float32, w*h)
t := make([]float32, w*h)
for i := 0; i < w*h; i++ {
s[i] = float32(0.5 + (float64(identity.S[i])-0.5)*scale)
t[i] = float32(0.5 + (float64(identity.T[i])-0.5)*scale)
}
frames[f] = &STMap{
Name: "lens_breathe",
Width: w,
Height: h,
S: s,
T: t,
}
}
return NewAnimatedSTMap("lens_breathe", frames, 30), nil
}
// generateVortex produces angular displacement increasing with distance.
func generateVortex(params map[string]float64, w, h, frameCount int) (*AnimatedSTMap, error) {
intensity := params["intensity"]
twoPi := 2.0 * math.Pi
fw := float64(w)
fh := float64(h)
frames := make([]*STMap, frameCount)
for f := 0; f < frameCount; f++ {
phase := twoPi * float64(f) / float64(frameCount)
s := make([]float32, w*h)
t := make([]float32, w*h)
for y := 0; y < h; y++ {
row := y * w
dy := (float64(y)+0.5)/fh - 0.5
for x := 0; x < w; x++ {
idx := row + x
dx := (float64(x)+0.5)/fw - 0.5
r := math.Sqrt(dx*dx + dy*dy)
angle := intensity * r * math.Sin(phase)
cosA := math.Cos(angle)
sinA := math.Sin(angle)
newDx := dx*cosA - dy*sinA
newDy := dx*sinA + dy*cosA
s[idx] = float32(newDx + 0.5)
t[idx] = float32(newDy + 0.5)
}
}
frames[f] = &STMap{
Name: "vortex",
Width: w,
Height: h,
S: s,
T: t,
}
}
return NewAnimatedSTMap("vortex", frames, 30), nil
}