From e4767d300dd23ed011aa25403f924d7bfe5cb30c Mon Sep 17 00:00:00 2001 From: phil jones Date: Sat, 30 Jan 2021 02:39:00 -0300 Subject: [PATCH] crappy tool for creating network diagrams, ignore this for the moment --- resources/clj_ts/ss.html | 29 ++++++ resources/clj_ts/ss.js | 196 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 resources/clj_ts/ss.html create mode 100644 resources/clj_ts/ss.js diff --git a/resources/clj_ts/ss.html b/resources/clj_ts/ss.html new file mode 100644 index 0000000..c1a5c94 --- /dev/null +++ b/resources/clj_ts/ss.html @@ -0,0 +1,29 @@ + + + + + + + p5.js example + + + + + + + +

Visual Structure Editor

+
+
+
+  
+
+
+ + + diff --git a/resources/clj_ts/ss.js b/resources/clj_ts/ss.js new file mode 100644 index 0000000..d7f8e8a --- /dev/null +++ b/resources/clj_ts/ss.js @@ -0,0 +1,196 @@ +class Node { + + constructor(eyed, ex, wy) { + this.id = eyed; + this.x = ex; + this.y = wy; + this.name = "" + this.id; + } + + draw() { + fill(124); + stroke(30); + + ellipse(this.x, this.y, 50, 35); + fill(0); + textAlign(CENTER, CENTER); + text(""+this.id, this.x, this.y); + } + + hit(nx, ny) { + if ((createVector(this.x,this.y)).dist(createVector(nx, ny)) < 50) { + return true; + } + return false; + } + + moveTo(ex, wy) { + this.x = ex; + this.y = wy; + } +} + +class Arc { + constructor(en1, en2) { + this.n1 = en1; + this.n2 = en2; + } + + draw() { + line(this.n1.x, this.n1.y, this.n2.x, this.n2.y); + } +} + +class Network { + + constructor() { + this.nodes = []; + this.arcs = []; + this.nid = 0; + this.aid = 0; + this.selectedNode = -1; + } + + addNode(ex, wy) { + var n = new Node(this.nid, ex, wy); + this.nodes.push(n); + this.nid++; + } + + hitOne(ex, wy) { + for (var i=0;i -1) { + // we'd already selected something + try { + var hid = network.hitOne(mouseX, mouseY); + if (hid < 0) { + // we haven't hit anything else, so we move + network.getNodeById(network.selectedNode).moveTo(mouseX, mouseY); + } else { + // we did hit something else so we add an arc + network.arcs.push(new Arc(network.getNodeById(network.selectedNode), + network.getNodeById(hid))); + } + } + catch (e) { + console.log("WTF??? " + e); + } + } else { + // we hadn't already selected something, so we create a new node + network.addNode(mouseX, mouseY); + } + network.selectedNode = -1; + + var edn = network.scaledTo(600,500).toEDN(); + console.log(edn); + document.getElementById("edn_text").innerHTML=edn; +} + +