0.2.1: Fixed input property constraints and added NOT gate

This commit is contained in:
MatCat 2021-02-21 02:21:27 -08:00
parent 0a38839418
commit 9db98c30a5
4 changed files with 40 additions and 2 deletions

View File

@ -12,6 +12,10 @@ To be decided, but at this moment this code is open source and free to use for n
## Changelog
### 0.2.1
* Fixed input property constraints on elements
* Added NOT gate
### 0.2.0
* Switched to a dark theme
* Added left hand toolbar

View File

@ -36,6 +36,7 @@
<input type="button" id="btn_AddNOR" value="!| NOR"/><br />
<input type="button" id="btn_AddXOR" value="^ XOR"/><br />
<input type="button" id="btn_AddXNOR" value="!^ XNOR"/><br />
<input type="button" id="btn_AddNOT" value="! NOT"/><br />
<input type="button" id="btn_AddSWITCH" value="|- SWITCH"/><br />
<input type="button" id="btn_AddCLK" value="🕑 Clock"/><br />
<input type="button" id="btn_Delete" value="🗑 Delete"/>

View File

@ -205,7 +205,7 @@ class Element extends CanvasTools {
this.Properties = new Array();
this.LogicEngine = logicengine;
let inputProperty = new ElementProperty("Inputs","int",{CBObject: this,CBFunction: "ChangeInputs"},2,Inputs);
let inputProperty = new ElementProperty("Inputs","int",{CBObject: this,CBFunction: "ChangeInputs"},2,Inputs,false,2);
this.Properties.push(inputProperty);
}
@ -454,6 +454,7 @@ class inputElement extends Element {
this.Name = "InputElement";
this.Output = false;
this.Width = 100;
this.removeProperty("Inputs");
}
getOutput() {
@ -579,6 +580,7 @@ class LogicXOR extends Element {
constructor(logicengine) {
super(logicengine,2); // Only 2 inputs on XOR
this.Name = "XOR";
this.removeProperty("Inputs");
}
getOutput() {
@ -602,6 +604,7 @@ class LogicXNOR extends Element {
constructor(logicengine) {
super(logicengine,2); // Only 2 inputs on XOR
this.Name = "XNOR";
this.removeProperty("Inputs");
}
getOutput() {
@ -621,6 +624,29 @@ class LogicXNOR extends Element {
}
}
class LogicNOT extends Element {
constructor(logicengine) {
super(logicengine,1); // Only 1 inputs on NOT
this.Name = "NOT";
this.removeProperty("Inputs");
}
getOutput() {
if (this.Inputs[0]) return false;
return true;
}
drawElement(x,y,ctx) {
let drawWidth = this.Width;
let drawHeight = this.Height;
this.drawBorderBox(ctx, x,y,drawWidth,drawHeight);
this.drawTextCentered(ctx,x,y,drawWidth,drawHeight,"|>🞄");
this.drawInputs(ctx,x,y);
this.drawOutputs(ctx,x,y);
}
}
class elementContainer {
constructor() {

View File

@ -2,7 +2,7 @@
MatCat BrowserLogic Simulator
*/
let Version = "0.2.0";
let Version = "0.2.1";
let spanVersion = document.getElementById("version");
spanVersion.innerText = Version;
// get the canvas and get the engine object going
@ -91,6 +91,13 @@ btn_AddXNOR.addEventListener('click', function(evt) {
logicEngine.ActiveContainer.AddElement(newXNOR);
}, false);
btn_AddNOT.addEventListener('click', function(evt) {
let newNOT = new LogicNOT(logicEngine);
newNOT.X = 20;
newNOT.Y = 20;
logicEngine.ActiveContainer.AddElement(newNOT);
}, false);
let btn_AddSWITCH = document.getElementById("btn_AddSWITCH");
btn_AddSWITCH.addEventListener('click', function(evt) {
let newSWITCH = new InputSwitch(logicEngine);