Guest User

Untitled

a guest
Sep 20th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. //CANVAS TRANSFORMATION:
  2.  
  3. canvas.font='bold 22px Tahoma'
  4. canvas.textAlign='start';
  5. canvas.fillText('start', 10,30);
  6.  
  7. canvas.translate(100,150); //canvas.translate() this function moves the canvas around,
  8. //it takes two params whic is the (x,y) params
  9.  
  10. canvas.fillText('after translate', 0, 0);
  11.  
  12. canvas.rotate(1);//this method takes only one params and it uses gradient...its is rotates the canvas
  13. canvas.fillText('after rotate', 0,0);
  14.  
  15. canvas.scale(1.5,4);//this method is to increase the size of the rotated text
  16. canvas.fillText('after scale', 0,20);
  17.  
  18. //WORKING WITH IMAGES ON THE CANVAS
  19.  
  20. var pic = new Image();
  21. pic.src="image/unsplash5.jpeg";
  22. pic.addEventListener('load', function(){
  23. canvas.drawImage(pic,0,0,x.Width,x.height)
  24. }, false)
  25.  
  26.  
  27. //USING CANVAS ANIMATION FOR GAMES
  28.  
  29. window.addEventListener('mousemove', Animate, false)
  30. };
  31.  
  32. function Animate (e) {
  33. // canvas.clearRect(0,0,600,400); // what this does is it takes a shape as a parameter and it clears all the pixels in it.
  34.  
  35. var xPosition = e.clientX; //this is to get the position of x in the canvas
  36.  
  37. var yPosition = e.clientY;
  38.  
  39. canvas.fillRect(xPosition-50,yPosition-50,100,100); // this is saying make a rectangle from the x to the y position(whenever the mouse is moving around)
  40. }
  41.  
  42. window.addEventListener('load', executeFirst, false)
Add Comment
Please, Sign In to add comment