Skip to content

Commit 97b80db

Browse files
committed
fix CanvasScene not rendering when offscreen and add CartesianAxes
1 parent c9f756e commit 97b80db

Some content is hidden

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

64 files changed

+1624
-271
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mathlikeanim-rs"
3-
version = "0.14.12"
3+
version = "0.14.13"
44
edition = "2021"
55
readme = "README.md"
66
description = "A Rust library for creating mathematical animations"

README.md

Lines changed: 9 additions & 10 deletions

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/Axis.html

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

docs/BoundingBox.html

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

docs/CartesianAxes.html

Lines changed: 3 additions & 0 deletions
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: 1 addition & 1 deletion
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: 1 addition & 1 deletion
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/Tick.html

Lines changed: 3 additions & 0 deletions
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: 10 additions & 4 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.12",
3+
"@mathlikeanim-rs/renderer": "^0.14.13",
44
"clean-jsdoc-theme": "^4.3.0",
55
"katex": "^0.16.21"
66
}

docs/pkg_index.js.html

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

docs/tutorial-About text and formulas.html

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

docs/tutorial-Get started.html

Lines changed: 11 additions & 6 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: 4 additions & 3 deletions
Large diffs are not rendered by default.

docs/typescript_dist_canvas-scene.js.html

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

docs/typescript_dist_scene.js.html

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

docs/typescript_dist_svg-scene.js.html

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

examples/hello-world/main.js

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
import init, { Color, Point2D, Style, VectorObjectBuilder, ParametricFunctionPlot, ClosedInterval } from '@mathlikeanim-rs/mathlikeanim-rs'
1+
import init, { Color, Point2D, Style, VectorObjectBuilder, Tick, Typst, FontFace, ClosedInterval, CartesianAxes } from '@mathlikeanim-rs/mathlikeanim-rs'
22
import { CanvasScene } from '@mathlikeanim-rs/renderer';
33

4-
const scene = new CanvasScene(1920, 1080);
4+
const scene = new CanvasScene(1920, 1080, '/node_modules/@mathlikeanim-rs/renderer/dist/offscreen-canvas-worker.js');
55
const renderButton = document.getElementById('render-button');
66
const stopRecordingButton = document.getElementById('stop-recording-button');
77
let firstTime = true;
88
let recorder;
99
let chunks = [];
1010
let stream;
11+
let data;
1112
const stopRecording = () => {
1213
recorder.stop();
1314
stopRecordingButton.removeEventListener('click', stopRecording);
1415
}
1516

16-
function text(text, x, y, font_size, font_family, fill_style, font_faces) {
17-
return VectorObjectBuilder.from_svg(`<svg xmlns="http://www.w3.org/2000/svg">
18-
<text x="${x}" y="${y}" font-size="${font_size}" font-family="${font_family}">${text}</text>
19-
</svg>`, font_faces)
20-
.set_fill(fill_style)
21-
}
22-
2317
const run = async () => {
2418
if (firstTime) {
2519
firstTime = false;
@@ -51,23 +45,51 @@ const run = async () => {
5145
svg.style.height = 'auto';
5246
canvasContainer.appendChild(canvas);
5347
canvasContainer.appendChild(svg);
48+
data = new Uint8Array(await fetch('/latinmodern-math.otf').then(response => response.arrayBuffer()));
5449
}
55-
const obj = new ParametricFunctionPlot(
50+
const axes = new CartesianAxes(
51+
new ClosedInterval(0, 10),
52+
new ClosedInterval(0, 10),
53+
new Point2D(960 - 400, 540 + 400),
54+
new Point2D(960 + 400, 540 - 400),
55+
Style.from_color(new Color(0, 0, 0, 1)),
56+
5,
57+
new Typst(`#show math.equation: set text(font: "Latin Modern Math")
58+
#set page(fill: none)
59+
$ x $`).vector_object_builder([new FontFace(data)]).scale(5, 5),
60+
new Typst(`#show math.equation: set text(font: "Latin Modern Math")
61+
#set page(fill: none)
62+
$ y $`).vector_object_builder([new FontFace(data)]).scale(5, 5),
63+
[new Tick(5, new Typst(`#show math.equation: set text(font: "Latin Modern Math")
64+
#set page(fill: none)
65+
$ 5 $`).vector_object_builder([new FontFace(data)]).scale(2.5, 2.5))]
66+
);
67+
const obj = axes.with_tips_at_ends(VectorObjectBuilder.default_tip_shape(50)).set_name('Axes').build();
68+
scene.objects.push(obj);
69+
const animations = new Map();
70+
const plot = axes.plot_function(
5671
't',
57-
'sin(t)',
58-
new ClosedInterval(-10, 10),
59-
new ClosedInterval(-10, 10),
60-
new ClosedInterval(-1, 1),
61-
).vector_object_builder
72+
't^2 / 10',
73+
new ClosedInterval(0, 10),
74+
new ClosedInterval(0, 10),
75+
new ClosedInterval(0, 10),
76+
);
77+
const obj2 = plot.vector_object_builder
6278
.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))
79+
.set_stroke_width(5)
80+
.set_name('Plot')
6781
.build();
68-
scene.objects.push(obj);
69-
const animations = new Map();
70-
animations.set('ParametricFunctionPlot', (old, t) => {
82+
console.log(obj2.path);
83+
scene.objects.push(obj2);
84+
animations.set('Axes', (old, t) => {
85+
if (t == 1) {
86+
return old;
87+
}
88+
return new VectorObjectBuilder(old)
89+
.become_partial(0, t)
90+
.build();
91+
});
92+
animations.set('Plot', (old, t) => {
7193
if (t == 1) {
7294
return old;
7395
}

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.12"
3+
"@mathlikeanim-rs/renderer": "^0.14.13"
44
}
55
}

0 commit comments

Comments
 (0)