61 lines
No EOL
1.6 KiB
TypeScript
61 lines
No EOL
1.6 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) {
|
|
trans.canFire();
|
|
}
|
|
for (const trans of transitions) {
|
|
console.log(trans.name, trans.fire());
|
|
}
|
|
update();
|
|
}
|
|
|
|
export 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);
|
|
|
|
setInterval(loop, 1000);
|
|
|
|
let n1 = new Node("n1", 100, 100);
|
|
let n2 = new Node("n2", 100, 300);
|
|
let n3 = new Node("n3", 200, 200);
|
|
n1.capacity = 2;
|
|
n2.capacity = 2;
|
|
n3.capacity = 2;
|
|
let t1 = new Transition("t1", 100, 200);
|
|
let t2 = new Transition("t2", 150, 250);
|
|
let t3 = new Transition("t3", 150, 150);
|
|
t1.inEdges.push(new Edge(n1, t1, true))
|
|
t1.outEdges.push(new Edge(n2, t1, false));
|
|
t2.inEdges.push(new Edge(n2, t2, true))
|
|
t2.outEdges.push(new Edge(n3, t2, false));
|
|
t3.inEdges.push(new Edge(n3, t3, true))
|
|
t3.outEdges.push(new Edge(n1, t3, false));
|
|
|
|
nodes.push(n1, n2, n3);
|
|
transitions.push(t1, t2, t3); |