Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions simple-canvas/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,20 @@
<body>
<canvas id="canvas" width="600" height="600"></canvas>

<script>
const canvas = document.getElementById("canvas");

const ctx = canvas.getContext("2d");

// Function to draw a rectangle on the canvas
const drawRectangle = (x, y, width, height) => {
ctx.fillStyle = "#222";
ctx.fillRect(x, y, width, height);
}

// Function to draw the circle
const drawCircle = (x, y, radius, start, end = Math.PI * 2) => {
ctx.beginPath();
ctx.arc(x, y, radius, start, end);
ctx.stroke();
}
<script src="js_library/Shapes.js"></script>

<script>
// Call the rectangle function
drawRectangle(20, 20, 100, 100);

// Call Semi Circle function
drawSemiCircle(500, 50, 60, 0, "#555", 7);

// Call the circle function
drawCircle(canvas.width / 2, canvas.height / 2, 120, 0);

// Call the trapezium function
drawTrapezium(200, 200, 400, 200, 250, 350, 50, 350, 200, 200);
</script>
</body>
</html>