examples/script/context2d/scripts/pacman.js
changeset 0 1918ee327afb
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 function roundedRect(ctx,x,y,width,height,radius){
       
     2   ctx.beginPath();
       
     3   ctx.moveTo(x,y+radius);
       
     4   ctx.lineTo(x,y+height-radius);
       
     5   ctx.quadraticCurveTo(x,y+height,x+radius,y+height);
       
     6   ctx.lineTo(x+width-radius,y+height);
       
     7   ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);
       
     8   ctx.lineTo(x+width,y+radius);
       
     9   ctx.quadraticCurveTo(x+width,y,x+width-radius,y);
       
    10   ctx.lineTo(x+radius,y);
       
    11   ctx.quadraticCurveTo(x,y,x,y+radius);
       
    12   ctx.stroke();
       
    13 }
       
    14 
       
    15 var canvas = document.getElementById('tutorial');
       
    16 
       
    17   // Make sure we don't execute when canvas isn't supported
       
    18   if (canvas.getContext){
       
    19 
       
    20     // use getContext to use the canvas for drawing
       
    21     var ctx = canvas.getContext('2d');
       
    22 
       
    23     // Draw shapes
       
    24     roundedRect(ctx,12,12,150,150,15);
       
    25     roundedRect(ctx,19,19,150,150,9);
       
    26     roundedRect(ctx,53,53,49,33,10);
       
    27     roundedRect(ctx,53,119,49,16,6);
       
    28     roundedRect(ctx,135,53,49,33,10);
       
    29     roundedRect(ctx,135,119,25,49,10);
       
    30 
       
    31     // Character 1
       
    32     ctx.beginPath();
       
    33     ctx.arc(37,37,13,Math.PI/7,-Math.PI/7,false);
       
    34     ctx.lineTo(34,37);
       
    35     ctx.fill();
       
    36 
       
    37     // blocks
       
    38     for(i=0;i<8;i++){
       
    39       ctx.fillRect(51+i*16,35,4,4);
       
    40     }
       
    41     for(i=0;i<6;i++){
       
    42       ctx.fillRect(115,51+i*16,4,4);
       
    43     }
       
    44     for(i=0;i<8;i++){
       
    45       ctx.fillRect(51+i*16,99,4,4);
       
    46     }
       
    47 
       
    48     // character 2
       
    49     ctx.beginPath();
       
    50     ctx.moveTo(83,116);
       
    51     ctx.lineTo(83,102);
       
    52 
       
    53     ctx.bezierCurveTo(83,94,89,88,97,88);
       
    54     ctx.bezierCurveTo(105,88,111,94,111,102);
       
    55     ctx.lineTo(111,116);
       
    56     ctx.lineTo(106.333,111.333);
       
    57     ctx.lineTo(101.666,116);
       
    58     ctx.lineTo(97,111.333);
       
    59     ctx.lineTo(92.333,116);
       
    60     ctx.lineTo(87.666,111.333);
       
    61     ctx.lineTo(83,116);
       
    62     ctx.fill();
       
    63     ctx.fillStyle = "white";
       
    64     ctx.beginPath();
       
    65     ctx.moveTo(91,96);
       
    66     ctx.bezierCurveTo(88,96,87,99,87,101);
       
    67     ctx.bezierCurveTo(87,103,88,106,91,106);
       
    68     ctx.bezierCurveTo(94,106,95,103,95,101);
       
    69     ctx.bezierCurveTo(95,99,94,96,91,96);
       
    70     ctx.moveTo(103,96);
       
    71     ctx.bezierCurveTo(100,96,99,99,99,101);
       
    72     ctx.bezierCurveTo(99,103,100,106,103,106);
       
    73     ctx.bezierCurveTo(106,106,107,103,107,101);
       
    74     ctx.bezierCurveTo(107,99,106,96,103,96);
       
    75     ctx.fill();
       
    76     ctx.fillStyle = "black";
       
    77     ctx.beginPath();
       
    78     ctx.arc(101,102,2,0,Math.PI*2,true);
       
    79     ctx.fill();
       
    80     ctx.beginPath();
       
    81     ctx.arc(89,102,2,0,Math.PI*2,true);
       
    82     ctx.fill();
       
    83   }