47 lines
No EOL
1.2 KiB
TypeScript
47 lines
No EOL
1.2 KiB
TypeScript
import { Edge } from "./PElems/Edge";
|
|
import { Transition } from "./PElems/Transition";
|
|
import { Node } from "./PElems/Node";
|
|
import { svgNamespace } from "./types";
|
|
|
|
export let svg = document.querySelector("svg") as SVGSVGElement;
|
|
export let svgNodes = document.createElementNS(svgNamespace, 'g') as SVGSVGElement;
|
|
export let svgArrows = document.createElementNS(svgNamespace, 'g') as SVGSVGElement;
|
|
|
|
|
|
svg.appendChild(svgArrows);
|
|
svg.appendChild(svgNodes);
|
|
|
|
|
|
let transitions: Transition[] = [];
|
|
let nodes: Node[] = [];
|
|
|
|
function loop() {
|
|
for (const trans of transitions) {
|
|
console.log(trans.name, trans.fire());
|
|
}
|
|
update();
|
|
}
|
|
|
|
function update() {
|
|
for (const nod of nodes) {
|
|
nod.updatePoints();
|
|
}
|
|
for (const trans of transitions) {
|
|
trans.canFire();
|
|
}
|
|
}
|
|
|
|
window.onresize = () => {
|
|
svg.setAttribute("viewBox", `0 0 ${window.innerWidth} ${window.innerHeight}`);
|
|
}
|
|
window.onresize(null as any);
|
|
|
|
|
|
let n1 = new Node("n1", 100, 100);
|
|
let n2 = new Node("n2", 100, 300);
|
|
let t1 = new Transition("t1", 100, 200);
|
|
t1.inEdges.push(new Edge(n1, t1, true))
|
|
t1.outEdges.push(new Edge(n2, t1, false));
|
|
|
|
nodes.push(n1, n2);
|
|
transitions.push(t1); |