Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

canvas-webgl

БесплатноБез исполняемых скриптовНе проверен

Browser graphics via the Canvas 2D API, WebGL and creative-coding libraries. Covers React canvas setup, the 2D API, particle systems, pixel manipulation…

claude-dev-suiteот claude-dev-suite★ 51 звезда на GitHub

Об этом скилле

Canvas / WebGL Skill

Browser graphics via Canvas 2D API, WebGL, and creative coding libraries.

Canvas 2D — React Setup

import { useEffect, useRef } from "react";

function Canvas2D({ draw }: { draw: (ctx: CanvasRenderingContext2D, t: number) => void }) {
  const canvasRef = useRef<HTMLCanvasElement>(null);

  useEffect(() => {
    const canvas = canvasRef.current!;
    const ctx = canvas.getContext("2d")!;
    let raf: number;
    let start: number | null = null;

    // Retina scaling
    const dpr = window.devicePixelRatio || 1;
    canvas.width  = canvas.offsetWidth  * dpr;
    canvas.height = canvas.offsetHeight * dpr;
    ctx.scale(dpr, dpr);

    const loop = (ts: number) => {
      if (!start) start = ts;
      const elapsed = (ts - start) / 1000; // seconds
      ctx.clearRect(0, 0, canvas.offsetWidth, canvas.offsetHeight);
      draw(ctx, elapsed);
      raf = requestAnimationFrame(loop);
    };

    raf = requestAnimationFrame(loop);
    return () => cancelAnimationFrame(raf);
  }, [draw]);

  return <canvas ref={canvasRef} style={{ width: "100%", height: "100%" }} />;
}

Canvas 2D API Reference

Drawing

// Paths
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x, y);
ctx.arc(x, y, radius, startAngle, endAngle, counterclockwise?);
ctx.arcTo(x1, y1, x2, y2, radius);
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
ctx.quadraticCurveTo(cpx, cpy, x, y);
ctx.rect(x, y, w, h);
ctx.roundRect(x, y, w, h, radii); // Chrome 99+
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.clip();

// Shapes
ctx.fillRect(x, y, w, h);
ctx.strokeRect(x, y, w, h);
ctx.clearRect(x, y, w, h);

// Text
ctx.font = "bold 16px system-ui";
ctx.textAlign = "center";      // left | right | center | start | end
ctx.textBaseline = "middle";   // top | middle | alphabetic | bottom
ctx.fillText("text", x, y);
ctx.strokeText("text", x, y);
const metrics = ctx.measureText("text"); // .width, .actualBoundingBoxHeight

Styles

ctx.fillStyle = "#6366f1";
ctx.fillStyle = "rgba(99, 102, 241, 0.5)";
ctx.strokeStyle = "#fff";
ctx.lineWidth = 2;
ctx.lineCap = "round";      // butt | round | square
ctx.lineJoin = "round";     // miter | round | bevel
ctx.globalAlpha = 0.8;
ctx.globalCompositeOperation = "screen"; // multiply | screen | overlay | lighten | darken | etc.

// Gradient
const grad = ctx.createLinearGradient(0, 0, 200, 0);
grad.addColorStop(0, "#6366f1");
grad.addColorStop(1, "#a855f7");
ctx.fillStyle = grad;

// Radial gradient
const rGrad = ctx.createRadialGradient(cx, cy, rInner, cx, cy, rOuter);

// Pattern
const img = new Image(); img.src = "/pattern.png";
ctx.fillStyle = ctx.createPattern(img, "repeat")!;

Transforms

ctx.save();                          // push state
ctx.translate(x, y);
ctx.rotate(angle);                   // radians
ctx.scale(sx, sy);
ctx.transform(a, b, c, d, e, f);    // raw matrix
ctx.setTransform(a, b, c, d, e, f); // reset + set
ctx.restore();                       // pop state

Particle System Pattern

class Particle {
  x: number; y: number; vx: number; vy: number;
  life: number; maxLife: number; size: number; color: string;

  constructor(w: number, h: number) {
    this.x = Math.random() * w;
    this.y = Math.random() * h;
    this.vx = (Math.random() - 0.5) * 2;
    this.vy = (Math.random() - 0.5) * 2;
    this.maxLife = 60 + Math.random() * 120;
    this.life = this.maxLife;
    this.size = 2 + Math.random() * 4;
    this.color = `hsl(${220 + Math.random() * 60}, 80%, 65%)`;
  }

  update() {
    this.x += this.vx; this.y += this.vy; this.life--;
  }

  draw(ctx: CanvasRenderingContext2D) {
    const alpha = this.life / this.maxLife;
    ctx.save();
    ctx.globalAlpha = alpha;
    ctx.fillStyle = this.color;
    ctx.beginPath();
    ctx.arc(this.x, this.y, this.size * alpha, 0, Math.PI * 2);
    ctx.fill();
    ctx.restore();
  }

  isDead() { return this.life <= 0; }
}

// In animation loop:
particles = particles.filter(p => !p.isDead());
while (particles.length < 100) particles.push(new Particle(w, h));
particles.forEach(p => { p.update(); p.draw(ctx); });

Pixel Manipulation

// Read/write every pixel
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const data = imageData.data; // Uint8ClampedArray: [r,g,b,a, r,g,b,a, ...]

for (let i = 0; i < data.length; i += 4) {
  const r = data[i], g = data[i+1], b = data[i+2]; // a = data[i+3]
  const gray = 0.299 * r + 0.587 * g + 0.114 * b;
  data[i] = data[i+1] = data[i+2] = gray; // grayscale
}

ctx.putImageData(imageData, 0, 0);

OffscreenCanvas (Web Worker)

// main.ts
const worker = new Worker(new URL("./canvas.worker.ts", import.meta.url));
const offscreen = canvas.transferControlToOffscreen();
worker.postMessage({ canvas: offscreen }, [offscreen]);

// canvas.worker.ts
self.onmessage = (e) => {
  const canvas: OffscreenCanvas = e.data.canvas;
  const ctx = canvas.getContext("2d")!;
  // Heavy drawing here — doesn't block main thre
Полный SKILL.md на GitHub

Установить canvas-webgl в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Read
Grep
Glob
Write
Edit

FAQ

Что делает скилл canvas-webgl?

Browser graphics via the Canvas 2D API, WebGL and creative-coding libraries. Covers React canvas setup, the 2D API, particle systems, pixel manipulation, OffscreenCanvas in a worker, raw WebGL, p5.js and noise functions. USE WHEN: user mentions "canvas", "getContext('2d')", "WebGL", "p5.js", "particle system", "pixel manipulation", "OffscreenCanvas", asks about drawing or generative graphics in the browser DO NOT USE FOR: 3D scene graphs (use `three-js`), vector graphics and SVG (use `svg-animation`), DOM animation (use `framer-motion` or `gsap`)

Как установить скилл canvas-webgl?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл canvas-webgl запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить canvas-webgl с