manim/bundle.js
2022-01-03 17:14:54 -06:00

112 lines
2.7 KiB
JavaScript

(() => {
// src/constants.ts
var PI = Math.PI;
var TAU = 2 * PI;
var DEFAULT_DOT_RADIUS = 0.08;
// src/mobject/geometry.ts
var Arc = class {
constructor(radius, startAngle, angle) {
this.radius = radius;
this.startAngle = startAngle;
this.angle = angle;
}
};
var Circle = class extends Arc {
constructor(radius) {
super(radius, 0, TAU);
}
};
var Dot = class extends Circle {
constructor(radius) {
super(radius != null ? radius : DEFAULT_DOT_RADIUS);
}
};
// src/renderer/index.ts
var Canvas2DRenderer = class {
constructor(context) {
this.context = context;
this.skipAnimations = false;
this.animationStartTime = new Date();
this.animationElapsedTime = 0;
}
init_scene(scene) {
}
render(scene) {
this.updateFrame(scene);
if (this.skipAnimations)
return;
for (let mobject of scene.mobjects) {
if (!mobject.shouldRender)
continue;
this.renderMobject(mobject);
}
}
renderMobject(mobject) {
}
updateFrame(scene) {
for (let mobject of scene.mobjects) {
if (!mobject.shouldRender)
continue;
this.renderMobject(mobject);
}
this.animationElapsedTime = +new Date() - +this.animationStartTime;
}
};
// src/scene/index.ts
var Scene = class {
constructor() {
this.animations = [];
this.mobjects = [];
}
construct() {
}
add(...mobjects) {
this.mobjects.push(...mobjects);
}
};
// src/utils/tex.ts
function texToSvg(expression) {
let el2 = MathJax.tex2svg(expression);
let child = el2.children[0];
return child.innerHTML;
}
// src/index.ts
function init(scene, el2) {
let canvasEl = document.createElement("canvas");
canvasEl.width = 640;
canvasEl.height = 480;
let contextOrNull = canvasEl.getContext("2d");
if (contextOrNull == null)
return;
let context = contextOrNull;
let renderer = new Canvas2DRenderer(context);
let lastTime;
let step = function(time) {
let timeDelta = time - (lastTime != null ? lastTime : 0);
renderer.render(scene);
requestAnimationFrame(step);
lastTime = time;
};
requestAnimationFrame(step);
el2.appendChild(canvasEl);
}
var ExampleScene = class extends Scene {
construct() {
let dot = new Dot([-2, -1, 0]);
let dot2 = new Dot([2, 1, 0]);
let line = new Line(dot.getCenter(), dot2.getCenter());
let b1 = new Brace(line);
this.add(line, dot, dot2);
}
};
texToSvg("x + 1");
var el = document.getElementById("manim");
if (el)
init(new ExampleScene(), el);
})();
//# sourceMappingURL=bundle.js.map