Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. #myCanvas1 {
  6. border: 1px solid black;
  7. }
  8. </style>
  9. </head>
  10. <body onload="init();">
  11. <canvas id="myCanvas1" width="300" height=200>Your browser does not support the canvas tag.</canvas>
  12. <script id="jsbin-javascript">
  13. var canvas, ctx, grdFrenchFlag;
  14.  
  15. function init() {
  16. // Good practice 1: set global vars canvas, ctx, gradients, etc here
  17. canvas = document.querySelector('#myCanvas1');
  18. ctx = canvas.getContext('2d');
  19.  
  20. // The gradient we create is also a global variable, we
  21. // will be able to reuse it for drawing different shapes
  22. // in different functions
  23. grdFrenchFlag = ctx.createLinearGradient(0, 0, 300, 0);
  24.  
  25. // Try adding colors with first parameter between 0 and 1
  26. grdFrenchFlag.addColorStop(0, "blue");
  27. grdFrenchFlag.addColorStop(0.5, "white");
  28. grdFrenchFlag.addColorStop(1, "red");
  29.  
  30. draw();
  31. }
  32.  
  33. function draw() {
  34. ctx.fillStyle = grdFrenchFlag;
  35. ctx.fillRect(0, 0, 300, 200);
  36. }
  37. </script>
  38.  
  39.  
  40.  
  41. <script id="jsbin-source-javascript" type="text/javascript">var canvas, ctx, grdFrenchFlag;
  42.  
  43. function init() {
  44. // Good practice 1: set global vars canvas, ctx, gradients, etc here
  45. canvas = document.querySelector('#myCanvas1');
  46. ctx = canvas.getContext('2d');
  47.  
  48. // The gradient we create is also a global variable, we
  49. // will be able to reuse it for drawing different shapes
  50. // in different functions
  51. grdFrenchFlag = ctx.createLinearGradient(0, 0, 300, 0);
  52.  
  53. // Try adding colors with first parameter between 0 and 1
  54. grdFrenchFlag.addColorStop(0, "blue");
  55. grdFrenchFlag.addColorStop(0.5, "white");
  56. grdFrenchFlag.addColorStop(1, "red");
  57.  
  58. draw();
  59. }
  60.  
  61. function draw() {
  62. ctx.fillStyle = grdFrenchFlag;
  63. ctx.fillRect(0, 0, 300, 200);
  64. }
  65. </script></body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement