Skip to content

Commit

Permalink
Merge pull request #631 from tidalcycles/fix-canvas-resize
Browse files Browse the repository at this point in the history
fix: update canvas size on window resize
  • Loading branch information
felixroos committed Jun 30, 2023
2 parents fbc73bc + 1b85aa7 commit f078599
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/core/draw.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export const getDrawContext = (id = 'test-canvas') => {
canvas.height = window.innerHeight;
canvas.style = 'pointer-events:none;width:100%;height:100%;position:fixed;top:0;left:0';
document.body.prepend(canvas);
let timeout;
window.addEventListener('resize', () => {
timeout && clearTimeout(timeout);
timeout = setTimeout(() => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}, 200);
});
}
return canvas.getContext('2d');
};
Expand Down
5 changes: 3 additions & 2 deletions packages/core/spiral.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ Pattern.prototype.spiral = function (options = {}) {
} = options;

function spiral({ ctx, time, haps, drawTime }) {
ctx.clearRect(0, 0, ctx.canvas.clientWidth, ctx.canvas.clientHeight);
const [cx, cy] = [ctx.canvas.width / 2, ctx.canvas.height / 2];
const [w, h] = [ctx.canvas.width, ctx.canvas.height];
ctx.clearRect(0, 0, w * 2, h * 2);
const [cx, cy] = [w / 2, h / 2];
const settings = {
margin: size / stretch,
cx,
Expand Down

0 comments on commit f078599

Please sign in to comment.