mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 13:05:07 +00:00

This implements only one of the two forms of this function, ctx.fill(winding_rule). Also tweaks the quadratic curve demo to have a nice looking filled shape.
56 lines
1,001 B
HTML
56 lines
1,001 B
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>canvas path - quadratic curve example</title>
|
|
</head>
|
|
<body>
|
|
<canvas width=500 height=500></canvas>
|
|
<script>
|
|
|
|
function drawSomeCurves() {
|
|
|
|
var canvas = document.querySelectorAll("canvas")[0];
|
|
var ctx = canvas.getContext("2d");
|
|
var x = 150;
|
|
var y = 150;
|
|
|
|
canvas.addEventListener("mousedown", function(e) {
|
|
x = e.offsetX;
|
|
y = e.offsetY;
|
|
});
|
|
|
|
canvas.addEventListener("mousemove", function(e) {
|
|
ctx.beginPath();
|
|
ctx.fillStyle = 'white';
|
|
ctx.fillRect(0, 0, 500, 500);
|
|
|
|
ctx.strokeStyle = 'red';
|
|
|
|
ctx.lineWidth = 1;
|
|
|
|
ctx.fillRect(0, 0, 500, 500);
|
|
|
|
ctx.moveTo(0, 0);
|
|
ctx.quadraticCurveTo(e.offsetX, e.offsetY, x, y);
|
|
ctx.stroke();
|
|
|
|
ctx.moveTo(30, 90);
|
|
ctx.lineTo(110, 20);
|
|
ctx.lineTo(240, 130);
|
|
ctx.lineTo(60, 130);
|
|
ctx.lineTo(190, 20);
|
|
ctx.lineTo(270, 90);
|
|
ctx.closePath();
|
|
|
|
// Fill path
|
|
ctx.fillStyle = 'green';
|
|
ctx.fill('evenodd');
|
|
});
|
|
|
|
}
|
|
|
|
drawSomeCurves();
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|