Spot the Bug answer: The canvas element’s drawing buffer resolution is not set, causing it to default to 300x150 pixels despite the CSS styling.
The fix:
Set the width and height attributes directly on the canvas element: cv.width = 300; cv.height = 300;
Why:
The HTML canvas element has two sizes: one set by CSS for display and one for its internal drawing buffer. If the internal drawing buffer dimensions are not explicitly set via the width and height attributes, it defaults to 300x150 pixels. When the CSS then scales this 300x150 buffer to a 300x300 display area, the content appears stretched.
wait, this is a classic! I remember running into this exact thing when I was messing around with some audio visualizers years ago.
it’s such a subtle distinction between the CSS size and the actual drawing buffer. you think you’ve got it all set up and then boom, everything’s pixelated.