Skip to content

Commit c9f756e

Browse files
committed
add parametric function plot functionality
1 parent f762132 commit c9f756e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1008
-277
lines changed

Cargo.lock

Lines changed: 54 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mathlikeanim-rs"
3-
version = "0.14.9"
3+
version = "0.14.12"
44
edition = "2021"
55
readme = "README.md"
66
description = "A Rust library for creating mathematical animations"
@@ -31,6 +31,7 @@ categories = ["mathematics", "graphics", "wasm"]
3131

3232
[dependencies]
3333
base64 = "0.22.1"
34+
exmex = "0.20.3"
3435
image = "0.25.5"
3536
typst = "0.13.0"
3637
typst-as-lib = "0.12.0"

docs/AnchorsAndHandles.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/Arc.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/BoundingBox.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/Circle.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/ClosedInterval.html

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

docs/Color.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/ColorStop.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/CubicBezierTuple.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/EquilateralTriangle.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/FontFace.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/ImageBitmap.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/ImageData.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/ImageLibrary.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/IntegerLerp.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/Line.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/LinearGradient.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/ParametricFunctionPlot.html

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

docs/Path2D.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/Point2D.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/RadialGradient.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/Rectangle.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/RightTriangle.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/Square.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/Style.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/TransformationMatrix.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/Triangle.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/Typst.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/VectorObject.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/VectorObjectBuilder.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/data/search.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/global.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/index.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/module.exports.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"@mathlikeanim-rs/renderer": "^0.14.11",
3+
"@mathlikeanim-rs/renderer": "^0.14.12",
44
"clean-jsdoc-theme": "^4.3.0",
55
"katex": "^0.16.21"
66
}

docs/pkg_index.js.html

Lines changed: 383 additions & 32 deletions
Large diffs are not rendered by default.

docs/tutorial-About text and formulas.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/tutorial-Get started.html

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

docs/tutorial-Initial tutorials.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/tutorial-Install the library.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/typescript_dist_canvas-scene.js.html

Lines changed: 13 additions & 13 deletions
Large diffs are not rendered by default.

docs/typescript_dist_scene.js.html

Lines changed: 20 additions & 11 deletions
Large diffs are not rendered by default.

docs/typescript_dist_svg-scene.js.html

Lines changed: 3 additions & 2 deletions
Large diffs are not rendered by default.

examples/hello-world/main.js

Lines changed: 22 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import init, { Color, Point2D, Style, VectorObjectBuilder, ImageLibrary, IntegerLerp, FontFace, Typst, Rectangle, BoundingBox, Circle, LinearGradient, ColorStop, VectorObject, RadialGradient, ImageBitmap, ImageData } from '@mathlikeanim-rs/mathlikeanim-rs'
2-
import { CanvasScene, SVGScene } from '@mathlikeanim-rs/renderer';
1+
import init, { Color, Point2D, Style, VectorObjectBuilder, ParametricFunctionPlot, ClosedInterval } from '@mathlikeanim-rs/mathlikeanim-rs'
2+
import { CanvasScene } from '@mathlikeanim-rs/renderer';
33

44
const scene = new CanvasScene(1920, 1080);
55
const renderButton = document.getElementById('render-button');
@@ -52,143 +52,32 @@ const run = async () => {
5252
canvasContainer.appendChild(canvas);
5353
canvasContainer.appendChild(svg);
5454
}
55-
scene.objects.forEach(obj => obj.free());
56-
scene.objects = [];
57-
// const obj = new Circle(
58-
// new Point2D(960, 540),
59-
// 500,
60-
// )
61-
// .vector_object_builder()
62-
// .set_fill(Style.from_color(new Color(255, 0, 0, 0.5)))
63-
// .set_stroke(Style.from_color(new Color(255, 0, 0, 1)))
64-
// .set_stroke_width(0.05)
65-
// .set_name('Circle')
66-
// .build();
67-
// scene.objects.push(new Rectangle(new BoundingBox(0, 0, 1920, 1080)).vector_object_builder.set_fill(Style.from_color(new Color(0, 0, 0, 1))).build());
68-
// scene.objects.push(obj);
69-
// const animations = new Map();
70-
// animations.set('Circle', (old, t) => {
71-
// if (t == 1) {
72-
// return new VectorObjectBuilder(old)
73-
// .set_fill(Style.from_color(new Color(255, 255, 0, 0.5)))
74-
// .set_stroke(Style.from_color(new Color(255, 255, 0, 1)))
75-
// .set_name('Circle')
76-
// .build();
77-
// }
78-
// const drawPathT = new IntegerLerp(0, 2, t);
79-
// return new VectorObjectBuilder(old)
80-
// .become_partial(0, drawPathT.index === 0 ? drawPathT.remainder : 1)
81-
// .fade_fill(drawPathT.index === 0 ? 1 : 1 - drawPathT.remainder)
82-
// .lerp_fill(Style.from_color(new Color(255, 255, 0, 0.5)), drawPathT.index === 0 ? 0 : drawPathT.remainder)
83-
// .lerp_stroke(Style.from_color(new Color(255, 255, 0, 1)), drawPathT.index === 0 ? 0 : drawPathT.remainder)
84-
// .set_name('Circle')
85-
// .build();
86-
// });
87-
// await scene.play(animations, 2000, t => t);
88-
// const animations2 = new Map();
89-
// animations2.set('Circle', (old, t) => {
90-
// return new VectorObjectBuilder(old)
91-
// .lerp_fill(Style.from_linear_gradient(new LinearGradient(
92-
// new Point2D(-1, -1),
93-
// new Point2D(1, 1),
94-
// [
95-
// new ColorStop(new Color(255, 0, 0, 0.5), 0),
96-
// new ColorStop(new Color(255, 255, 0, 0.5), 0.5),
97-
// new ColorStop(new Color(255, 0, 255, 0.5), 1)
98-
// ]
99-
// )), t)
100-
// .lerp_stroke(Style.from_linear_gradient(new LinearGradient(
101-
// new Point2D(-1, -1),
102-
// new Point2D(1, 1),
103-
// [
104-
// new ColorStop(new Color(255, 0, 0, 1), 0),
105-
// new ColorStop(new Color(255, 255, 0, 1), 0.5),
106-
// new ColorStop(new Color(255, 0, 255, 1), 1)
107-
// ]
108-
// )), t)
109-
// .set_name('Circle')
110-
// .build();
111-
// });
112-
// await scene.play(animations2, 2000, t => t);
113-
// // const animations3 = new Map();
114-
// // animations3.set('Circle', (old, t) => {
115-
// // console.log(t);
116-
// // return new VectorObjectBuilder(old)
117-
// // .lerp_fill(Style.from_radial_gradient(
118-
// // new RadialGradient(
119-
// // new Point2D(0, 0),
120-
// // new Point2D(0, 0),
121-
// // 1,
122-
// // [
123-
// // new ColorStop(new Color(255, 0, 0, 0.5), 0),
124-
// // new ColorStop(new Color(255, 255, 0, 0.5), 1)
125-
// // ]
126-
// // )), t, 100, 100)
127-
// // .lerp_stroke(
128-
// // Style.from_radial_gradient(
129-
// // new RadialGradient(
130-
// // new Point2D(960, 540),
131-
// // new Point2D(960, 540),
132-
// // 500,
133-
// // [
134-
// // new ColorStop(new Color(255, 0, 0, 1), 0),
135-
// // new ColorStop(new Color(255, 255, 0, 1), 1)
136-
// // ]
137-
// // )), t, 100, 100)
138-
// // .build();
139-
// // });
140-
// // await scene.play(animations3, 2000, t => t);
141-
// let c = new VectorObjectBuilder(scene.objects[1])
142-
// .set_fill(Style.from_image(ImageBitmap.fill_linear_gradient(
143-
// -2,
144-
// -2,
145-
// 4,
146-
// 4,
147-
// 300,
148-
// 300,
149-
// new LinearGradient(
150-
// new Point2D(-1, -1),
151-
// new Point2D(1, 1),
152-
// [
153-
// new ColorStop(new Color(255, 0, 0, 0.5), 0),
154-
// new ColorStop(new Color(255, 255, 0, 0.5), 0.5),
155-
// new ColorStop(new Color(255, 0, 255, 0.5), 1)
156-
// ]
157-
// )
158-
// )))
159-
// .set_stroke(Style.from_image(ImageBitmap.fill_linear_gradient(
160-
// -2,
161-
// -2,
162-
// 4,
163-
// 4,
164-
// 300,
165-
// 300,
166-
// new LinearGradient(
167-
// new Point2D(-1, -1),
168-
// new Point2D(1, 1),
169-
// [
170-
// new ColorStop(new Color(255, 0, 0, 1), 0),
171-
// new ColorStop(new Color(255, 255, 0, 1), 0.5),
172-
// new ColorStop(new Color(255, 0, 255, 1), 1)
173-
// ]
174-
// )
175-
// )))
176-
// .build();
177-
// scene.objects[1] = c;
178-
// scene.render();
179-
const imageLibrary = new ImageLibrary();
180-
const data = await fetch('mdn_logo_only_color.png').then(res => res.arrayBuffer()).then(buffer => new Uint8Array(buffer));
181-
imageLibrary.set('mdn_logo_only_color.png', new ImageData(data));
182-
const obj = text('Hello, World!', 960, 540, 100, 'Latin Modern Math', Style.from_color(new Color(0, 0, 0, 1)), [new FontFace(new Uint8Array(await fetch('latinmodern-math.otf').then(res => res.arrayBuffer())))]).set_name('Text').build();
55+
const obj = new ParametricFunctionPlot(
56+
't',
57+
'sin(t)',
58+
new ClosedInterval(-10, 10),
59+
new ClosedInterval(-10, 10),
60+
new ClosedInterval(-1, 1),
61+
).vector_object_builder
62+
.set_stroke(Style.from_color(new Color(255, 0, 0, 1)))
63+
.set_stroke_width(1)
64+
.set_name('ParametricFunctionPlot')
65+
.scale_to_width(1920)
66+
.move_to(new Point2D(960, 540))
67+
.build();
18368
scene.objects.push(obj);
18469
const animations = new Map();
185-
animations.set('Text', (old, t) => {
70+
animations.set('ParametricFunctionPlot', (old, t) => {
71+
if (t == 1) {
72+
return old;
73+
}
18674
return new VectorObjectBuilder(old)
187-
.lerp_fill(Style.from_color(new Color(255, 0, 0, 1)), t)
188-
.set_name('Text')
75+
.become_partial(0, t)
18976
.build();
19077
});
19178
await scene.play(animations, 2000, t => t);
79+
scene.objects.forEach(obj => obj.free());
80+
scene.objects = [];
19281
};
19382

19483
const onClick = async () => {

examples/hello-world/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dependencies": {
3-
"@mathlikeanim-rs/renderer": "^0.14.11"
3+
"@mathlikeanim-rs/renderer": "^0.14.12"
44
}
55
}

src/objects/geometry/arc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl Arc {
6969
.set_path(path)
7070
.scale(self.radius, self.radius, None, None)
7171
.shift(self.center.x, self.center.y, None)
72+
.actual_path_as_path(None, None)
7273
}
7374

7475
/// Returns the center point of the arc.

src/objects/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod vector_object;
22
pub mod geometry;
3-
pub mod typesetting;
3+
pub mod typesetting;
4+
pub mod plotting;

0 commit comments

Comments
 (0)