Friday, April 4, 2014

NIIT HTML Q3 ACTIVITY BOOK CHAPTER 6 Smiley face

Q3) You have been assigned a task to create a smiley on canvas. the face of the smiley
     should be colored in yellow, with eye balls colored in blue, and month outline in red, as shown in the following  figure. How will you perform this task?

Ans3)

<!Doctype HTML><html>
<head>
</head>
<body>
<canvas id="canvas" width='500' height="500"></canvas>
<script>
var ctc=document.getElementById("canvas");
var ctx=ctc.getContext("2d");
ctx.beginPath();
ctx.arc(150, 150, 100, 0, 2 * Math.PI, false);
ctx.closePath();
ctx.fillStyle="gold";
ctx.stroke();
ctx.fill();

ctx.beginPath();
ctx.arc(120, 130, 20, 0, 2 * Math.PI, false);
ctx.closePath();
ctx.fillStyle = "white";
ctx.stroke();
ctx.fill();


ctx.beginPath();
ctx.arc(123, 133, 4, 0, 2 * Math.PI, false);
ctx.closePath();
ctx.fillStyle="blue";
ctx.stroke();
ctx.fill();


ctx.beginPath();
ctx.arc(180, 130, 20, 0, 2 * Math.PI, false);
ctx.closePath();
ctx.fillStyle = "white";
ctx.stroke();
ctx.fill();


ctx.beginPath();
ctx.arc(183, 133, 4, 0, 2 * Math.PI, true);
ctx.closePath();
ctx.fillStyle = "blue";
ctx.stroke();
ctx.fill();

ctx.beginPath();
ctx.arc(155, 165, 60, 0, 3, false);
ctx.closePath();
ctx.lineWidth = 5;
ctx.strokeStyle = "red";
ctx.fillStyle = "white";
ctx.stroke();
ctx.fill();

</script>
</body>
</html>

No comments:

Post a Comment