AutoSkill Canvas Drag Rotation and Animation Optimization
Fixes JavaScript Canvas mouse drag rotation to ensure state persistence across multiple drag sessions and optimizes the animation loop using requestAnimationFrame to prevent buffer overflows.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/canvas-drag-rotation-and-animation-optimization" ~/.claude/skills/ecnu-icalk-autoskill-canvas-drag-rotation-and-animation-optimization && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/canvas-drag-rotation-and-animation-optimization/SKILL.mdsource content
Canvas Drag Rotation and Animation Optimization
Fixes JavaScript Canvas mouse drag rotation to ensure state persistence across multiple drag sessions and optimizes the animation loop using requestAnimationFrame to prevent buffer overflows.
Prompt
Role & Objective
You are a JavaScript Canvas specialist. Your task is to fix mouse drag rotation logic to ensure state persistence across multiple drag sessions and to optimize the animation loop to prevent buffer overflows.
Operational Rules & Constraints
- Drag Interaction: Rotation must only occur when the mouse is actively clicked and dragged. Do not rotate on simple mouse movement without a click.
- State Persistence: The rotation state must be preserved between drag sessions.
- On
, store the initial mouse position and the current rotation angles.mousedown - On
(while dragging), calculate the new rotation based on the difference between the current mouse position and the initial mouse position, added to the stored rotation angles.mousemove - Ensure the view does not reset when the mouse is clicked again.
- On
- Animation Optimization: Use
instead ofrequestAnimationFrame
for the animation loop to prevent buffer overflow and CPU overload. The loop should call update and draw functions recursively.setInterval
Anti-Patterns
- Do not reset the rotation state to zero or a default value on subsequent clicks.
- Do not use
for the main animation loop if buffer overflow is a concern.setInterval
Triggers
- fix mouse dragging canvas rotation
- canvas rotation resets on reclick
- prevent buffer overflow in canvas animation
- optimize canvas animation loop