Facebook
From Commodious Parrot, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 129
  1. <!doctype html>
  2. <html>
  3. <head>
  4.   <title>2D Context</title>
  5.   <script>
  6.       window.onload = setup2d;
  7.  
  8.  
  9.       function setup2d()
  10.       {
  11.           const canvas = document.getElementById("my-canvas");
  12.           const context = canvas.getContext('2d');
  13.  
  14.           context.fillStyle = random_rgba();
  15.           context.fillRect (10, 10, 100, 100);
  16.  
  17.           context.fillStyle = random_rgba();
  18.           context.fillRect (120, 120, 100, 100);
  19.  
  20.           context.fillStyle = random_rgba();;
  21.           context.fillRect (120, 10, 100, 100);
  22.  
  23.           context.fillStyle = random_rgba();
  24.           context.fillRect (10, 120, 100, 100);
  25.       }
  26.  
  27.       function random_rgba() {
  28.           var o = Math.round, r = Math.random, s = 255;
  29.           return 'rgba(' + o(r()*s) + ',' + o(r()*s) + ',' + o(r()*s) + ',' + r().toFixed(1) + ')';
  30.       }
  31.   </script>
  32.   <style>
  33.     #my-canvas {
  34.       background-color: yellow;
  35.     }
  36.   </style>
  37. </head>
  38. <body>
  39. <p>Jarosław Gryczan</p>
  40. <p>47184</p>
  41. <canvas id="my-canvas" width="230" height="230">
  42. </canvas>
  43.  
  44. </body>
  45. </html>
  46.