@@ -54,7 +54,11 @@ var TextStage = Utilities.createSubclass(Stage,
54
54
Stage . prototype . initialize . call ( this , benchmark ) ;
55
55
56
56
this . _template = document . getElementById ( "template" ) ;
57
- this . _offset = this . size . subtract ( Point . elementClientSize ( this . _template ) ) . multiply ( .5 ) ;
57
+
58
+ const templateSize = Point . elementClientSize ( this . _template ) ;
59
+ this . _offset = this . size . subtract ( templateSize ) . multiply ( .5 ) ;
60
+ this . _maxOffset = templateSize . height / 4 ;
61
+
58
62
this . _template . style . left = this . _offset . width + "px" ;
59
63
this . _template . style . top = this . _offset . height + "px" ;
60
64
@@ -68,7 +72,7 @@ var TextStage = Utilities.createSubclass(Stage,
68
72
69
73
if ( count < 0 ) {
70
74
this . _offsetIndex = Math . max ( this . _offsetIndex + count , 0 ) ;
71
- for ( var i = this . _offsetIndex ; i < this . testElements . length ; ++ i )
75
+ for ( let i = this . _offsetIndex ; i < this . testElements . length ; ++ i )
72
76
this . testElements [ i ] . style . visibility = "hidden" ;
73
77
74
78
this . _stepProgress = 1 / this . _offsetIndex ;
@@ -78,44 +82,43 @@ var TextStage = Utilities.createSubclass(Stage,
78
82
this . _offsetIndex = this . _offsetIndex + count ;
79
83
this . _stepProgress = 1 / this . _offsetIndex ;
80
84
81
- var index = Math . min ( this . _offsetIndex , this . testElements . length ) ;
82
- for ( var i = 0 ; i < index ; ++ i )
85
+ const index = Math . min ( this . _offsetIndex , this . testElements . length ) ;
86
+ for ( let i = 0 ; i < index ; ++ i )
83
87
this . testElements [ i ] . style . visibility = "visible" ;
84
88
85
89
if ( this . _offsetIndex <= this . testElements . length )
86
90
return ;
87
91
88
- for ( var i = this . testElements . length ; i < this . _offsetIndex ; ++ i ) {
89
- var clone = this . _template . cloneNode ( true ) ;
92
+ for ( let i = this . testElements . length ; i < this . _offsetIndex ; ++ i ) {
93
+ const clone = this . _template . cloneNode ( true ) ;
90
94
this . testElements . push ( clone ) ;
91
95
this . element . insertBefore ( clone , this . element . firstChild ) ;
92
96
}
93
97
} ,
94
98
95
- animate : function ( timeDelta ) {
96
- var angle = Stage . dateCounterValue ( this . millisecondsPerRotation ) ;
97
-
98
- var progress = 0 ;
99
- var stepX = Math . sin ( angle ) * this . particleDistanceX ;
100
- var stepY = Math . cos ( angle ) * this . particleDistanceY ;
101
- var x = - stepX * 3 ;
102
- var y = - stepY * 3 ;
103
- var gradient = this . gradients [ Math . floor ( angle / ( Math . PI * 2 ) ) % this . gradients . length ] ;
104
- var offset = Stage . dateCounterValue ( 200 ) ;
105
- this . _template . style . transform = "translate(" + Math . floor ( x ) + "px," + Math . floor ( y ) + "px)" ;
106
- for ( var i = 0 ; i < this . _offsetIndex ; ++ i ) {
107
- var element = this . testElements [ i ] ;
108
-
109
- var colorProgress = this . shadowFalloff . solve ( progress ) ;
110
- var shimmer = Math . sin ( offset - colorProgress ) ;
99
+ animate : function ( timeDelta )
100
+ {
101
+ const angle = Stage . dateCounterValue ( this . millisecondsPerRotation ) ;
102
+
103
+ const gradient = this . gradients [ Math . floor ( angle / ( Math . PI * 2 ) ) % this . gradients . length ] ;
104
+ const offset = Stage . dateCounterValue ( 200 ) ;
105
+ const maxX = Math . sin ( angle ) * this . _maxOffset ;
106
+ const maxY = Math . cos ( angle ) * this . _maxOffset ;
107
+
108
+ let progress = 0 ;
109
+ for ( let i = 0 ; i < this . _offsetIndex ; ++ i ) {
110
+ const element = this . testElements [ i ] ;
111
+
112
+ let colorProgress = this . shadowFalloff . solve ( progress ) ;
113
+ const shimmer = Math . sin ( offset - colorProgress ) ;
111
114
colorProgress = Math . max ( Math . min ( colorProgress + Utilities . lerp ( shimmer , this . shimmerAverage , this . shimmerMax ) , 1 ) , 0 ) ;
112
- var r = Math . round ( Utilities . lerp ( colorProgress , gradient [ 0 ] , gradient [ 3 ] ) ) ;
113
- var g = Math . round ( Utilities . lerp ( colorProgress , gradient [ 1 ] , gradient [ 4 ] ) ) ;
114
- var b = Math . round ( Utilities . lerp ( colorProgress , gradient [ 2 ] , gradient [ 5 ] ) ) ;
115
+ const r = Math . round ( Utilities . lerp ( colorProgress , gradient [ 0 ] , gradient [ 3 ] ) ) ;
116
+ const g = Math . round ( Utilities . lerp ( colorProgress , gradient [ 1 ] , gradient [ 4 ] ) ) ;
117
+ const b = Math . round ( Utilities . lerp ( colorProgress , gradient [ 2 ] , gradient [ 5 ] ) ) ;
115
118
element . style . color = "rgb(" + r + "," + g + "," + b + ")" ;
116
119
117
- x += stepX ;
118
- y += stepY ;
120
+ const x = Utilities . lerp ( i / this . _offsetIndex , 0 , maxX ) ;
121
+ const y = Utilities . lerp ( i / this . _offsetIndex , 0 , maxY ) ;
119
122
element . style . transform = "translate(" + Math . floor ( x ) + "px," + Math . floor ( y ) + "px)" ;
120
123
121
124
progress += this . _stepProgress ;
0 commit comments