Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
espmaniac authored Sep 15, 2024
1 parent b282336 commit ec6cf30
Show file tree
Hide file tree
Showing 30 changed files with 8,265 additions and 0 deletions.
127 changes: 127 additions & 0 deletions component.js
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);
}

}
Binary file added icons/capacitor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions icons/capacitor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/cursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions icons/cursor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions icons/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/inductor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions icons/inductor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/res_eu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions icons/res_eu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/res_us.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions icons/res_us.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/selection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions icons/selection.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/wire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions icons/wire.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions index.html
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>
Loading

0 comments on commit ec6cf30

Please sign in to comment.