Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <title>Function Plotter</title>
  6.  
  7. <meta charset="UTF-8">
  8. <meta name="description" content="graph drawer">
  9. <meta name="keywords" content="HTML,CSS,JavaScript">
  10. <meta name="author" content="Paolo Bettelini">
  11. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  12.  
  13. <!-- Browser: Brave -->
  14. <!-- O.S.: Mac OS X -->
  15. <!-- Data creazione: 18.10.2019 -->
  16. <!-- Data ultima modifica: 18.10.2019 -->
  17.  
  18. <style>
  19. body {
  20. background: white;
  21. }
  22. #canvas {
  23. position: absolute;
  24. top: 25px;
  25. left: 500px;
  26. }
  27. </style>
  28. </head>
  29.  
  30. <body>
  31. <canvas id="canvas" width="1000" height="1000">
  32. <button type = "button">up
  33. </button>
  34. <script>
  35. var
  36. canvas = document.getElementById("canvas"),
  37. ctx = canvas.getContext("2d"),
  38. cLength = canvas.width,
  39. scale = 5;
  40. fLength = (cLength/2)/scale,
  41. dotSize = 1;
  42.  
  43. function f(x) {
  44. //return Math.sin(Math.sqrt(x)*Math.tan(x));
  45. return Math.sin(Math.sqrt(4-Math.pow(x,2)));
  46. //return Math.pow(Math.random()*x, 2)-3;
  47. //return -Math.random()*Math.ceil(x);
  48. //return Math.random()*5;
  49. //return Math.random()*Math.sin(x);
  50. //return Math.pow(Math.random()*x, Math.random()*x);
  51. //return Math.sqrt(Math.random()*x);
  52. //return Math.sin(Math.random()*x);
  53. //return Math.random()*x;
  54. //return Math.sin(Math.abs(Math.pow(x, x), Math.abs(Math.pow(x, x))));
  55.  
  56. }
  57.  
  58. window.addEventListener("keypress", function() {
  59.  
  60. });
  61.  
  62. function drawPlane() {
  63. ctx.fillStyle = "black";
  64. ctx.fillRect(0, 0, cLength, 1);
  65. ctx.fillRect(0, 0, 1, cLength);
  66. ctx.fillRect(0, cLength - 1 , cLength, 1);
  67. ctx.fillRect(cLength - 1, 0, 1, cLength);
  68. ctx.fillRect(cLength/2, 0, 1, cLength);
  69. ctx.fillRect(0, cLength/2, cLength, 1);
  70. }
  71.  
  72. function drawFunction() {
  73. ctx.fillStyle = "red";
  74. for (i = 0; i <= cLength/2; i += 0.01)
  75. ctx.fillRect(i + cLength/2, cLength/2 - f(i / fLength) * fLength, dotSize, dotSize);
  76. for (i = 0; i <= cLength/2; i += 0.01)
  77. ctx.fillRect(cLength/2 - i, cLength/2 - f(- i / fLength) * fLength, dotSize, dotSize);
  78. }
  79. function draw() {
  80. ctx.fillStyle = "white";
  81. ctx.fillRect(0, 0, cLength, cLength);
  82. drawFunction();
  83. drawPlane();
  84. }
  85. draw();
  86. </script>
  87. </body>
  88.  
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement