Будиночок
Створення зображень в <canvas>
by oleksandr_s
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Будиночок</title>
</head>
<body>
<center><canvas id="canvas" width="800" height="500" style="background: lightgrey; margin-left: 2px; margin-top: 2px"></canvas>
<p><input type="button" value="Побудувати" onclick="draw()"></p></center>
<script type="text/javascript" src="house.js"></script>
</body>
</html>
JavaScript
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
function draw(){
ctx.beginPath();
ctx.fillStyle = "green";
ctx.rect(290, 260, 200, 200);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = "maroon";
ctx.moveTo(275, 260);
ctx.lineTo(390, 150);
ctx.lineTo(505, 260);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = "yellow";
ctx.rect(350, 310, 80, 80);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = "black";
ctx.moveTo(390, 310);
ctx.lineTo(390, 390);
ctx.moveTo(350, 350);
ctx.lineTo(430, 350);
ctx.fill();
ctx.stroke();
}