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
|
SVG.Morphable = SVG.invent({
create: function (controller) {
// FIXME: the default controller does not know about easing
this.controller = controller || function (from, to, pos) {
return from + (to - from) * pos
}
},
extend: {
from: function (val) {
this._from = this._set(val)
return this
},
to: function (val, modifier) {
this._to = this._set(val)
this.modifier = modifier
return this
},
type: function (type) {
this._type = type
// non standard morphing
if(type instanceof SVG.Morphable.NonMorphable) {
this._controller = function (from, to, pos) {
return pos < 1 ? from : to
}
}
return this
},
_set: function (value) {
if(!this._type) {
if (SVG.Color.isColor(val)) {
this.type(SVG.Color)
} else if (SVG.regex.delimiter.test(val)) {
this.type(SVG.regex.pathLetters.test(val)
? SVG.PathArray
: SVG.Array
)
} else if (SVG.regex.numberAndUnit.test(val)) {
this.type(SVG.Number)
} else if (value in SVG.MorphableTypes) {
this.type(value.constructor)
} else {
this.type(SVG.Morphable.NonMorphable)
}
}
return (new this._type(value)).toArray()
},
controller: function (controller) {
this._controller = controller
},
at: function (pos) {
var _this = this
modifier = this.modifier || function(el) { return el }
// for(var i = 0, len = this._from.length; i < len; ++i) {
// arr.push(this.controller(this._from[i], this._to[i]))
// }
return this.type.fromArray(modifier(this._from.map(function (i, index) {
return _this._controller(i, _this._to[i], pos)
})))
},
valueOf: function () {
return this._value
}
}
})
SVG.Morphable.NonMorphable = SVG.invent({
create: function (val) {
this.value = val
},
extend: {
valueOf: function () {
return this.value
},
toArray: function () {
return [this.value]
},
fromArray: function (arr) {
return new SVG.Morphable.NonMorphable(arr[0])
}
}
})
SVG.Morphable.TransformBag = SVG.invent({
create: function (val) {
this.value = new Matrix(val).decompose()
},
extend: {
valueOf: function () {
return this.value
},
toArray: function (){
var v = this.value
return [
v.scaleX,
v.scaleY,
v.shear,
v.rotate,
v.translateX,
v.translateY
]
},
fromArray: function (arr) {
return new SVG.Morphable.TransformBag({
scaleX: arr[0],
scaleY: arr[1],
shear: arr[2],
rotate: arr[3],
translateX: arr[4],
translateY: arr[5]
})
}
}
})
SVG.Morphable.ObjectBag = SVG.invent({
create: function (obj) {
this.values = []
this.keys = []
for(var i in obj) {
this.values.push(obj[i])
this.keys.push(i)
}
},
extend: {
valueOf: function () {
return this.values
},
toArray: function (){
return this.values
},
fromArray: function (arr) {
var obj = {}
for(var i = 0, len = arr.length; i < len; ++i) {
obj[this.keys[i]] = arr[i]
}
return obj
}
}
})
SVG.MorphableTypes = [
SVG.Number,
SVG.Color,
SVG.Box,
SVG.Matrix,
SVG.Array,
SVG.PointArray,
SVG.PathArray,
SVG.Morphable.NonMorphable,
SVG.Morphable.TransformBag,
SVG.Morphable.ObjectBag,
]
SVG.extend(SVG.MorphableTypes, {
to: (item, args) => {
let a = new SVG.Morphable().type(this.constructor).to(item, args)
},
})
// animate().ease(function(pos) { return pos})
// function Ease (func) {
// return function eased (fromOrCurr, to, pos) {
// return fromOrCurr + func(pos) * (to - fromOrCurr) // normal easing
// }
// }
///
/// el.animate()
/// .fill('#00f')
/// ---->> timeline.fill
/// val = new Morphable().to('#0ff').controller(controller)
/// func init() {
/// val.from(el.fill())
/// }
/// func run (pos) {
/// curr = val.at(pos)
/// el.fill(curr)
/// }
/// this.queue(init, run)
// - Objects are just variable bags
// - morph rerutrns a morphable. No state on normal objects (like SVG.Color)
// - Objects can be represented as Array (with toArray())
// - Objects have an unmorph/fromarray function which converts it back to a normal object
// var b = new Color('#fff')
// b.morph('#000') === new Morph(b).to('#000')
// sweet = Color('#fff')
// dark = Color('#fef')
// sweet.to(dark, 'hsl')
// angle = Number(30)
// lastAngle = Number(300)
// angle.to(lastAngle, cyclic)
// mat1 = Matrix().transform({rotation: 30, scale: 0})
// mat2 = Matrix(30, 40, 50, 60, 10, 20)
// mat1.to(mat2)
// C R x = D C x = A x
//
// (C R inv(C)) C x
//
//
// C R = D C
// D = C R inv(C)
/*
absolute -> start at current - {affine params}
relative -> start at 0 always - {random stuff}
*/
/**
INIT
- save the current transformation
ELEMENT TIMELINE (one timeline per el)
- Reads the current transform and save it to the transformation stack
- Runs all available runners, runners will:
- Modify their transformation on the stack
- Mark their transformation as complete
- After each runner, we group the matrix (not for now)
- After running the runners, we bundle all contiguous transformations into
a single transformation
- transformtionstack is like this: [RunnerB, Matrix, RunnerC]
- skip merging for now (premature blabla)
el.loop({times: 5, swing: true, wait: [20, 50]})
el.opacity(0)
.animate(300).opacity(1)
.animate(300, true).scale(5).reverse()
for(var i = 0; i < 7; ++i)
circle.clone()
.scale(3).rotate(0)
.loop({swing: false, wait: 500})
.scale(1)
.rotate(360)
.delay(1000)
.animate(500, 'swingOut')
.scale(3)
}
fn () => {
el.animate().stroke('dashoffset', 213).scale(1)
.delay(1)
.animate().scale(2)
.after(fn)
}
When you start an element has a base matrix B - which starts as the identity
If you modify the matrix, then we have:
T U V W X B x
. . .
runner.step()
for all runners in stack:
if(runner is done) repalce with matrix
if(2 matrix next to eachother are done) {
}
What if
/// RunnerA
el.animate()
.transform({rotate: 30, scale: 2})
.transform({rotate: 500}, true)
f| -----A-----
s| --------B---------
t| ---------C-------
**/
|