UNPKG

@tsparticles/interaction-external-grab

Version:

tsParticles grab external interaction

16 lines (15 loc) 688 B
import { getStyleFromRgb } from "@tsparticles/engine"; import { drawLine } from "@tsparticles/canvas-utils"; const defaultWidth = 0; export function drawGrabLine(context, width, begin, end, colorLine, opacity, hdr = false) { drawLine(context, begin, end); context.strokeStyle = getStyleFromRgb(colorLine, hdr, opacity); context.lineWidth = width; context.stroke(); } export function drawGrab(container, particle, lineColor, opacity, mousePos) { container.canvas.render.draw(ctx => { const beginPos = particle.getPosition(); drawGrabLine(ctx, particle.retina.linksWidth ?? defaultWidth, beginPos, mousePos, lineColor, opacity, container.hdr); }); }