Skip to content

Commit

Permalink
✨ calculate the brightness and size of LED
Browse files Browse the repository at this point in the history
  • Loading branch information
DrSensor committed May 19, 2018
1 parent 5e22803 commit 3c70b75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div id="app">
<Led size="3mm" scale="10px/mm"
input-voltage="3.3V" input-current="50mA"
input-voltage="3.3V" input-current="13mA"
max-power="43mW" />
</div>
</template>
Expand Down
7 changes: 4 additions & 3 deletions src/components/Led.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
import { unit, createUnit } from 'mathjs'
import { unit, createUnit, compile } from 'mathjs'
createUnit('px', { aliases: ['pixel', 'pixels', 'dot'] })
const baseUnit = (unitName: string) => (value: string) => unit(value).equalBase(unit(unitName))
const calculate = (expression: string) => compile(expression).eval()
@Component
export default class Led extends Vue {
Expand All @@ -23,7 +24,7 @@ export default class Led extends Vue {
@Prop({ validator: baseUnit('volt') }) inputVoltage!: string
@Prop({ validator: baseUnit('ampere') }) inputCurrent!: string
get height(): number { return 232 }
get brightness(): number { return 50 }
get height(): number { return calculate(`1.3 * ${this.size}*${this.scale}`).toNumber('pixel') }
get brightness(): number { return calculate(`${this.inputVoltage}*${this.inputCurrent} / ${this.maxPower}`) }
}
</script>

0 comments on commit 3c70b75

Please sign in to comment.