Facebook
From Gentle Motmot, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 118
  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.           context.fillStyle = random_rgba();
  14.           context.fillRect (10, 10, 100, 100);
  15.           context.fillStyle = random_rgba();
  16.           context.fillRect (110, 110, 100, 100);
  17.           context.fillStyle = random_rgba();;
  18.           context.fillRect (110, 10, 100, 100);
  19.           context.fillStyle = random_rgba();
  20.           context.fillRect (10, 110, 100, 100);
  21.       }
  22.  
  23.       function random_rgba() {
  24.           var o = Math.round, r = Math.random, s = 255;
  25.           return 'rgba(' + o(r()*s) + ',' + o(r()*s) + ',' + o(r()*s) + ',' + r().toFixed(1) + ')';
  26.       }
  27.   </script>
  28.   <style>
  29.       #my-canvas {
  30.         background-color: blueviolet;
  31.       }
  32.   </style>
  33. </head>
  34. <body>
  35. <p>Jarosław Gryczan</p>
  36. <p>47184</p>
  37. <canvas id="my-canvas" width="220" height="220">
  38. </canvas>
  39.  
  40. </body>
  41. </html>
  42.