canvas and svg example

by REPLY2SAGAR

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Canvas and SVG Example</title>
    <script>
        window.onload = function() {
            var canvas = document.getElementById('myCanvas');
            var ctx = canvas.getContext('2d');
            
            // Draw a blue rectangle
            ctx.fillStyle = '#0000ff';
            ctx.fillRect(10, 10, 150, 100);

            // Draw a red line
            ctx.beginPath();
            ctx.moveTo(10, 120);
            ctx.lineTo(160, 120);
            ctx.strokeStyle = '#ff0000';
            ctx.lineWidth = 5;
            ctx.stroke();
        };
    </script>
</head>
<body>
    <h1>Canvas and SVG Demo</h1>

    <h2>Canvas Example</h2>
    <canvas id="myCanvas" width="200" height="200" style="border:1px solid #000000;">
        Your browser does not support the canvas element.
    </canvas>

    <h2>SVG Example</h2>
    <svg width="200" height="200">
        <!-- Draw a yellow rectangle -->
        <rect x="10" y="10" width="150" height="100" fill="yellow" stroke="black" stroke-width="2"/>

        <!-- Draw a green circle -->
        <circle cx="100" cy="150" r="40" fill="green"/>
        
        <!-- Draw text -->
        <text x="50" y="50" font-family="Verdana" font-size="20" fill="red">SVG Text</text>
    </svg>
</body>
</html>