math-coffee
/
/ [-]
/ [@htm-math-coffee]
/ math-coffee.htm
<script type="text/javascript" src="cfg/math/mathsvg.js"></script></script>
<body>
<center>
<embed width="600" height="260" src="../media/d.svg"
script='
initPicture(-3,3,-3,3)
axes(1,1,"labels",1)
// a = 1.5
update()
'>
<script id="coffee" type="text/coffeescript">
square = (x) -> x * x
cube = (x) -> square(x) * x
window.square = square;
window.cube = cube;
</script>
<script>
function compile(cf) {
//alert(cf);
source = document.getElementById(cf).innerText;
//alert(source);
JS = CoffeeScript.compile(source);
//alert(JS);
eval(JS);
}
</script>
<script src="coffee/documentation/vendor/jquery-1.4.2.js"></script>
<script src="coffee/extras/coffee-script.js"></script>
<script>
function setfv() {
f=document.getElementById('fv').value;
}
a = 2.5;
xmode = 0;
thestroke = "blue";
compile("coffee");
cube = window.cube;
square = window.square;
toggle(s)
function toggle() {
if (xmode == 1) { thestroke = "blue"; xmode = 0; }
else { thestroke = "red"; xmode = 1; }
// alert("update");
update();
}
function xstroke() { return thestroke; }
update(s)
function update () {
f=document.getElementById('fv').value;
p = []
with (Math)
for (var x = -a; x < a+.1; x += .1)
p[p.length] = [x, eval(f)]
stroke = xstroke()
//path(p,"func")
plot(f,-a,a)
setText(f,"fval")
setText(a.toFixed(2),"aval")
setText((-a).toFixed(2),"maval")
}
</script>
<h5>
y=<span id="fval">f</span>
<input type="text" id="fv" name="fname" value="cube(x)" onblur="toggle()" />
for <span id="maval">a <=x<= a</span>
<input type="button" value="-" onclick="a-=.25;update()"/>
<input type="button" value="+" onclick="a+=.25;update()"/>
</h5>
</center>
</body>
