-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
8,265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
|
||
class Component { | ||
constructor(name, value, x, y) { | ||
this.name = name; | ||
this.value = value; | ||
this.x = x; | ||
this.y = y; | ||
this.width = cellSize * 2; | ||
this.height = cellSize; | ||
this.angle = 0; | ||
this.selected = false; | ||
|
||
this.node1 = new Node(); | ||
this.node2 = new Node(); | ||
|
||
this.node1.parent = this; | ||
this.node2.parent = this; | ||
|
||
connectNodes(this.node1, this.node2, this.value); | ||
|
||
} | ||
|
||
rotationPointX() { | ||
//return this.x; | ||
return this.x + this.width/2; | ||
} | ||
|
||
rotationPointY() { | ||
//return this.y; | ||
return this.y + this.height/2; | ||
} | ||
|
||
drawComponent() {} | ||
|
||
draw() { | ||
ctx.save(); | ||
|
||
ctx.translate(this.rotationPointX(), this.rotationPointY()); | ||
ctx.rotate(this.angle * (Math.PI / 180)); | ||
ctx.translate(-this.rotationPointX(), -this.rotationPointY()); | ||
|
||
if (this.selected) { | ||
ctx.strokeStyle = "#FF0000"; | ||
ctx.fillStyle = "#FF0000"; | ||
} | ||
else { | ||
ctx.strokeStyle = "#000000"; | ||
ctx.fillStyle = "#000000"; | ||
} | ||
|
||
ctx.beginPath(); | ||
|
||
this.drawComponent(); | ||
|
||
ctx.closePath(); | ||
ctx.stroke(); | ||
|
||
ctx.font = "bold 12px sans-serif"; | ||
|
||
let nameMetric = ctx.measureText(this.name); | ||
let valueMetric = ctx.measureText(this.value); | ||
|
||
/* ALIGN text left */ | ||
//ctx.fillText(this.value, this.x, this.y - (valueMetric.actualBoundingBoxAscent + valueMetric.actualBoundingBoxDescent) / 2); | ||
//ctx.fillText(this.name, this.x, this.y - (nameMetric.actualBoundingBoxAscent + nameMetric.actualBoundingBoxDescent) * 2); | ||
/* ALIGN text left*/ | ||
|
||
|
||
ctx.fillText(this.value, this.x + (this.width - valueMetric.width) / 2, this.y - (valueMetric.actualBoundingBoxAscent + valueMetric.actualBoundingBoxDescent) / 2); | ||
ctx.fillText(this.name, this.x + (this.width - nameMetric.width) / 2, this.y - (nameMetric.actualBoundingBoxAscent + nameMetric.actualBoundingBoxDescent) * 2); | ||
|
||
ctx.restore(); | ||
|
||
//drawCirc(this.rotationPointX(), this.rotationPointY()); // rotation point | ||
} | ||
|
||
hitTest(x, y) { | ||
let rotatedPoint = rotatePoint( | ||
{x: x, y: y}, | ||
{x: this.rotationPointX(), y: this.rotationPointY()}, | ||
-this.angle | ||
); | ||
if ((rotatedPoint.x >= this.x && rotatedPoint.x <= (this.x + this.width)) && | ||
(rotatedPoint.y >= this.y && rotatedPoint.y <= (this.y + this.height))) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
hitNode(x, y) { // interpolate? | ||
let rotatedPoint = rotatePoint( | ||
{x: x, y: y}, | ||
{x: this.rotationPointX(), y: this.rotationPointY()}, | ||
-this.angle | ||
); | ||
|
||
rotatedPoint.x = snapToGrid(rotatedPoint.x); | ||
rotatedPoint.y = snapToGrid(rotatedPoint.y); | ||
|
||
if ((rotatedPoint.x === (this.x-this.width)) && (rotatedPoint.y === this.y + this.height / 2)) return this.node1; | ||
|
||
if ((rotatedPoint.x === (this.x + this.width * 2)) && (rotatedPoint.y === (this.y + this.height / 2))) return this.node2; | ||
|
||
return null; | ||
} | ||
|
||
getNodeLeft() { | ||
return rotatePoint( | ||
{x: this.x - this.width, y: this.y + this.height / 2}, | ||
{x: this.rotationPointX(), y: this.rotationPointY()}, | ||
-this.angle | ||
); | ||
} | ||
|
||
getNodeRight() { | ||
return rotatePoint( | ||
{x: this.x + this.width * 2, y: this.y + this.height / 2}, | ||
{x: this.rotationPointX(), y: this.rotationPointY()}, | ||
-this.angle); | ||
} | ||
|
||
onDelete() { | ||
deleteNode(this.node1); | ||
deleteNode(this.node2); | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!-- | ||
github: https://github.com/espmaniac/parallelserieshtml5 | ||
--> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>ParallelSeries</title> | ||
<meta name="keywords" content="ParallelSeries, equivalent resistance, equivalent capacitance, equivalent inductance, delta star transform, parallel connection, series connection, resistance calculator, capacitance calculator, inductance calculator, resistor network solver, capacitor network solver, inductor network solver"> | ||
<link rel="icon" href="logo/favicon.svg" sizes="any" type="image/svg+xml"> | ||
<link rel="shortcut icon" href="logo/favicon16x16.ico" type="image/x-icon"> | ||
<link rel="shortcut icon" href="logo/favicon32x32.ico" type="image/x-icon"> | ||
<link rel="shortcut icon" href="logo/favicon96x96.ico" type="image/x-icon"> | ||
<link rel="shortcut icon" href="logo/favicon180x180.ico" type="image/x-icon"> | ||
<link rel="shortcut icon" href="logo/favicon512x512.ico" type="image/x-icon"> | ||
<link rel="stylesheet" href="main.css"> | ||
</head> | ||
<body> | ||
|
||
<div id="chooseComponent"> | ||
<h1>Choose a component</h1> | ||
<div id="components"> | ||
<button id="resistor" ></button> | ||
<button id="capacitor"></button> | ||
<button id="inductor"></button> | ||
</div> | ||
</div> | ||
|
||
<div id="header"> | ||
<div id="left"> | ||
<button id="open">Open</button> | ||
<button id="save">Save</button> | ||
<button id="matrix">Matrix</button> | ||
<button id="calculate">Calculate</button> | ||
</div> | ||
|
||
<a href="https://github.com/espmaniac" target="_blank"><img src="icons/github.png" alt="github" srcset="" id="github"></a> | ||
|
||
<div id="right"> | ||
<button id="clear">Clear</button> | ||
</div> | ||
</div> | ||
|
||
<div id="scheme"> | ||
<div id="tools"> | ||
<button id="cursorTool" class="active"> | ||
<img src="icons/cursor.svg" alt="" srcset="" width="40" height="20"> | ||
</button> | ||
<button id="selectionTool"> | ||
<img src="icons/selection.svg" alt="" srcset="" width="40" height="20"> | ||
</button> | ||
<button id="wireTool"> | ||
<img src="icons/wire.svg" alt="" srcset="" width="40" height="20"> | ||
</button> | ||
<button id="addComponent"> | ||
<img src="" alt="" srcset="" width="40" height="20"> | ||
</button> | ||
|
||
</div> | ||
|
||
<canvas id="myCanvas"></canvas> | ||
|
||
</div> | ||
|
||
<div id="form"> | ||
<textarea name="" id="inp" cols="1" rows="1" placeholder="expression"></textarea> | ||
<button id="calc"> = </button> | ||
</div> | ||
<div id="answer"> | ||
<h2 id="result">Answer: 42</h2> | ||
</div> | ||
|
||
<div id="contextMenu"></div> | ||
|
||
<script src="parallelseries.js" defer></script> | ||
<script src="component.js" defer></script> | ||
<script src="main.js" defer></script> | ||
<script src="node.js" defer></script> | ||
<script src="wire.js" defer></script> | ||
</body> | ||
</html> |
Oops, something went wrong.