vonko1988

CanvasScaleProblem

Jun 1st, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.onload = function() {
  2.  
  3.     var canvas = document.getElementById("canvas-el");
  4.     canvas.width = 1100;
  5.     canvas.height = 800;
  6.  
  7.     var ctx = canvas.getContext("2d");
  8.  
  9.     ctx.save();
  10.  
  11.     //draw the head
  12.     ctx.fillStyle = "#90CAD7";
  13.     ctx.beginPath();
  14.     ctx.scale(1,0.9);
  15.     ctx.arc(250,260, 70, 0, 2*Math.PI);
  16.     ctx.fill();
  17.     ctx.stroke();
  18.  
  19.     //left eye
  20.     ctx.restore();
  21.     ctx.beginPath();
  22.     ctx.scale(1, 0.8);
  23.     ctx.arc(210,260, 10, 0, 2*Math.PI);
  24.     ctx.stroke();
  25.  
  26.     //right eye
  27.     ctx.restore();
  28.     ctx.beginPath();
  29.     ctx.arc(270,260, 10, 0, 2*Math.PI);
  30.     ctx.stroke();
  31.  
  32.     //nose
  33.     ctx.restore();
  34.     ctx.beginPath();
  35.     ctx.moveTo(240, 260);
  36.     ctx.lineTo(225, 305);
  37.     ctx.lineTo(250,305);
  38.     ctx.stroke();
  39.  
  40.  
  41.     //draw the bottom of the hat
  42.     ctx.restore();
  43.     ctx.fillStyle = "#396693";
  44.     ctx.strokeStyle = "black";
  45.     ctx.beginPath();
  46.     ctx.scale(1, 0.2);
  47.     ctx.arc(250, 1100, 100, 0, 2*Math.PI);
  48.     ctx.fill();
  49.     ctx.stroke();
  50.  
  51.     //draw the top of the hat
  52.     ctx.restore();
  53.     ctx.fillStyle = "#396693";
  54.     ctx.beginPath();
  55.     ctx.scale(1, 1.8);
  56.     ctx.arc(250, 250, 50, 0, 2 * Math.PI);
  57.     ctx.fill();
  58.     ctx.stroke();
  59.  
  60.     ctx.lineTo(300,250);
  61.     ctx.arc(250, 580, 50, 0, Math.PI);
  62.     ctx.lineTo(200,240);
  63.     ctx.fill();
  64.     ctx.stroke();
  65. }
Advertisement
Add Comment
Please, Sign In to add comment