[ create a new paste ] login | about

Link: http://codepad.org/qCTghFQA    [ raw code | fork ]

C, pasted on Nov 19:
 // Create a timer
 var index = -250;
 timer1 = setInterval(renderLoop, 16);

 function renderLoop() 
 {
   if (index > 600) index = -250;
   index += 4;
   draw(index);
 }

 function draw(x) 
 {
   ctx.fillStyle = "black";
   ctx.fillRect(0, 0, 400, 500);

   // Create a clipping region
   ctx.save();
   ctx.beginPath();
   ctx.arc(x, x, 200, 0, Math.PI * 2, true);
   ctx.clip();

   // Create a white background
   ctx.fillStyle = "white";
   ctx.fillRect(0, 0, 400, 500);
 
   // Draw smiley
   drawSmiley();
  
   // Restore state
   ctx.restore();
 }         

 function drawSmiley()
 {
    if (!isNaN(video.duration))
    {
      // Play the video
      video.play();
      
      // Draw the video
      ctx.drawImage(video, 0, 0, 400, 500);
    }
   // Draw eye
   ctx.lineWidth = 20;
   ctx.strokeStyle = "orange";
   ctx.beginPath();
   ctx.moveTo(230, 130);
   ctx.bezierCurveTo(230, 130, 230, 130, 230, 210);
   ctx.stroke();
 
   // Draw eye
   ctx.beginPath();
   ctx.moveTo(170, 130);
   ctx.bezierCurveTo(170, 130, 170, 130, 170, 210);
   ctx.stroke();

   // Draw smile
   ctx.beginPath();
   ctx.moveTo(100, 230);
   ctx.bezierCurveTo(100, 230, 200, 380, 300, 230);
   ctx.stroke();

   // Draw tongue
   ctx.beginPath();
   ctx.moveTo(219, 298);
   ctx.bezierCurveTo(278, 351, 315, 315, 277, 258);
   ctx.stroke();
 }                     


Create a new paste based on this one


Comments: