소개
Math2D 인스턴스 생성하기
Math2D 모듈을 로드한 뒤 new mathcore.math2d.Math2D()
로 math2d
인스턴스를 생성합니다.
await mathcore.helper.load("math2d", { key: "TESTKEY" });
const math2d = new mathcore.math2d.Math2D();
Math2D 렌더링하기
렌더링 타겟인 Root Element를 지정하고 render
메소드를 이용하여 렌더링합니다.
주의
Root Element의 크기와 위치에 맞춰서 캔버스가 렌더링됩니다.
따라서 Root Element의 css position 속성은 relative
, absolute
, fixed
, sticky
중 하나여야 하며, 가로와 세로의 크기가 0보다 커야 합니다.
- Javascript
- HTML
const root = document.getElementById("root");
math2d.render(root);
<div
id="root"
style="position: relative; height: 300px;"
></div>
렌더링이 성공하면 다음과 같은 화면이 생성됩니다.
팁
HTMLElement 또는 HTMLElement의 id를 이용해서 렌더링 할 수 있습니다.
math2d.render("root");