11import blobs from ".." ;
22
3- import { canvasClear , canvasSize , drawInfo , drawShape } from "./draw" ;
3+ import { clear , drawInfo , drawShape } from "./canvas /draw" ;
44import { interpolateBetweenLoop } from "./interpolate" ;
55import { approxCurveLength , divideShape , prepShapes , splitCurveAt , splitCurveBy } from "./prep" ;
66import { Coord , Point } from "./types" ;
@@ -10,6 +10,14 @@ const animationStart = 0.3;
1010const debug = true ;
1111const size = 1000 ;
1212
13+ const canvas = document . createElement ( "canvas" ) ;
14+ document . body . appendChild ( canvas ) ;
15+ canvas . height = size ;
16+ canvas . width = size ;
17+ const temp = canvas . getContext ( "2d" ) ;
18+ if ( temp === null ) throw new Error ( "context is null" ) ;
19+ const ctx = temp ;
20+
1321const rad = ( deg : number ) => {
1422 return ( deg / 360 ) * 2 * Math . PI ;
1523} ;
@@ -46,15 +54,16 @@ const testSplitAt = (percentage: number) => {
4654 const next = points [ ( i + 1 ) % points . length ] ;
4755 length += approxCurveLength ( curr , next ) ;
4856 }
49- drawInfo ( "split at lengths sum" , length ) ;
57+ drawInfo ( ctx , 1 , "split at lengths sum" , length ) ;
5058
51- drawShape ( debug , points ) ;
59+ drawShape ( ctx , debug , points ) ;
5260} ;
5361
5462const testSplitBy = ( ) => {
5563 const count = 10 ;
5664 for ( let i = 0 ; i < count ; i ++ ) {
5765 drawShape (
66+ ctx ,
5867 debug ,
5968 splitCurveBy (
6069 i + 1 ,
@@ -69,6 +78,7 @@ const testDivideShape = () => {
6978 const count = 10 ;
7079 for ( let i = 0 ; i < count ; i ++ ) {
7180 drawShape (
81+ ctx ,
7282 debug ,
7383 divideShape ( i + 3 , [
7484 point ( 0.3 , 0.2 + i * 0.05 , - 10 , 0.04 , - 45 , 0.02 ) ,
@@ -92,13 +102,13 @@ const testInterpolateBetween = (percentage: number) => {
92102 point ( 0.35 , 0.82 , 360 * 10 , 0 , 180 , 0 ) ,
93103 point ( 0.3 , 0.77 , 90 , 0 , - 90 , 0 ) ,
94104 ] ;
95- drawShape ( debug , interpolateBetweenLoop ( percentage , a , b ) ) ;
105+ drawShape ( ctx , debug , interpolateBetweenLoop ( percentage , a , b ) ) ;
96106} ;
97107
98108const testPrepShapesA = ( percentage : number ) => {
99109 const a = genBlob ( "a" , 0.6 , 0.6 , 0.3 , { x : 0.5 , y : 0.2 } ) ;
100110 const b = genBlob ( "b" , 1 , 0.6 , 0.3 , { x : 0.5 , y : 0.2 } ) ;
101- drawShape ( debug , interpolateBetweenLoop ( percentage , ...prepShapes ( a , b ) ) ) ;
111+ drawShape ( ctx , debug , interpolateBetweenLoop ( percentage , ...prepShapes ( a , b ) ) ) ;
102112} ;
103113
104114const testPrepShapesB = ( percentage : number ) => {
@@ -109,7 +119,7 @@ const testPrepShapesB = (percentage: number) => {
109119 point ( 0.75 , 0.7 , 0 , 0 , 0 , 0 ) ,
110120 point ( 0.55 , 0.7 , 0 , 0 , 0 , 0 ) ,
111121 ] ;
112- drawShape ( debug , interpolateBetweenLoop ( percentage , ...prepShapes ( a , b ) ) ) ;
122+ drawShape ( ctx , debug , interpolateBetweenLoop ( percentage , ...prepShapes ( a , b ) ) ) ;
113123} ;
114124
115125const genBlob = (
@@ -147,10 +157,9 @@ const genBlob = (
147157 let percentage = animationStart ;
148158
149159 const renderFrame = ( ) => {
150- canvasClear ( ) ;
151- canvasSize ( size , size ) ;
160+ clear ( ctx ) ;
152161
153- drawInfo ( "percentage" , percentage ) ;
162+ drawInfo ( ctx , 0 , "percentage" , percentage ) ;
154163 testSplitAt ( percentage ) ;
155164 testSplitBy ( ) ;
156165 testDivideShape ( ) ;
0 commit comments