Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Active-object/JavaScript/active-object-1.js
Normal file
26
Task/Active-object/JavaScript/active-object-1.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
function Integrator(sampleIntervalMS) {
|
||||
var inputF = function () { return 0.0 };
|
||||
var sum = 0.0;
|
||||
|
||||
var t1 = new Date().getTime();
|
||||
var input1 = inputF(t1 / 1000);
|
||||
|
||||
function update() {
|
||||
var t2 = new Date().getTime();
|
||||
var input2 = inputF(t2 / 1000);
|
||||
var dt = (t2 - t1) / 1000;
|
||||
|
||||
sum += (input1 + input2) * dt / 2;
|
||||
|
||||
t1 = t2;
|
||||
input1 = input2;
|
||||
}
|
||||
|
||||
var updater = setInterval(update, sampleIntervalMS);
|
||||
|
||||
return ({
|
||||
input: function (newF) { inputF = newF },
|
||||
output: function () { return sum },
|
||||
shutdown: function () { clearInterval(updater) },
|
||||
});
|
||||
}
|
||||
20
Task/Active-object/JavaScript/active-object-2.js
Normal file
20
Task/Active-object/JavaScript/active-object-2.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<p><span id="a">Test running...</span> <code id="b">-</code></p>
|
||||
|
||||
<script type="text/javascript">
|
||||
var f = 0.5;
|
||||
|
||||
var i = new Integrator(1);
|
||||
var displayer = setInterval(function () { document.getElementById("b").firstChild.data = i.output() }, 100)
|
||||
|
||||
setTimeout(function () {
|
||||
i.input(function (t) { return Math.sin(2*Math.PI*f*t) }); // test step 1
|
||||
setTimeout(function () { // test step 2
|
||||
i.input(function (t) { return 0 }); // test step 3
|
||||
setTimeout(function () { // test step 3
|
||||
i.shutdown();
|
||||
clearInterval(displayer);
|
||||
document.getElementById("a").firstChild.data = "Done, should be about 0: "
|
||||
}, 500);
|
||||
}, 2000);
|
||||
}, 1)
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue