From 964555a374e684738ed791e06a64c4fe0a1d4ea4 Mon Sep 17 00:00:00 2001 From: Nickoetje2 Date: Fri, 11 Nov 2022 17:36:38 +0100 Subject: [PATCH] updates --- gates/gate.js | 45 +++++++++++++++++++++++++++++++++++++++------ index.html | 6 ++++++ sketch.js | 2 ++ 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/gates/gate.js b/gates/gate.js index deb143c..7ac7578 100644 --- a/gates/gate.js +++ b/gates/gate.js @@ -1,10 +1,43 @@ class Gate { - constructor(type) { - switch (type) { - case 'logic': - break; - default: - break; + constructor(x, y, type) { + this.x = x; + this.y = y; + this.types = new Types(type); + this.selected = false; + + this.inputs = []; + this.outputs = []; + for(var i = 0; i < this.types.type.inputs; i++){ + //TODO calculate postions for ankors based on this.x and this.y + this.inputs.push(new Ankor(this.x - 10, this.y)); + } + for(var i = 0; i < this.types.type.outputs; i++){ + //TODO calculate postions for ankors based on this.x and this.y + this.outputs.push(new Ankor(this.x + 10, this.y)); } } + + draw() { + //todo draw gate and ankors and use type to resolve image + + } + + calculate() { + //todo calculate outputs based on inputs and function and add exception for light and switch if type.state + + } + + returnOnAnkor(x, y) { + this.inputs.forEach(ankor => { + if(x == ankor.x && y == ankor.y){ + return ankor; + } + }); + this.outputs.forEach(ankor => { + if(x == ankor.x && y == ankor.y){ + return ankor; + } + }); + return false; + } } \ No newline at end of file diff --git a/index.html b/index.html index 4a8f2b5..c64c0c8 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,11 @@ + + + + + + diff --git a/sketch.js b/sketch.js index 8aaddd1..e1bb7d4 100644 --- a/sketch.js +++ b/sketch.js @@ -14,6 +14,8 @@ function preload() { function setup() { createCanvas(displayWidth, displayHeight); + var gate = new Gate(1, 2, "light"); + console.log(gate) } function draw() {