Advertisement
Guest User

jac

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4. <head>
  5. <title>hej</title>
  6. <meta charset="utf-8" />
  7. <style>
  8. canvas{
  9. border: 1px solid black
  10. }
  11. </style>
  12. </head>
  13.  
  14. <body>
  15. <canvas id="cvs" width="800" height="600">
  16. Browser does not support canvas...
  17. </canvas>
  18. <script type="text/javascript">
  19. var cvs = document.getElementById("cvs");
  20. var ctx = cvs.getContext("2d");
  21. var X, Y, W, H;
  22. X = 0;
  23. Y = 0;
  24. W = cvs.width;
  25. H = cvs.height;
  26. ctx.fillRect(X, Y, W, H);
  27. ctx.fillStyle = "rgb(255,0,0)";
  28. ctx.fillRect(W / 2 - W / 4, H / 2 - H / 4, W / 2, H / 2);
  29. var x, y, w, h;
  30. x = y = 0;
  31. w = h = 40;
  32. var r = parseInt(H / h);
  33. var c = parseInt(W / w);
  34.  
  35. /*}
  36. for(var i = 0; i < r; i++){
  37. if (i % 2 === 0){
  38. ctx.fillStyle = "rgb(0,255,0)";
  39. }else{
  40. ctx.fillStyle = "rgb(0,0,255)";
  41. }
  42. y = i * h;
  43. ctx.fillRect(x, y, w, h);
  44. }
  45. */
  46. for(var i = 0; i < r; i++){
  47. y = i * h;
  48. if (i % 2 === 0){
  49. for(var j = 0; j < c; j++){
  50. if (j % 2 === 0){
  51.  
  52. ctx.fillStyle = "rgb(255,0,0)";
  53. }else{
  54. ctx.fillStyle = "rgb(184,3,255)";
  55. }
  56. x = j * w;
  57. ctx.fillRect(x, y, w, h);
  58. }
  59. }else{
  60. for(var j = 0; j < c; j++){
  61. if (j % 2 !== 0){
  62. ctx.fillStyle = "rgb(255,0,0)";
  63. }else{
  64. ctx.fillStyle = "rgb(184,3,255)";
  65. }
  66. x = j * w;
  67. ctx.fillRect(x, y, w, h);
  68. }
  69.  
  70. }
  71.  
  72. }
  73. </script>
  74.  
  75.  
  76.  
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement