Skip to content

Commit

Permalink
Added ground circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
r-arvind committed Oct 4, 2018
1 parent 9f42433 commit 77527fd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1>Opamp Designer</h1>
<div class="content">

<div class="box">
<h2>Try it Out <h4>(Works, but not completely)</h4></h2>
<h2>Try it Out</h2>
<p>Write the coefficients of all the terms in the equation with a space</p>
<div>
<input type="text" id="input">
Expand Down
2 changes: 1 addition & 1 deletion js/execute.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function generateCircuit(){
circuit.init(ctx);
circuit.drawOpamp(ctx, 36, 24);
circuit.drawOpamp(ctx, 39, 24);
circuit.drawGridX(ctx);
circuit.drawGridY(ctx);
circuit.evaluateInput(localStorage.getItem("query"));
Expand Down
80 changes: 71 additions & 9 deletions js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ var circuit = {
nodes["Vout"] = {x: x+4,y: y};
nodes["Vplus"] = {x: x,y: y+2};
nodes["Vminus"] = {x: x,y: y-2};
fillText(ctx,"+",nodes.Vplus.x + 0.2,nodes.Vplus.y+0.4);
fillText(ctx,"-",nodes.Vminus.x + 0.3,nodes.Vminus.y+0.4);
},

extendRight: function(ctx,node,length){
Expand Down Expand Up @@ -152,7 +154,7 @@ var circuit = {
this.extendLeft(ctx,nodes.Vminus,8);
this.markNode(ctx,nodes.current,"nodeNegative");
this.extendLeft(ctx,nodes.Vplus,4);
if(this.z < 0) {
if(this.z > 0) {
this.markNode(ctx,nodes.current,"nodeX");
}
this.extendLeft(ctx,nodes.current,4);
Expand All @@ -169,15 +171,15 @@ var circuit = {
this.z = this.z + int;
if(int > 0) this.posTerms.push(obj);
if(int < 0) this.negTerms.push(obj);
}
}
},
drawNegative : function(ctx){
for(var i=0;i<this.negTerms.length;i++){
this.extendUp(ctx,nodes.nodeNegative,i*4);
this.extendLeft(ctx,nodes.current,5);
this.extendLeft(ctx,nodes.current,7);
var resValue = -(this.rf/this.negTerms[i].value).toFixed(2);
this.resistorLeft(ctx,nodes.current,`R${this.negTerms[i].index}`,resValue);
this.extendLeft(ctx,nodes.current,5);
this.extendLeft(ctx,nodes.current,4);
this.drawVoltageRight(ctx,nodes.current,`V${this.negTerms[i].index}`);
}

Expand All @@ -187,17 +189,19 @@ var circuit = {
this.extendRight(ctx,nodes.current,1);
var resValue = -(this.rf/this.z).toFixed(2);
this.resistorRight(ctx,nodes.current,"Rx",resValue);
this.extendRight(ctx,nodes.current,1);
this.extendRight(ctx,nodes.current,2);
this.extendDown(ctx,nodes.current,1);
this.groundDown(ctx,nodes.current);
}
},

drawPositive : function(ctx){
for(var i=0;i<this.posTerms.length;i++){
this.extendDown(ctx,nodes.nodePositive,i*4);
this.extendLeft(ctx,nodes.current,5);
this.extendLeft(ctx,nodes.current,7);
var resValue = (this.rf/this.posTerms[i].value).toFixed(2);
this.resistorLeft(ctx,nodes.current,`R${this.posTerms[i].index}`,resValue);
this.extendLeft(ctx,nodes.current,5);
this.extendLeft(ctx,nodes.current,4);
this.drawVoltageRight(ctx,nodes.current,`V${this.posTerms[i].index}`);
}

Expand All @@ -207,17 +211,75 @@ var circuit = {
this.extendRight(ctx,nodes.current,1);
var resValue = (this.rf/this.z).toFixed(2);
this.resistorRight(ctx,nodes.current,"Rx",resValue);
this.extendRight(ctx,nodes.current,1);
this.extendRight(ctx,nodes.current,2);
this.extendDown(ctx,nodes.current,2);
this.groundDown(ctx,nodes.current);
}
},

drawVoltageRight : function(ctx,node,name){
drawVoltageRight : function(ctx,node,name,i){
ctx.beginPath();
fillText(ctx,"+",node.x + 0.1,node.y -0.1);
fillText(ctx,"-",node.x - 2.4,node.y -0.1);
circle(ctx,node.x-1,node.y);
ctx.stroke();
fillText(ctx,name,node.x-1.4,node.y+0.4);
moveTo(ctx,node.x-2,node.y);
this.extendLeft(ctx,nodes.current,2);
this.extendDown(ctx,nodes.current,1);
this.groundDown(ctx,nodes.current);
},

groundLeft : function(ctx,node){
ctx.strokeStyle = "black";
ctx.beginPath();
moveTo(ctx,node.x,node.y-1);
lineTo(ctx,node.x,node.y+1);
// moveTo(ctx,node.x-1,node.y);

moveTo(ctx,node.x-0.3,node.y-0.7);
lineTo(ctx,node.x-0.3,node.y+0.7);
// moveTo(ctx,node.x-1,node.y);

moveTo(ctx,node.x-0.6,node.y-0.4);
lineTo(ctx,node.x-0.6,node.y+0.4);
// moveTo(ctx,node.x-1,node.y);
ctx.stroke();
ctx.closePath();
},
groundRight : function(ctx,node){
ctx.strokeStyle = "black";
ctx.beginPath();
moveTo(ctx,node.x,node.y-1);
lineTo(ctx,node.x,node.y+1);
// moveTo(ctx,node.x-1,node.y);

moveTo(ctx,node.x+0.3,node.y-0.7);
lineTo(ctx,node.x+0.3,node.y+0.7);
// moveTo(ctx,node.x-1,node.y);

moveTo(ctx,node.x+0.6,node.y-0.4);
lineTo(ctx,node.x+0.6,node.y+0.4);
// moveTo(ctx,node.x-1,node.y);
ctx.stroke();
ctx.closePath();
},
groundDown : function(ctx,node){
ctx.strokeStyle = "black";
ctx.beginPath();
moveTo(ctx,node.x-0.8,node.y);
lineTo(ctx,node.x+0.8,node.y);
// moveTo(ctx,node.x-1,node.y);

moveTo(ctx,node.x-0.5,node.y+0.4);
lineTo(ctx,node.x+0.5,node.y+0.4);
// moveTo(ctx,node.x-1,node.y);

moveTo(ctx,node.x-0.2,node.y+0.8);
lineTo(ctx,node.x+0.2,node.y+0.8);
// moveTo(ctx,node.x-1,node.y);
ctx.stroke();
ctx.closePath();
}
}

Expand Down

0 comments on commit 77527fd

Please sign in to comment.