mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 16:15:10 +00:00
LibWeb: Add some basic path drawing functionality to the canvas element
This patch adds the following methods to CanvasRenderingContext2D: - beginPath() - moveTo(x, y) - lineTo(x, y) - closePath() - stroke() We also add the lineWidth property. :^)
This commit is contained in:
parent
60c2e41079
commit
0d93e249c3
6 changed files with 163 additions and 0 deletions
40
Base/home/anon/www/canvas-path.html
Normal file
40
Base/home/anon/www/canvas-path.html
Normal file
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head></title>
|
||||
<body>
|
||||
<canvas width=300 height=300></canvas>
|
||||
<script>
|
||||
|
||||
function drawHouse() {
|
||||
|
||||
var ctx = document.querySelectorAll("canvas")[0].getContext("2d");
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(0, 0, 300, 300);
|
||||
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.strokeStyle = 'red';
|
||||
|
||||
// Set line width
|
||||
ctx.lineWidth = 10;
|
||||
|
||||
// Wall
|
||||
ctx.strokeRect(75, 140, 150, 110);
|
||||
|
||||
// Door
|
||||
ctx.fillRect(130, 190, 40, 60);
|
||||
|
||||
// Roof
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(50, 140);
|
||||
ctx.lineTo(150, 60);
|
||||
ctx.lineTo(250, 140);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
|
||||
}
|
||||
|
||||
drawHouse();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue