Merge branch 'master' of leafbla.de:dominic/ResistorJS
This commit is contained in:
commit
562e2ea9dc
15
README.md
15
README.md
@ -3,18 +3,29 @@ ResistorJS is a Javascript library intended to compose electronical resistors.
|
|||||||
|
|
||||||
## Using Resistors in Code
|
## Using Resistors in Code
|
||||||
In order to instantiate an 100 Ohm resistor, we simply call `new Resistor(100)`. In order to compose several resistors, the composite resistor types `SeriesResistor` and `ParallelResistor` are available.
|
In order to instantiate an 100 Ohm resistor, we simply call `new Resistor(100)`. In order to compose several resistors, the composite resistor types `SeriesResistor` and `ParallelResistor` are available.
|
||||||
```
|
```JS
|
||||||
var r1 = new Resistor(100);
|
var r1 = new Resistor(100);
|
||||||
var r2 = new Resistor(150);
|
var r2 = new Resistor(150);
|
||||||
// Combining resistors
|
// Combining resistors
|
||||||
var inSeries = r1.series(r2); // type: SeriesResistor
|
var inSeries = r1.series(r2); // type: SeriesResistor
|
||||||
var inParallel = r1.parallel(r2); // type: ParallelResistor
|
var inParallel = r1.parallel(r2); // type: ParallelResistor
|
||||||
|
|
||||||
|
// Computing resulting resistors
|
||||||
|
inSeries.getOhmage() // 250
|
||||||
|
inParallel.getOhmage() // 60
|
||||||
|
|
||||||
// Drawing to DOM
|
// Drawing to DOM
|
||||||
r1.draw(div1);
|
r1.draw(div1);
|
||||||
r2.draw(div2);
|
r2.draw(div2);
|
||||||
inSeries.draw(div3);
|
inSeries.draw(div3);
|
||||||
inParallel.draw(div4);
|
inParallel.draw(div4);
|
||||||
```
|
```
|
||||||
Calling `Resistor.draw(element)` generates an SVG from the constructed Resistor object. Above code would render something like this:
|
Calling `Resistor.draw(element)` generates an SVG from the constructed Resistor object. Above code will render something like this:
|
||||||

|

|
||||||
|
|
||||||
|
## Computing approximations
|
||||||
|
Sometimes, one wants to use ohmages in an electronical circuit that simply are not available. By cleverly combining a sufficient number of available resistors, one can approximate the needed values. For instance, using only 100Ohm and 100Ohm resistors, one can construct a (sufficiently close to) 127Ohm resistor like so:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
`main.js` contains an example application using dynamic programming that computes sufficiently good approximations for resistor values within a set range.
|
Loading…
Reference in New Issue
Block a user