Advertisement
Guest User

Canvas help

a guest
Sep 24th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4. <head>
  5. <link rel="stylesheet" href="style.css">
  6. </head>
  7.  
  8. <body>
  9. <canvas id="myCanvas" width="1280" height="720" style="border:1px solid #000000;"></canvas>
  10.  
  11.  
  12. <script>
  13. var canvas = document.getElementById('myCanvas');
  14. var ctx = canvas.getContext("2d");
  15. ctx.clearRect(0, 0, canvas.width, canvas.height);
  16.  
  17. function square(x, y){
  18. this.x = x;
  19. this.y = y;
  20. this.sizex = 10;
  21. this.sizey = 10;
  22. this.Colo = Colo;
  23. function Colo(){
  24. var r = Math.floor(Math.random() * (255-1)+1);
  25. var g = Math.floor(Math.random() * (255-1)+1);
  26. var b = Math.floor(Math.random() * (255-1)+1);
  27. var run = true;
  28. var rup, gup, bup = true;
  29. while(run){
  30.  
  31. if(rup){
  32. if(r == 255){
  33. rup = false;
  34. }else if(r == 0){
  35. rup = true;
  36. }
  37.  
  38. r += 1;
  39. r.toString();
  40.  
  41. }
  42. else if(!gup){
  43. r -= 1;
  44. r.toString();
  45. }
  46.  
  47. if(gup){
  48. if(g == 255){
  49. gup = false;
  50. }else if(g == 0){
  51. gup = true;
  52. }
  53. g += 1;
  54. g.toString();
  55.  
  56.  
  57. }
  58. else if (!gup){
  59. g -= 1;
  60. g.toString();
  61. }
  62.  
  63.  
  64. if(bup = true){
  65. if(b == 255){
  66. bup = false;
  67. }else if(b == 0){
  68. bup = true;
  69. }
  70.  
  71. b += 1;
  72. b.toString();
  73.  
  74.  
  75.  
  76. }
  77. else if (!gup){
  78. b -= 1;
  79. b.toString();
  80. }
  81.  
  82.  
  83. ctx.clearRect(0, 0, canvas.width, canvas.height);
  84. var col = "rgb(" + r + "," + g + "," + b + ")";
  85.  
  86. return col;
  87. window.onfocus = function () {
  88. rup = true;
  89. };
  90. window.onblur = function () {
  91. isActive = false;
  92. };
  93. console.log("Ran loop.")
  94. }
  95. }
  96.  
  97.  
  98.  
  99. ctx.fillStyle = Colo();
  100. ctx.fillRect(this.x, this.y, this.sizex, this.sizey);
  101. }
  102.  
  103.  
  104. var squares = new Array();
  105. var p = 0;
  106. for (var i= 0; i < 128; i++){
  107. for (var j = 0; j < 72; j++){
  108. p = i + j;
  109. squares[p] = new square(i*10, j*10);
  110.  
  111. }
  112.  
  113. }
  114.  
  115.  
  116.  
  117. </script>
  118. </body>
  119.  
  120. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement