From 75a9f0d763bf46006a8c5bc52115d6d51b510f7b Mon Sep 17 00:00:00 2001 From: Marius Van Nieuwenhuyse Date: Mon, 25 Feb 2019 17:59:54 +0100 Subject: [PATCH] Adding NAND,NOT and XNOR gates --- app/css/toolbar.css | 6 +++--- app/index.html | 3 +++ app/js/components.js | 47 ++++++++++++++++++++++++++++++++++++++++- app/js/localStorage2.js | 2 +- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/app/css/toolbar.css b/app/css/toolbar.css index 1eaa0ed5..b638ea03 100644 --- a/app/css/toolbar.css +++ b/app/css/toolbar.css @@ -2,8 +2,8 @@ position: fixed; left: 50%; bottom: 0; - margin-left: -175px; - width: 350px; + margin-left: -250px; + width: 500px; height: 50px; background: #111; color: #555; @@ -156,4 +156,4 @@ #toolbar #list li:hover, #toolbar #list li:active { background: #ddd; -} \ No newline at end of file +} diff --git a/app/index.html b/app/index.html index 4872408a..58ac761b 100755 --- a/app/index.html +++ b/app/index.html @@ -228,8 +228,11 @@

Tutorial

I/O
!
&
+
!&
|
+
!|
^
+
!^
memory
list
diff --git a/app/js/components.js b/app/js/components.js index 87fdd8c9..046941dd 100644 --- a/app/js/components.js +++ b/app/js/components.js @@ -1138,7 +1138,7 @@ function findComponentsInSelection( for(let i = 0; i < components.length; ++i) { const component = components[i]; if(x < component.pos.x + (component.width || 0) - .5 && - x2 > component.pos.x - .5 && + x2 > component.pos.x - .5 && y2 > component.pos.y - (component.height || 0) + .5 && y < component.pos.y +.5) { result.push(component); @@ -1985,6 +1985,21 @@ class AND extends Component { } } +class NAND extends Component { + constructor(name, pos) { + super (name, pos, 2, 2, {type: "char", text: "!&"}); + this.addInputPort({side: 3, pos: 1}); + this.addInputPort({side: 3, pos: 0}); + this.addOutputPort({side: 1, pos: 0}); + this.function = () => { + if (this.input[0].value & this.input[1].value == 1) + this.output[0].value = 0; + else + this.output[0].value = 1; + } + } +} + class OR extends Component { constructor(name,pos) { super(name,pos,2,2,{ type: "char", text: "|" }); @@ -1997,6 +2012,21 @@ class OR extends Component { } } +class NOR extends Component { + constructor(name,pos) { + super(name,pos,2,2,{ type: "char", text: "!|" }); + this.addInputPort({ side: 3, pos: 1 }); + this.addInputPort({ side: 3, pos: 0 }); + this.addOutputPort({ side: 1, pos: 0 }); + this.function = function() { + if (this.input[0].value | this.input[1].value) + this.output[0].value = 0; + else + this.output[0].value = 1; + } + } +} + class XOR extends Component { constructor(name,pos) { super(name,pos,2,2,{ type: "char", text: "^" }); @@ -2009,6 +2039,21 @@ class XOR extends Component { } } +class XNOR extends Component { + constructor(name,pos) { + super(name,pos,2,2,{ type: "char", text: "!^" }); + this.addInputPort({ side: 3, pos: 1 }); + this.addInputPort({ side: 3, pos: 0 }); + this.addOutputPort({ side: 1, pos: 0 }); + this.function = function() { + if (this.input[0].value ^ this.input[1].value) + this.output[0].value = 0; + else + this.output[0].value = 1; + } + } +} + class Button extends Component { constructor(name,pos) { super(name,pos,2,1,{ type: "icon", text: "radio_button_checked" }); diff --git a/app/js/localStorage2.js b/app/js/localStorage2.js index d3f4550c..b590e34f 100644 --- a/app/js/localStorage2.js +++ b/app/js/localStorage2.js @@ -94,7 +94,7 @@ function getLocalStorage() { } const constructors = { - Input,Output,NOT,AND,OR,XOR, + Input,Output,NOT,AND,NAND,OR,NOT,XOR,XNOR, Button,Constant,Delay,Clock,Debug, Beep,Counter,LED,Display, Custom, TimerStart, TimerEnd,