atm959

Help...

Oct 2nd, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEventListener("load", onLoad);
  2.  
  3. var canvas;
  4. var context;
  5. var myImage;
  6. var blockSize = 100;
  7. var x;
  8. var y;
  9. var frameCount = 0;
  10.  
  11. function onLoad(event)
  12. {
  13.     canvas = document.getElementById("mosaicCanvas");
  14.     context = canvas.getContext("2d");
  15.     myImage = document.createElement("img");
  16.     myImage.src = "Mosaic/effect.jpg";
  17.  
  18.     animate();
  19. }
  20.  
  21. //This is called 60 times per second, or once every frame.
  22. function animate()
  23. {
  24.     frameCount++;
  25.     blockSize = (frameCount % 64) + 1;
  26.     if(blockSize < 1) blockSize = 1;
  27.     context.fillStyle = "white";
  28.     context.fillRect(0, 0, canvas.width, canvas.height);
  29.     for(x = 0; x <= 799; x++){
  30.         for(y = 0; y <= 599; y++){
  31.             context.drawImage(myImage, x * blockSize, y * blockSize, blockSize, blockSize, x * blockSize, y * blockSize, blockSize, blockSize);
  32.         }
  33.     }
  34.  
  35.     //This tells us to run the animate() function again on the next frame.
  36.    
  37.     requestAnimationFrame(animate);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment