JSFiddle - React, Tailwind, and code Playground
by m1erickson
HTML
<p>A thicker oval with a less contrasting background</p>
<canvas id="canvas" width=350 height=350></canvas>
CSS
body {
background-color: ivory;
}
#canvas {
border:1px solid red;
}
JavaScript
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var cx = 180;
var cy = 200;
var w = 300;
var h = 250;
// Start with a less-contrasting background
ctx.fillStyle = "#ddd";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
var lx = cx - w / 2,
rx = cx + w / 2,
ty = cy - h / 2,
by = cy + h / 2;
var magic = 0.551784;
var xmagic = magic * w / 2;
var ymagic = h * magic / 2;
ctx.moveTo(cx, ty);
ctx.bezierCurveTo(cx + xmagic, ty, rx, cy - ymagic, rx, cy);
ctx.bezierCurveTo(rx, cy + ymagic, cx + xmagic, by, cx, by);
ctx.bezierCurveTo(cx - xmagic, by, lx, cy + ymagic, lx, cy);
ctx.bezierCurveTo(lx, cy - ymagic, cx - xmagic, ty, cx, ty);
ctx.fillStyle = "#555";
ctx.strokeStyle = ctx.fillStyle;
ctx.lineWidth = 1.5;
ctx.stroke();