Skip to content
Snippets Groups Projects
Commit 1473143a authored by Jake Read's avatar Jake Read
Browse files

+= and integer-floats generic

parent 7d05c157
Branches
No related tags found
No related merge requests found
/*
convert to floats, respect discretion
*/
import {
Hunkify,
Input,
Output,
State
} from '../hunks.js'
export default function DiscreteConverter(){
Hunkify(this)
let floatsPerInteger = new State('number', 'units per increment', 4.23387)
this.states.push(floatsPerInteger)
let intInput = new Input('number', 'integer', this)
this.inputs.push(intInput)
let floatOutput = new Output('number', 'value', this)
this.outputs.push(floatOutput)
this.init = () => {
//
}
this.loop = () => {
// consider: a shorthand for these very-simple-hunks ? inline expressions ?
if(intInput.io() && !floatOutput.io()){
floatOutput.put(floatsPerInteger.value * Math.round(intInput.get()))
}
}
}
/*
output += input
*/
import {
Hunkify,
Input,
Output,
State
} from '../hunks.js'
export default function PlusEquals() {
Hunkify(this)
let internalValue = 0
let hasUpdate = false
let input = new Input('number', 'plus', this)
this.inputs.push(input)
let output = new Output('number', 'result', this)
this.outputs.push(output)
let reset = new State('boolean', 'reset', false)
reset.onChange = (value) => {
internalValue = 0
hasUpdate = true
}
this.states.push(reset)
this.init = () => {
//
}
this.loop = () => {
if(input.io()){
internalValue += input.get()
hasUpdate = true
}
if(!output.io() && hasUpdate){
output.put(internalValue)
hasUpdate = false
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment