Advertisement
Guest User

Plottable Alpha

a guest
Dec 22nd, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.88 KB | None | 0 0
  1.  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  3. "http://www.w3.org/TR/html4/loose.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5.     <head>
  6.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7.         <title>Plottable Alpha</title>
  8.        
  9.         <script type="text/javascript" src="grid.js"></script>
  10.         <script type="text/javascript" src="math.js"></script>
  11.  
  12.         <script type="text/javascript">
  13.  
  14.             function coord(i) {
  15.                
  16.                 return (i/20)-13;
  17.                
  18.             }
  19.  
  20.             function clearBoard() {
  21.                
  22.                 var canvas = document.getElementById("master");
  23.                 var context = canvas.getContext("2d");
  24.                
  25.                 context.fillStyle = "black";
  26.                 context.fillRect(0,0,520,520);
  27.                
  28.                 var opts = {
  29.                 distance : 20,
  30.                 lineWidth : 1.5,
  31.                 gridColor : "green",
  32.                 caption : false
  33.                 };
  34.                
  35.                 new Grid(opts).draw(context);
  36.                
  37.                 context.fillStyle = "white";
  38.                
  39.                 context.fillRect(0,260,520,1.5);
  40.                 context.fillRect(260,0,1.5,520);
  41.                
  42.             }
  43.            
  44.             function submit() {
  45.                
  46.                 var context = document.getElementById("master").getContext("2d");
  47.                
  48.                 expr = Parser.parse(document.getElementById("func").value);
  49.                
  50.                 context.fillStyle = "red";
  51.  
  52.                 var i=0;
  53.                
  54.                 while (i<=520) {
  55.                    
  56.                     context.fillRect(i,520-((expr.evaluate({x : coord(i)})+13)*20),1.5,1.5);
  57.                     i += 0.01;
  58.                    
  59.                 }
  60.             }
  61.            
  62.         </script>
  63.        
  64.     </head>
  65.     <body bgcolor="black" onload="clearBoard();">
  66.        
  67.         <canvas id="master" width="520" height="520">Sorry, your browser does not support the canvas HTML5 tag. Please update your browser.</canvas>
  68.        
  69.         <div id="inputs">
  70.         <input type="text" id="func" />
  71.         <input type="button" value="Go!" onclick="submit();" />
  72.         <input type="button" value="Clear" onclick="clearBoard();" />
  73.         </div>
  74.        
  75.     </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement