1- import { interpolateBetweenLoop } from "../interpolate" ;
1+ import { interpolateBetweenSmooth } from "../interpolate" ;
22import { divideShape , prepShapes } from "../prepare" ;
33import { Coord , Point , Shape } from "../../types" ;
4- import { length , insertAt , insertCount , rad , mod , mapShape , forShape } from "../../util" ;
4+ import { length , insertAt , insertCount , rad , mod , mapShape , forShape , smooth } from "../../util" ;
55import { clear , drawInfo , drawShape } from "../../render/canvas" ;
66import { genBlob } from "../../blobs" ;
77import { rand } from "../../rand" ;
@@ -101,13 +101,13 @@ const testInterpolateBetween = (percentage: number) => {
101101 point ( 0.35 , 0.82 , 360 * 10 , 0 , 180 , 0 ) ,
102102 point ( 0.3 , 0.77 , 90 , 0 , - 90 , 0 ) ,
103103 ] ;
104- drawShape ( ctx , debug , interpolateBetweenLoop ( percentage , a , b ) ) ;
104+ drawShape ( ctx , debug , loopBetween ( percentage , a , b ) ) ;
105105} ;
106106
107107const testPrepShapesA = ( percentage : number ) => {
108108 const a = blob ( "a" , 6 , 0.15 , { x : 0.45 , y : 0.1 } ) ;
109109 const b = blob ( "b" , 10 , 0.15 , { x : 0.45 , y : 0.1 } ) ;
110- drawShape ( ctx , debug , interpolateBetweenLoop ( percentage , ...prepShapes ( a , b ) ) ) ;
110+ drawShape ( ctx , debug , loopBetween ( percentage , ...prepShapes ( a , b ) ) ) ;
111111} ;
112112
113113const testPrepShapesB = ( percentage : number ) => {
@@ -118,7 +118,7 @@ const testPrepShapesB = (percentage: number) => {
118118 point ( 0.6 , 0.4 , 0 , 0 , 0 , 0 ) ,
119119 point ( 0.45 , 0.4 , 0 , 0 , 0 , 0 ) ,
120120 ] ;
121- drawShape ( ctx , debug , interpolateBetweenLoop ( percentage , ...prepShapes ( a , b ) ) ) ;
121+ drawShape ( ctx , debug , loopBetween ( percentage , ...prepShapes ( a , b ) ) ) ;
122122} ;
123123
124124const testPrepShapesC = ( percentage : number ) => {
@@ -137,7 +137,7 @@ const testPrepShapesC = (percentage: number) => {
137137 point ( 0.45 , 0.5 , 0 , 0 , 0 , 0 ) ,
138138 point ( 0.5 , 0.5 , 0 , 0 , 0 , 0 ) ,
139139 ] ;
140- drawShape ( ctx , debug , interpolateBetweenLoop ( percentage , ...prepShapes ( b , a ) ) ) ;
140+ drawShape ( ctx , debug , loopBetween ( percentage , ...prepShapes ( b , a ) ) ) ;
141141} ;
142142
143143const testPrepShapesD = ( percentage : number ) => {
@@ -147,7 +147,26 @@ const testPrepShapesD = (percentage: number) => {
147147 point ( 0.525 , 0.725 , 0 , 0 , 0 , 0 ) ,
148148 point ( 0.525 , 0.725 , 0 , 0 , 0 , 0 ) ,
149149 ] ;
150- drawShape ( ctx , debug , interpolateBetweenLoop ( percentage , ...prepShapes ( a , b ) ) ) ;
150+ drawShape ( ctx , debug , loopBetween ( percentage , ...prepShapes ( a , b ) ) ) ;
151+ } ;
152+
153+ const testPrepLetters = ( percentage : number ) => {
154+ const a : Shape = [
155+ point ( 0.65 , 0.2 , 0 , 0 , 0 , 0 ) ,
156+ point ( 0.85 , 0.2 , 0 , 0 , 0 , 0 ) ,
157+ point ( 0.85 , 0.25 , 0 , 0 , 0 , 0 ) ,
158+ point ( 0.7 , 0.25 , 0 , 0 , 0 , 0 ) ,
159+ point ( 0.7 , 0.4 , 0 , 0 , 0 , 0 ) ,
160+ point ( 0.8 , 0.4 , 0 , 0 , 0 , 0 ) ,
161+ point ( 0.8 , 0.35 , 0 , 0 , 0 , 0 ) ,
162+ point ( 0.75 , 0.35 , 0 , 0 , 0 , 0 ) ,
163+ point ( 0.75 , 0.3 , 0 , 0 , 0 , 0 ) ,
164+ point ( 0.85 , 0.3 , 0 , 0 , 0 , 0 ) ,
165+ point ( 0.85 , 0.45 , 0 , 0 , 0 , 0 ) ,
166+ point ( 0.65 , 0.45 , 0 , 0 , 0 , 0 ) ,
167+ ] ;
168+ const b : Shape = blob ( "lettersa" , 8 , 0.25 , { x : 0.65 , y : 0.2 } ) ;
169+ drawShape ( ctx , debug , loopBetween ( percentage , ...prepShapes ( a , b ) ) ) ;
151170} ;
152171
153172const blob = ( seed : string , count : number , scale : number , offset : Coord ) : Shape => {
@@ -164,6 +183,14 @@ const blob = (seed: string, count: number, scale: number, offset: Coord): Shape
164183 } ) ;
165184} ;
166185
186+ const loopBetween = ( percentage : number , a : Shape , b : Shape ) : Shape => {
187+ if ( percentage < 0.5 ) {
188+ return interpolateBetweenSmooth ( 2 * percentage , a , b ) ;
189+ } else {
190+ return interpolateBetweenSmooth ( - 2 * percentage + 2 , a , b ) ;
191+ }
192+ } ;
193+
167194( ( ) => {
168195 let percentage = animationStart ;
169196
@@ -179,6 +206,7 @@ const blob = (seed: string, count: number, scale: number, offset: Coord): Shape
179206 testPrepShapesB ( percentage ) ;
180207 testPrepShapesC ( percentage ) ;
181208 testPrepShapesD ( percentage ) ;
209+ testPrepLetters ( percentage ) ;
182210
183211 percentage += animationSpeed / 1000 ;
184212 percentage = mod ( percentage , 1 ) ;
0 commit comments