11import { interpolateBetweenSmooth } from "../interpolate" ;
2- import { divideShape , prepShapes } from "../prepare" ;
3- import { Coord , Point , Shape } from "../../types" ;
4- import { length , insertAt , insertCount , rad , mod , mapShape , forShape , smooth } from "../../util" ;
5- import { clear , drawInfo , drawShape } from "../../render/canvas" ;
2+ import { divide , prepare } from "../prepare" ;
3+ import { Coord , Point } from "../../types" ;
4+ import { length , insertAt , insertCount , rad , mod , mapPoints , forPoints } from "../../util" ;
5+ import { clear , drawInfo , drawClosed } from "../../render/canvas" ;
66import { genBlob } from "../../blobs" ;
77import { rand } from "../../rand" ;
88
@@ -33,35 +33,35 @@ const point = (x: number, y: number, ia: number, il: number, oa: number, ol: num
3333} ;
3434
3535const testSplitAt = ( percentage : number ) => {
36- let shape : Shape = [
36+ let points : Point [ ] = [
3737 point ( 0.15 , 0.15 , 135 , 0.1 , 315 , 0.2 ) ,
3838 point ( 0.85 , 0.15 , 225 , 0.1 , 45 , 0.2 ) ,
3939 point ( 0.85 , 0.85 , 315 , 0.1 , 135 , 0.2 ) ,
4040 point ( 0.15 , 0.85 , 45 , 0.1 , 225 , 0.2 ) ,
4141 ] ;
4242
43- const count = shape . length ;
43+ const count = points . length ;
4444 const stop = 2 * count - 1 ;
4545 for ( let i = 0 ; i < count ; i ++ ) {
4646 const double = i * 2 ;
4747 const next = mod ( double + 1 , stop ) ;
48- shape . splice ( double , 2 , ...insertAt ( percentage , shape [ double ] , shape [ next ] ) ) ;
48+ points . splice ( double , 2 , ...insertAt ( percentage , points [ double ] , points [ next ] ) ) ;
4949 }
50- shape . splice ( 0 , 1 ) ;
50+ points . splice ( 0 , 1 ) ;
5151
5252 let sum = 0 ;
53- forShape ( shape , ( { curr, next} ) => {
53+ forPoints ( points , ( { curr, next} ) => {
5454 sum += length ( curr , next ( ) ) ;
5555 } ) ;
5656 drawInfo ( ctx , 1 , "split at lengths sum" , sum ) ;
5757
58- drawShape ( ctx , debug , shape ) ;
58+ drawClosed ( ctx , debug , points ) ;
5959} ;
6060
6161const testSplitBy = ( ) => {
6262 const count = 10 ;
6363 for ( let i = 0 ; i < count ; i ++ ) {
64- drawShape (
64+ drawClosed (
6565 ctx ,
6666 debug ,
6767 insertCount (
@@ -73,13 +73,13 @@ const testSplitBy = () => {
7373 }
7474} ;
7575
76- const testDivideShape = ( ) => {
76+ const testDividePoints = ( ) => {
7777 const count = 10 ;
7878 for ( let i = 0 ; i < count ; i ++ ) {
79- drawShape (
79+ drawClosed (
8080 ctx ,
8181 debug ,
82- divideShape ( i + 3 , [
82+ divide ( i + 3 , [
8383 point ( 0.3 , 0.2 + i * 0.05 , - 10 , 0.04 , - 45 , 0.02 ) ,
8484 point ( 0.35 , 0.2 + i * 0.05 - 0.02 , 180 , 0.02 , 0 , 0.02 ) ,
8585 point ( 0.4 , 0.2 + i * 0.05 , - 135 , 0.02 , 170 , 0.04 ) ,
@@ -101,29 +101,29 @@ 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 , loopBetween ( percentage , a , b ) ) ;
104+ drawClosed ( ctx , debug , loopBetween ( percentage , a , b ) ) ;
105105} ;
106106
107- const testPrepShapesA = ( percentage : number ) => {
107+ const testPrepPointsA = ( 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 , loopBetween ( percentage , ...prepShapes ( a , b ) ) ) ;
110+ drawClosed ( ctx , debug , loopBetween ( percentage , ...prepare ( a , b ) ) ) ;
111111} ;
112112
113- const testPrepShapesB = ( percentage : number ) => {
113+ const testPrepPointsB = ( percentage : number ) => {
114114 const a = blob ( "a" , 8 , 0.15 , { x : 0.45 , y : 0.25 } ) ;
115- const b : Shape = [
115+ const b : Point [ ] = [
116116 point ( 0.45 , 0.25 , 0 , 0 , 0 , 0 ) ,
117117 point ( 0.6 , 0.25 , 0 , 0 , 0 , 0 ) ,
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 , loopBetween ( percentage , ...prepShapes ( a , b ) ) ) ;
121+ drawClosed ( ctx , debug , loopBetween ( percentage , ...prepare ( a , b ) ) ) ;
122122} ;
123123
124- const testPrepShapesC = ( percentage : number ) => {
124+ const testPrepPointsC = ( percentage : number ) => {
125125 const a = blob ( "c" , 8 , 0.15 , { x : 0.45 , y : 0.45 } ) ;
126- const b : Shape = [
126+ const b : Point [ ] = [
127127 point ( 0.5 , 0.45 , 0 , 0 , 0 , 0 ) ,
128128 point ( 0.55 , 0.45 , 0 , 0 , 0 , 0 ) ,
129129 point ( 0.55 , 0.5 , 0 , 0 , 0 , 0 ) ,
@@ -137,21 +137,21 @@ 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 , loopBetween ( percentage , ...prepShapes ( b , a ) ) ) ;
140+ drawClosed ( ctx , debug , loopBetween ( percentage , ...prepare ( b , a ) ) ) ;
141141} ;
142142
143- const testPrepShapesD = ( percentage : number ) => {
143+ const testPrepPointsD = ( percentage : number ) => {
144144 const a = blob ( "d" , 8 , 0.15 , { x : 0.45 , y : 0.65 } ) ;
145- const b : Shape = [
145+ const b : Point [ ] = [
146146 point ( 0.525 , 0.725 , 0 , 0 , 0 , 0 ) ,
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 , loopBetween ( percentage , ...prepShapes ( a , b ) ) ) ;
150+ drawClosed ( ctx , debug , loopBetween ( percentage , ...prepare ( a , b ) ) ) ;
151151} ;
152152
153153const testPrepLetters = ( percentage : number ) => {
154- const a : Shape = [
154+ const a : Point [ ] = [
155155 point ( 0.65 , 0.2 , 0 , 0 , 0 , 0 ) ,
156156 point ( 0.85 , 0.2 , 0 , 0 , 0 , 0 ) ,
157157 point ( 0.85 , 0.25 , 0 , 0 , 0 , 0 ) ,
@@ -165,14 +165,14 @@ const testPrepLetters = (percentage: number) => {
165165 point ( 0.85 , 0.45 , 0 , 0 , 0 , 0 ) ,
166166 point ( 0.65 , 0.45 , 0 , 0 , 0 , 0 ) ,
167167 ] ;
168- const b : Shape = blob ( "lettersa " , 8 , 0.25 , { x : 0.65 , y : 0.2 } ) ;
169- drawShape ( ctx , debug , loopBetween ( percentage , ...prepShapes ( a , b ) ) ) ;
168+ const b : Point [ ] = blob ( "" , 8 , 0.25 , { x : 0.65 , y : 0.2 } ) ;
169+ drawClosed ( ctx , debug , loopBetween ( percentage , ...prepare ( a , b ) ) ) ;
170170} ;
171171
172- const blob = ( seed : string , count : number , scale : number , offset : Coord ) : Shape => {
172+ const blob = ( seed : string , count : number , scale : number , offset : Coord ) : Point [ ] => {
173173 const rgen = rand ( seed ) ;
174- const shape = genBlob ( count , ( ) => 0.3 + 0.2 * rgen ( ) ) ;
175- return mapShape ( shape , ( { curr} ) => {
174+ const points = genBlob ( count , ( ) => 0.3 + 0.2 * rgen ( ) ) ;
175+ return mapPoints ( points , ( { curr} ) => {
176176 curr . x *= scale * size ;
177177 curr . y *= scale * size ;
178178 curr . x += offset . x * size ;
@@ -183,7 +183,7 @@ const blob = (seed: string, count: number, scale: number, offset: Coord): Shape
183183 } ) ;
184184} ;
185185
186- const loopBetween = ( percentage : number , a : Shape , b : Shape ) : Shape => {
186+ const loopBetween = ( percentage : number , a : Point [ ] , b : Point [ ] ) : Point [ ] => {
187187 if ( percentage < 0.5 ) {
188188 return interpolateBetweenSmooth ( 1 , 2 * percentage , a , b ) ;
189189 } else {
@@ -200,12 +200,12 @@ const loopBetween = (percentage: number, a: Shape, b: Shape): Shape => {
200200 drawInfo ( ctx , 0 , "percentage" , percentage ) ;
201201 testSplitAt ( percentage ) ;
202202 testSplitBy ( ) ;
203- testDivideShape ( ) ;
203+ testDividePoints ( ) ;
204204 testInterpolateBetween ( percentage ) ;
205- testPrepShapesA ( percentage ) ;
206- testPrepShapesB ( percentage ) ;
207- testPrepShapesC ( percentage ) ;
208- testPrepShapesD ( percentage ) ;
205+ testPrepPointsA ( percentage ) ;
206+ testPrepPointsB ( percentage ) ;
207+ testPrepPointsC ( percentage ) ;
208+ testPrepPointsD ( percentage ) ;
209209 testPrepLetters ( percentage ) ;
210210
211211 percentage += animationSpeed / 1000 ;
0 commit comments