sashomaga

Canvas -> house

May 10th, 2013
91
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="500" height="550">
  14.     </canvas>
  15.    
  16. </body>
  17.     <script>
  18.         var ctx = document.getElementById('can1').getContext('2d');                
  19.         // house base  
  20.         ctx.strokeStyle = '#000000';
  21.         ctx.lineWidth = 2;      
  22.         ctx.fillStyle = '#975B5B';      
  23.         ctx.fillRect(100, 200, 300, 300);
  24.         ctx.strokeRect(100, 200, 300, 300);
  25.         // roof
  26.         ctx.beginPath();
  27.         ctx.moveTo(100, 200);
  28.         ctx.lineTo(250, 50);
  29.         ctx.lineTo(400, 200);
  30.         ctx.lineTo(100, 200);
  31.         ctx.fill();
  32.         ctx.stroke();
  33.         //chimney
  34.         ctx.beginPath();
  35.         ctx.moveTo(330, 180);
  36.         ctx.lineTo(330, 100);
  37.         ctx.lineTo(360, 100);
  38.         ctx.lineTo(360, 180);
  39.         ctx.fill();
  40.         ctx.stroke();
  41.  
  42.         // upper windows
  43.         ctx.fillStyle = '#000000';
  44.         ctx.fillRect(140, 250, 40, 30);
  45.         ctx.fillRect(185, 250, 40, 30);
  46.         ctx.fillRect(140, 285, 40, 30);
  47.         ctx.fillRect(185, 285, 40, 30);
  48.        
  49.         ctx.fillRect(270, 250, 40, 30);
  50.         ctx.fillRect(315, 250, 40, 30);
  51.         ctx.fillRect(270, 285, 40, 30);
  52.         ctx.fillRect(315, 285, 40, 30);
  53.  
  54.         // base window
  55.         ctx.fillRect(270, 350, 40, 30);
  56.         ctx.fillRect(315, 350, 40, 30);
  57.         ctx.fillRect(270, 385, 40, 30);
  58.         ctx.fillRect(315, 385, 40, 30);
  59.        
  60.         // door
  61.         ctx.beginPath();
  62.         ctx.moveTo(140, 500);
  63.         ctx.lineTo(140, 420);
  64.         ctx.moveTo(215, 420);
  65.         ctx.lineTo(215, 500);
  66.         ctx.moveTo(177, 500);
  67.         ctx.lineTo(177, 404);
  68.         ctx.stroke();
  69.  
  70.         //door small circles
  71.         ctx.beginPath();
  72.         ctx.arc(165, 465, 5, 0, Math.PI * 2, false);              
  73.         ctx.stroke();
  74.  
  75.         ctx.beginPath();
  76.         ctx.arc(190, 465, 5, 0, Math.PI * 2, false);
  77.         ctx.stroke();
  78.  
  79.         // door arc    
  80.         ctx.save();
  81.         ctx.scale(2.5, 1);
  82.         ctx.beginPath();
  83.         ctx.lineWidth = 2;        
  84.         ctx.arc(71, 420, 15, Math.PI, 2 * Math.PI, false);
  85.         ctx.restore();
  86.         ctx.stroke();
  87.     </script>
  88. </html>
Advertisement
Add Comment
Please, Sign In to add comment