Professional Documents
Culture Documents
Lab 5
Lab 5
VI SEMESTER
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title> Khush</title>
<style>
#canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id="canvas" width="700" height="380"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.rect(110, 50, 50, 50);
ctx.stroke();
ctx.fillStyle = "#0071d7";
ctx.fill();
ctx.beginPath();
ctx.rect(50, 110, 50, 50);
ctx.stroke();
ctx.fillStyle = "#0071d7";
ctx.fill();
ctx.beginPath();
ctx.rect(110, 110, 50, 50);
ctx.stroke();
ctx.fillStyle = "#0071d7";
ctx.fill();
ctx.beginPath();
ctx.rect(110, 200, 50, 50);
ctx.fillStyle = "#7FBA00";
ctx.fill();
ctx.beginPath();
ctx.rect(50, 260, 50, 50);
ctx.fillStyle = "#00A4EF";
ctx.fill();
ctx.beginPath();
ctx.rect(110, 260, 50, 50);
ctx.fillStyle = "#FFB900";
ctx.fill();
Q.2 Draw the House Painting of your own choice using HTML Canvas.
Output:
.
Code:
<!DOCTYPE html>
<html>
<head>
<title> Khush</title>
<style>
#canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id="canvas" width="500" height="380"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.moveTo(175,200);
ctx.lineTo(225,200);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(200,175);
ctx.lineTo(200,225);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(275,200);
ctx.lineTo(325,200);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(300,175);
ctx.lineTo(300,225);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(75, 150);
ctx.lineTo(30, 300);
ctx.lineTo(120, 300);
ctx.closePath();
ctx.stroke();
ctx.fillStyle = "green";
ctx.fill();
ctx.beginPath();
ctx.moveTo(425, 150);
ctx.lineTo(470, 300);
ctx.lineTo(380, 300);
ctx.closePath();
ctx.stroke();
ctx.fillStyle = "green";
ctx.fill();
</script>
</body>
</html>