gibney.org
:
Technology
:
Javascript
:
Tools
:
plot
(Entry Nr. 2247, by user 1 |
edit
)
<!doctype html> <html><body id=body> <style> body,html { width: 100%; height: 100%; margin: 0; padding: 0; } </style> <canvas id=canvas width=1 height=1 style='width: 100%; height: 99%; margin: 0'></canvas> <script> function plot(code) { // put all Math functions into the global scope: var x=Object.getOwnPropertyNames(Math); for (var m in x) window[x[m]]=Math[x[m]]; var canvas = document.getElementById("canvas"); var body=document.getElementById("body"); canvas.width=body.clientWidth; canvas.height=body.clientHeight; var ctx = canvas.getContext("2d"); ctx.fillStyle = "rgb(0, 0, 100)"; for (var sx=0;sx<canvas.width;sx+=1) { var x=-1+2*sx/canvas.width; var y=eval(code); var sy=0.5*canvas.height-0.5*y*canvas.height; ctx.fillRect (sx,sy,1,1); } } function go() { var code=location.hash.replace("#",""); plot (code); } go(); window.onhashchange=go; </script> </body></html>
Create a new entry at this position