PNet/js/index.ts

58 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-06-22 17:47:04 +02:00
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[] = [];
2023-06-28 16:06:31 +02:00
function loop() {
2023-06-27 09:19:06 +02:00
for (const trans of transitions) {
trans.canFire();
}
2023-06-22 17:47:04 +02:00
for (const trans of transitions) {
console.log(trans.name, trans.fire());
}
update();
}
2023-06-27 09:19:06 +02:00
export function update() {
2023-06-22 17:47:04 +02:00
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);
2023-06-27 09:19:06 +02:00
setInterval(loop, 1000);
2023-06-22 17:47:04 +02:00
let n1 = new Node("n1", 100, 100);
let n2 = new Node("n2", 100, 300);
2023-06-27 09:19:06 +02:00
let n3 = new Node("n3", 200, 200);
2023-06-22 17:47:04 +02:00
let t1 = new Transition("t1", 100, 200);
2023-06-27 09:19:06 +02:00
let t2 = new Transition("t2", 150, 250);
let t3 = new Transition("t3", 150, 150);
2023-06-22 17:47:04 +02:00
t1.inEdges.push(new Edge(n1, t1, true))
t1.outEdges.push(new Edge(n2, t1, false));
2023-06-27 09:19:06 +02:00
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));
2023-06-22 17:47:04 +02:00
2023-06-27 09:19:06 +02:00
nodes.push(n1, n2, n3);
transitions.push(t1, t2, t3);