Codesine/implementation
Jump to navigation
Jump to search
So far I have this running along with html that's just an input box with the ID read and a button to call EVAL(). I'm wondering if I should bother trying to implement named variables, or just go with making people use numbers as variable references.
function program()
{
this.wavesets = [];
this.add = function(name,f,a) {
//here I should be able to take a string and convert it to an array index
//or if not found, create a new index. Thus allowing named wavesets.
}
function waveset()
{
this.waves = [];
this.add = function(f,a) {
f = Math.min(Math.abs(f));
while (f >= this.waves.length) {
this.waves.push(0);
}
this.waves[f] = a;
};
this.weval = function(input) {
//No idea if this is how cosine wave transform works.
var total = this.waves[0];
for (var loop = 1; loop < this.waves.length ; loop++) {
total += (1/loop)/Math.cos(input)*this.waves[loop];
}
return total;
};
this.waverage = function(total) {
return total/this.waves.length;
};
}
function LineEval(commands) {
switch(commands[0]) {
case "addwave":
if (commands.length == 3) { Waveset.add(commands[1],commands[2]); } else {
window.alert("Wrong number of arguments for " + commands[0]);
}
break;
case "print":
if (commands.length == 2) { window.alert(Waveset.weval(commands[1])); } else {
window.alert("Wrong number of arguments for " + commands[0]);
}
break;
case "alert":
for (var loop = 1; loop < commands.length ; loop++) {
window.alert(commands[loop]);
}
break;
case "nop":
break;
default:
window.alert('Command "'+commands[0]+'" not understood, skipped.');
}
}
function EVAL() {
//read
var command = document.getElementById("read").value;
LineEval(command.split(" "));
}
var Waveset = new waveset();