canva.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Canvas Manipulation</title>
  7. <style>
  8. body {
  9. margin: 0;
  10. padding: 0;
  11. font-family: Arial, sans-serif;
  12. }
  13. #canvasContainer {
  14. position: relative;
  15. display: block;
  16. }
  17. #controls {
  18. position: fixed;
  19. top: 10px;
  20. right: 10px;
  21. z-index: 999;
  22. background-color: #f1f1f1;
  23. padding: 10px;
  24. border: 1px solid #ccc;
  25. border-radius: 5px;
  26. }
  27. #canvasContainer canvas {
  28. border: 1px solid #000;
  29. margin-top: 10px;
  30. display: block;
  31. position: relative;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div id="controls">
  37. <label for="width">Width:</label>
  38. <input type="number" id="width" min="1">
  39. <label for="height">Height:</label>
  40. <input type="number" id="height" min="1">
  41. <button onclick="createCanvas()">Create Canvas</button>
  42. </div>
  43. <div id="canvasContainer">
  44. </div>
  45. <script>
  46. let canvasCount = 0;
  47. function createCanvas() {
  48. const width = document.getElementById("width").value;
  49. const height = document.getElementById("height").value;
  50. if (width <= 0 || height <= 0 || width >= 1080 || height >= 1920) {
  51. alert("Please enter valid width and height values.");
  52. return;
  53. }
  54. const canvasId = `canvas_${canvasCount}`;
  55. const canvasContainer = document.getElementById("canvasContainer");
  56. const canvas = document.createElement("canvas");
  57. canvas.id = canvasId;
  58. canvas.width = width;
  59. canvas.height = height;
  60. canvasContainer.appendChild(canvas);
  61. const canvasControls = document.createElement("div");
  62. canvasControls.classList.add("canvasControls");
  63. const clearButton = document.createElement("button");
  64. clearButton.textContent = "Clear";
  65. clearButton.onclick = function() {
  66. const ctx = canvas.getContext("2d");
  67. ctx.clearRect(0, 0, canvas.width, canvas.height);
  68. };
  69. const pauseButton = document.createElement("button");
  70. pauseButton.textContent = "Pause";
  71. pauseButton.onclick = function() {
  72. const ctx = canvas.getContext("2d");
  73. console.log("Pausing v86");
  74. };
  75. const consoleButton = document.createElement("button");
  76. consoleButton.textContent = "Get console";
  77. consoleButton.onclick = function() {
  78. const ctx = canvas.getContext("2d");
  79. console.log("Getting v86 console");
  80. ctx.clearRect(0, 0, canvas.width, canvas.height);
  81. };
  82. const deleteButton = document.createElement("button");
  83. deleteButton.textContent = "Delete";
  84. deleteButton.onclick = function() {
  85. canvas.remove();
  86. canvasControls.remove();
  87. };
  88. canvasControls.appendChild(clearButton);
  89. canvasControls.appendChild(deleteButton);
  90. canvasControls.appendChild(pauseButton);
  91. canvasControls.appendChild(consoleButton);
  92. canvasContainer.appendChild(canvasControls);
  93. canvasCount++;
  94. }
  95. </script>
  96. </body>
  97. </html>