@@ -54,7 +54,11 @@ var TextStage = Utilities.createSubclass(Stage,
5454 Stage . prototype . initialize . call ( this , benchmark ) ;
5555
5656 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+
5862 this . _template . style . left = this . _offset . width + "px" ;
5963 this . _template . style . top = this . _offset . height + "px" ;
6064
@@ -68,7 +72,7 @@ var TextStage = Utilities.createSubclass(Stage,
6872
6973 if ( count < 0 ) {
7074 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 )
7276 this . testElements [ i ] . style . visibility = "hidden" ;
7377
7478 this . _stepProgress = 1 / this . _offsetIndex ;
@@ -78,44 +82,43 @@ var TextStage = Utilities.createSubclass(Stage,
7882 this . _offsetIndex = this . _offsetIndex + count ;
7983 this . _stepProgress = 1 / this . _offsetIndex ;
8084
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 )
8387 this . testElements [ i ] . style . visibility = "visible" ;
8488
8589 if ( this . _offsetIndex <= this . testElements . length )
8690 return ;
8791
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 ) ;
9094 this . testElements . push ( clone ) ;
9195 this . element . insertBefore ( clone , this . element . firstChild ) ;
9296 }
9397 } ,
9498
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 ) ;
111114 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 ] ) ) ;
115118 element . style . color = "rgb(" + r + "," + g + "," + b + ")" ;
116119
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 ) ;
119122 element . style . transform = "translate(" + Math . floor ( x ) + "px," + Math . floor ( y ) + "px)" ;
120123
121124 progress += this . _stepProgress ;
0 commit comments