Skip to content

Commit 87327eb

Browse files
committed
Hydra - improve resize behaviour
1 parent 5f7365f commit 87327eb

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

server/priv/static/hydra.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
canvas.width = width;
130130
canvas.height = height;
131131

132+
// Save the current sketch if it exists
133+
const currentSketch = window.currentSketch;
134+
132135
// Reinitialize Hydra with new dimensions
133136
hydra = new Hydra({
134137
canvas: canvas,
@@ -138,8 +141,19 @@
138141
height: height
139142
});
140143

141-
// Rerun the current sketch
142-
runDefaultSketch();
144+
// Immediately restore the sketch if it existed
145+
if (currentSketch) {
146+
try {
147+
eval(currentSketch);
148+
} catch (e) {
149+
console.error('Error restoring sketch after resize:', e);
150+
// Fall back to default sketch if restoration fails
151+
runDefaultSketch();
152+
}
153+
} else {
154+
// No custom sketch was running, use default
155+
runDefaultSketch();
156+
}
143157
});
144158
</script>
145159
</body>

0 commit comments

Comments
 (0)