Skip to content
Back to skills

Canvas Drag Rotation And Animation Optimization

ASecurity

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.

  • 581 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
educationjavascriptjavaperformance

Works with

  • cli

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill canvas-drag-rotation-and-animation-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Canvas Drag Rotation And Animation Optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Canvas Drag Rotation And Animation Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-canvas-drag-rotation-and-animation-optimization/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-canvas-drag-rotation-and-animation-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "58148c95-f72c-4eca-ba87-88bf1a0e0015"
name: "Canvas Drag Rotation and Animation Optimization"
description: "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."
version: "0.1.0"
tags:
  - "javascript"
  - "canvas"
  - "animation"
  - "mouse-events"
  - "performance"
triggers:
  - "fix mouse dragging canvas rotation"
  - "canvas rotation resets on reclick"
  - "prevent buffer overflow in canvas animation"
  - "optimize canvas animation loop"
---

# 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
1. **Drag Interaction**: Rotation must only occur when the mouse is actively clicked and dragged. Do not rotate on simple mouse movement without a click.
2. **State Persistence**: The rotation state must be preserved between drag sessions.
   - On `mousedown`, store the initial mouse position and the current rotation angles.
   - On `mousemove` (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.
   - Ensure the view does not reset when the mouse is clicked again.
3. **Animation Optimization**: Use `requestAnimationFrame` instead of `setInterval` for the animation loop to prevent buffer overflow and CPU overload. The loop should call update and draw functions recursively.

# Anti-Patterns
- Do not reset the rotation state to zero or a default value on subsequent clicks.
- Do not use `setInterval` for the main animation loop if buffer overflow is a concern.

## Triggers

- fix mouse dragging canvas rotation
- canvas rotation resets on reclick
- prevent buffer overflow in canvas animation
- optimize canvas animation loop

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.