1
1
import 'pixi.js'
2
- import { TweenMax , Power3 , RoughEase , Linear } from 'gsap'
2
+ import { TweenMax , Power3 , Power4 , RoughEase , Linear } from 'gsap'
3
3
/* globals PIXI */
4
4
5
5
// Create class - needed something that was effected by vue
6
6
export default class VueBuildIntro {
7
7
constructor ( ) {
8
8
this . height = window . innerHeight
9
9
this . width = window . innerWidth
10
+ this . primaryColor = parseInt ( '41B883' , 16 ) // #41B883
11
+ this . secondaryColor = parseInt ( '35495E' , 16 ) // #35495E
10
12
this . canvas = document . getElementById ( 'canvasIntro' )
11
13
this . app = new PIXI . Application ( this . height , this . width , {
12
14
antialias : true ,
@@ -18,6 +20,10 @@ export default class VueBuildIntro {
18
20
window . addEventListener ( 'resize' , this . resize ( ) )
19
21
this . canvas . appendChild ( this . app . view )
20
22
this . all = new PIXI . Container ( ) // Container for all v's
23
+ this . all . positionX = this . width / 2
24
+ this . all . positionY = this . height / 2
25
+ this . all . positionYStart = - 200
26
+ this . all . positionYEnd = 200
21
27
22
28
// Make a container to hold all v's
23
29
this . app . stage . addChild ( this . all ) // Add to state
@@ -30,14 +36,10 @@ export default class VueBuildIntro {
30
36
// Center and scale
31
37
this . allCenter ( )
32
38
33
- // Animate minis
34
- this . animateMinis ( )
35
-
36
- // Animate
37
- this . spreadOut ( 0.5 , 1 )
38
- . then ( ( ) => {
39
+ // Start animations
40
+ setTimeout ( ( ) => {
39
41
this . animate ( )
40
- } )
42
+ } , 500 )
41
43
}
42
44
43
45
// When window resizes resize renderer
@@ -53,11 +55,11 @@ export default class VueBuildIntro {
53
55
this . all . pivot . y = this . height / 2
54
56
55
57
// Set x and y
56
- this . all . x = this . width / 2
57
- this . all . y = this . height / 2
58
+ this . all . x = this . all . positionX
59
+ this . all . y = this . all . positionYStart
58
60
59
61
// Scale to size - must be dont after setting pivot
60
- this . all . scale . set ( 0.3 )
62
+ this . all . scale . set ( 0.4 )
61
63
}
62
64
63
65
// Create V container and center
@@ -69,14 +71,16 @@ export default class VueBuildIntro {
69
71
v . addChild ( vBottom )
70
72
71
73
// Set pivot and position
72
- v . pivot . x = info . pivotX ? info . pivotX : v . width / 2
73
- v . pivot . y = info . pivotY ? info . pivotY : - 115
74
74
v . x += info . x ? info . x : this . width / 2
75
75
v . y += info . y ? info . y : this . height / 2
76
+ if ( info . pivotX && info . pivotX === 'center' ) { info . pivotX = v . width / 2 }
77
+ if ( info . pivotY && info . pivotY === 'center' ) { info . pivotY = v . height / 2 }
78
+ v . pivot . x = info . pivotX ? info . pivotX : v . width / 2
79
+ v . pivot . y = info . pivotY ? info . pivotY : - 115
76
80
77
- if ( info . scale ) {
78
- v . scale . set ( info . scale )
79
- }
81
+ if ( info . scale ) { v . scale . set ( info . scale ) }
82
+ if ( info . rotation ) { v . rotation = info . rotation }
83
+ if ( info . alpha ) { v . alpha = info . alpha }
80
84
81
85
return v
82
86
}
@@ -85,7 +89,7 @@ export default class VueBuildIntro {
85
89
vTop ( ) {
86
90
var v = new PIXI . Graphics ( )
87
91
88
- v . beginFill ( parseInt ( '35495E' , 16 ) )
92
+ v . beginFill ( this . secondaryColor )
89
93
v . moveTo ( 80 , 0 )
90
94
v . lineTo ( 200 , 205 )
91
95
v . lineTo ( 320 , 0 )
@@ -102,7 +106,7 @@ export default class VueBuildIntro {
102
106
vBottom ( ) {
103
107
var v = new PIXI . Graphics ( )
104
108
105
- v . beginFill ( parseInt ( '41B883' , 16 ) )
109
+ v . beginFill ( this . primaryColor )
106
110
v . moveTo ( 0 , 0 )
107
111
v . lineTo ( 200 , 345 )
108
112
v . lineTo ( 400 , 0 )
@@ -115,43 +119,150 @@ export default class VueBuildIntro {
115
119
return v
116
120
}
117
121
118
- animateMinis ( ) {
122
+ // Animate is responsible for calling animations in order and timing
123
+ animate ( ) {
124
+ // Zoom v in
125
+ this . zoomIn ( )
126
+ . then ( ( ) => {
127
+ this . shakeAll ( 0.3 , 2 )
128
+ this . minisIn ( ) // Send out the minis
129
+
130
+ return this . spreadOut ( 0.5 , 1 )
131
+ } )
132
+ . then ( ( ) => {
133
+ this . spin ( 1 )
134
+ this . scaleOutAll ( 0.7 )
135
+ . then ( ( ) => {
136
+ return this . scaleInAll ( 0.3 )
137
+ } )
138
+
139
+ return this . openV ( 0.7 )
140
+ . then ( ( ) => {
141
+ return this . closeV ( 0.3 )
142
+ . then ( ( ) => {
143
+ this . minisOut ( )
144
+ return this . shakeAll ( 0.3 , 5 )
145
+ } )
146
+ } )
147
+ } )
148
+ }
149
+
150
+ // Take all container and zoom into positionY
151
+ // Also create
152
+ zoomIn ( timing = 0.75 ) {
153
+ return new Promise ( ( resolve , reject ) => {
154
+ TweenMax . fromTo ( this . all , timing ,
155
+ { y : - 200 } ,
156
+ { y : this . all . positionY ,
157
+ ease : Power4 . easeIn ,
158
+ onComplete : ( ) => {
159
+ resolve ( )
160
+ }
161
+ } )
162
+
163
+ // Create trailing zoom
164
+ var rect = new PIXI . Graphics ( )
165
+ rect . beginFill ( this . primaryColor , 1 )
166
+ rect . drawRect ( 0 , 0 , 1 , 2 )
167
+ rect . endFill ( )
168
+ this . app . stage . addChild ( rect )
169
+
170
+ rect . pivot . x = rect . width / 2
171
+ rect . pivot . y = 0
172
+ rect . x = this . width / 2
173
+ rect . y = 0
174
+
175
+ TweenMax . to ( rect , timing ,
176
+ {
177
+ delay : 0.1 ,
178
+ height : this . height ,
179
+ ease : Power4 . easeOut ,
180
+ onComplete : ( ) => {
181
+ TweenMax . to ( rect , 0.3 , {
182
+ alpha : 0 ,
183
+ width : this . width ,
184
+ ease : Power4 . easeIn ,
185
+ onComplete : ( ) => {
186
+ setTimeout ( ( ) => {
187
+ rect . destroy ( )
188
+ } , 1000 )
189
+ }
190
+ } )
191
+ }
192
+ }
193
+ )
194
+ } )
195
+ }
196
+
197
+ // Load a bunch mini v's and animate them in the center
198
+ minisIn ( ) {
119
199
// Load a bunch of mini v's
120
200
for ( var iMini = 0 ; iMini < 100 ; iMini ++ ) {
201
+ let x = this . getRandomNum ( - 600 , this . width + 600 )
202
+ let y = - 200
203
+ let toX = this . width / 2
204
+ let toY = this . height / 2
205
+
121
206
let vMini = this . v ( {
122
207
scale : 0.3 ,
123
- x : this . getRandomNum ( - 600 , this . width + 600 ) ,
124
- y : - 200
208
+ x : x ,
209
+ y : y ,
210
+ pivotX : 'center' ,
211
+ pivotY : 'center'
125
212
} )
126
213
this . app . stage . addChild ( vMini )
127
214
TweenMax . to ( vMini , 0.6 , {
128
215
delay : this . getRandomNum ( 0 , 2 ) ,
129
216
ease : Power3 . easeIn ,
130
- x : this . width / 2 ,
131
- y : this . height / 2 ,
132
- height : 0 ,
133
- width : 0 ,
217
+ x : toX ,
218
+ y : toY ,
219
+ alpha : 0.3 ,
220
+ height : 5 ,
221
+ width : 5 ,
134
222
onComplete ( ) {
135
223
vMini . destroy ( )
136
224
}
137
225
} )
138
226
}
139
227
}
140
228
141
- // Animate is responsible for calling animations in order and timing
142
- animate ( ) {
143
- this . spin ( 1 )
144
- this . scaleOutAll ( 0.7 )
145
- . then ( ( ) => {
146
- this . scaleInAll ( 0.3 )
147
- } )
148
- this . openV ( 0.7 )
149
- . then ( ( ) => {
150
- this . closeV ( 0.3 )
151
- . then ( ( ) => {
152
- this . shakeAll ( 0.3 )
229
+ // Load a bunch mini v's and animate them in the center
230
+ minisOut ( ) {
231
+ // Load a bunch of mini v's
232
+ for ( var iMini = 0 ; iMini < 100 ; iMini ++ ) {
233
+ let x = this . width / 2
234
+ let y = this . height / 2
235
+ let toX = this . getRandomNum ( 0 , this . width )
236
+ let toY = this . getRandomNum ( 0 , this . height )
237
+
238
+ let vMini = this . v ( {
239
+ alpha : 0 ,
240
+ scale : 0.1 ,
241
+ x : x ,
242
+ y : y ,
243
+ pivotX : 'center' ,
244
+ pivotY : 'center'
153
245
} )
154
- } )
246
+ this . app . stage . addChildAt ( vMini , this . app . stage . length - 1 ) // Add to front
247
+ TweenMax . to ( vMini , 1 , {
248
+ delay : this . getRandomNum ( 0 , 0.2 ) ,
249
+ ease : Power4 . easeOut ,
250
+ alpha : 0.1 ,
251
+ x : toX ,
252
+ y : toY ,
253
+ onComplete : ( ) => {
254
+ // vMini.destroy()
255
+ TweenMax . to ( vMini , 1 , {
256
+ alpha : 0 ,
257
+ x : this . getRandomNum ( toX - 150 , toX + 150 ) ,
258
+ y : this . height ,
259
+ onComplete : ( ) => {
260
+
261
+ }
262
+ } )
263
+ }
264
+ } )
265
+ }
155
266
}
156
267
157
268
// Animate v letters spreading out
@@ -161,15 +272,19 @@ export default class VueBuildIntro {
161
272
TweenMax . to ( this . all . children [ 1 ] , timing , {
162
273
delay : delay ,
163
274
rotation : 120 * PIXI . DEG_TO_RAD ,
164
- ease : Power3 . easeIn
275
+ ease : Power3 . easeIn ,
276
+ onComplete : ( ) => {
277
+ this . shakeAll ( 0.3 )
278
+ }
165
279
} )
166
280
167
281
// Rotate top right
168
282
TweenMax . to ( this . all . children [ 2 ] , timing , {
169
283
delay : delay * 1.5 ,
170
284
rotation : 240 * PIXI . DEG_TO_RAD ,
171
285
ease : Power3 . easeIn ,
172
- onComplete : function ( ) {
286
+ onComplete : ( ) => {
287
+ this . shakeAll ( 0.3 )
173
288
resolve ( )
174
289
}
175
290
} )
@@ -238,13 +353,12 @@ export default class VueBuildIntro {
238
353
} )
239
354
}
240
355
356
+ // Slam down v's
241
357
scaleInAll ( timing ) {
242
358
return new Promise ( ( resolve , reject ) => {
243
- // Open v and slam sh
244
359
TweenMax . to ( this . all . scale , timing , {
245
360
x : 0.5 ,
246
361
y : 0.5 ,
247
- // this.all.scale.set(0.4),
248
362
ease : Power3 . easeIn ,
249
363
onComplete : function ( ) {
250
364
resolve ( )
@@ -254,19 +368,19 @@ export default class VueBuildIntro {
254
368
}
255
369
256
370
// Shake all container
257
- shakeAll ( timing ) {
371
+ shakeAll ( timing = 0.3 , shake = 4 ) {
258
372
TweenMax . fromTo ( this . all , timing ,
259
- { x : this . width / 2 , y : this . height / 2 } ,
260
- { x : '+=3' ,
261
- y : '+=3' ,
373
+ { x : this . all . positionX , y : this . all . positionY } ,
374
+ { x : '+=' + shake ,
375
+ y : '+=' + shake ,
262
376
ease : RoughEase . ease . config ( {
263
377
strength : 8 , points : 20 , template : Linear . easeNone , randomize : false
264
378
} )
265
379
}
266
380
)
267
381
268
382
// Make sure you are back to center again
269
- TweenMax . to ( this . all , 0 , { delay : timing , x : this . width / 2 , y : this . height / 2 } )
383
+ TweenMax . to ( this . all , 0 , { delay : timing , x : this . all . positionX , y : this . all . positionY } )
270
384
}
271
385
272
386
getRandomNum ( min , max ) {
0 commit comments