sashomaga

Canvas -> arcs

May 10th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <title></title>
  5.     <style>
  6.         #can1
  7.         {
  8.             border: 1px solid black;
  9.         }
  10.     </style>
  11. </head>
  12. <body>
  13.     <canvas id="can1" width="400" height="500">
  14.     </canvas>
  15.    
  16. </body>
  17.     <script>
  18.         var ctx = document.getElementById('can1').getContext('2d');
  19.         // hat                      
  20.         ctx.beginPath();
  21.         ctx.arc(200, 350, 100, 0, Math.PI * 2, false);                
  22.         ctx.fillStyle = '#90CAD7';
  23.         ctx.fill();
  24.         ctx.lineWidth = 2;
  25.         ctx.strokeStyle = '#317281';
  26.         ctx.stroke();
  27.  
  28.         // oval face
  29.         ctx.save();
  30.         ctx.scale(2.5, 1);
  31.         ctx.beginPath();
  32.         ctx.arc(80, 400, 15, 0, Math.PI * 2, false);        
  33.         ctx.closePath();
  34.         ctx.restore();
  35.         ctx.stroke();
  36.  
  37.         // nose
  38.         ctx.beginPath();
  39.         ctx.moveTo(200, 320);
  40.         ctx.lineTo(170, 370);
  41.         ctx.lineTo(200, 370);
  42.         ctx.stroke();
  43.        
  44.         // eyes
  45.         ctx.save();
  46.         ctx.scale(2, 1);      
  47.         ctx.beginPath();
  48.         ctx.arc(90, 310, 5, 0, 2 * Math.PI, false);
  49.         ctx.restore();
  50.         ctx.stroke();
  51.  
  52.         ctx.save();
  53.         ctx.scale(2, 1);
  54.         ctx.beginPath();
  55.         ctx.arc(110, 310, 5, 0, 2 * Math.PI, false);
  56.         ctx.restore();
  57.         ctx.stroke();        
  58.  
  59.         // hat
  60.         ctx.save();
  61.         ctx.scale(5, 1);
  62.         ctx.beginPath();
  63.         ctx.arc(40, 250, 20, 0, 2 * Math.PI, false);
  64.         ctx.fillStyle = '#396693';
  65.         ctx.fill();        
  66.         ctx.restore();
  67.         ctx.strokeStyle = '#25201C';
  68.         ctx.stroke();
  69.  
  70.         ctx.save();
  71.         ctx.scale(3, 1);
  72.         ctx.beginPath();
  73.         ctx.arc(65, 235, 20, 0, 2 * Math.PI, false);
  74.         ctx.fillStyle = '#396693';
  75.         ctx.fill();
  76.         ctx.restore();
  77.         ctx.strokeStyle = '#25201C';
  78.         ctx.stroke();    
  79.  
  80.         //fil rectangle
  81.         ctx.fillStyle = '#396693';
  82.         ctx.fillRect(135, 135, 120, 100);
  83.  
  84.         //lines on hat
  85.         ctx.beginPath();
  86.         ctx.moveTo(135, 135);
  87.         ctx.lineTo(135, 235);
  88.         ctx.moveTo(255, 135);
  89.         ctx.lineTo(255, 235);
  90.         ctx.stroke();
  91.  
  92.         //top oval
  93.         ctx.save();
  94.         ctx.scale(3, 1);
  95.         ctx.beginPath();
  96.         ctx.arc(65, 135, 20, 0, 2 * Math.PI, false);
  97.         ctx.fillStyle = '#396693';
  98.         ctx.fill();
  99.         ctx.restore();
  100.         ctx.strokeStyle = '#25201C';
  101.         ctx.stroke();
  102.     </script>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment