@@ -14,7 +14,7 @@ https://bryan.blog/vimath/
1414
1515``` npm install vimath --save ```
1616
17- ### Example usage
17+ ### Example usage (simple)
1818
1919``` ts
2020import { Scene , Square } from ' vimath' ;
@@ -36,7 +36,89 @@ new TestScene().render();
3636```
3737
3838#### Output
39- ![ example output] ( https://raw.githubusercontent.com/blparker/vimath/master/assets/screenshot.png )
39+ ![ example output] ( https://raw.githubusercontent.com/blparker/vimath/master/assets/example1.png )
40+
41+ ### Example
42+ Modeled after manim's logo.
43+
44+ ``` ts
45+ import { Scene , Tex , Circle , Square , Triangle , Group , LEFT , RIGHT , ORIGIN } from ' vimath' ;
46+
47+ class TestScene extends Scene {
48+ compose() {
49+ const v = new Tex ({ text: ' \\ mathbb{V}' , color: ' #343434' }).scale (7 );
50+ v .shift (LEFT (2.25 ), UP (1.5 ));
51+
52+ const circle = new Circle ({ color: ' #87c2a5' , lineColor: Colors .transparent () }).shift (LEFT ());
53+ const square = new Square ({ color: ' #525893' , lineColor: Colors .transparent () }).shift (UP ());
54+ const triangle = new Triangle ({ color: ' #e07a5f' , lineColor: Colors .transparent () }).shift (RIGHT ());
55+
56+ const logo = new Group (triangle , square , circle , v );
57+ logo .moveTo (ORIGIN );
58+ this .add (logo );
59+ }
60+ }
61+
62+ new TestScene ().render ();
63+ ```
64+
65+ #### Output
66+ ![ example 2 output] ( https://raw.githubusercontent.com/blparker/vimath/master/assets/example2.png )
67+
68+ ### Example (with animation)
69+
70+ ``` ts
71+ import { Scene , Tex , Circle , Square , Triangle , Group , LEFT , RIGHT , ORIGIN } from ' vimath' ;
72+
73+ class TestScene extends Scene {
74+ compose() {
75+ const axes = new Axes ({
76+ xLength: 10 ,
77+ yLength: 6 ,
78+ xRange: [0 , 1 ],
79+ xStep: 0.25 ,
80+ yRange: [0 , 50 ],
81+ yStep: 5 ,
82+ xLabel: ' time (h)' ,
83+ yLabel: ' distance (miles)'
84+ });
85+
86+ const fn = x => 25 * x * x ;
87+ const p = axes .plot (fn ).changeLineColor (Colors .green ());
88+
89+ this .add (axes , p );
90+
91+ const p1 = axes .point (0.25 , fn (0.25 ));
92+ const p2 = axes .point (0.5 , fn (0.5 ));
93+ const p3 = axes .point (0.75 , fn (0.75 ));
94+ const p4 = axes .point (1 , fn (1 ));
95+
96+ const tangent = new TangentLine ({ plot: p , x: 0.5 , color: Colors .pink (), length: 8 });
97+ const centerPoint = new Dot ({ center: p2 , color: Colors .pink () });
98+
99+ this .add (
100+ tangent ,
101+ new Dot ({ center: p1 , color: Colors .green () }),
102+ centerPoint ,
103+ new Dot ({ center: p3 , color: Colors .green () }),
104+ new Dot ({ center: p4 , color: Colors .green () }),
105+ );
106+
107+ this .add (new Updater ((pctComplete : number , starting : boolean ) => {
108+ const x = math .lerp (0 , 0.99 , pctComplete );
109+ centerPoint .moveTo (p .pointAtX (x ));
110+ tangent .updateX (x );
111+ }, { duration: 3000 , easing: Easing .easeInOutCubic , repeat: true , yoyo: true , }));
112+ }
113+ }
114+
115+ new TestScene ().render ();
116+ ```
117+
118+ #### Output
119+ ![ example 3 output] ( https://raw.githubusercontent.com/blparker/vimath/master/assets/example3.gif )
120+
121+
40122
41123## Playground
42124
0 commit comments