All Projects → steveruizok → Perfect Arrows

steveruizok / Perfect Arrows

Licence: mit
Draw perfect arrows between points and shapes.

Programming Languages

typescript
32286 projects
HTML
75241 projects

Projects that are alternatives of or similar to Perfect Arrows

Whitebophir
Online collaborative Whiteboard that is simple, free, easy to use and to deploy
Stars: ✭ 821 (-61.62%)
Mutual labels:  draw
Mopaint
🎨💪 Modern, modular paint and more! (pre-alpha, not much done yet)
Stars: ✭ 50 (-97.66%)
Mutual labels:  draw
Generating Devanagari Using Draw
PyTorch implementation of DRAW: A Recurrent Neural Network For Image Generation trained on Devanagari dataset.
Stars: ✭ 82 (-96.17%)
Mutual labels:  draw
React Planner
✏️ A React Component for plans design. Draw a 2D floorplan and navigate it in 3D mode.
Stars: ✭ 846 (-60.45%)
Mutual labels:  draw
Rnn Vae
Variational Autoencoder with Recurrent Neural Network based on Google DeepMind's "DRAW: A Recurrent Neural Network For Image Generation"
Stars: ✭ 39 (-98.18%)
Mutual labels:  draw
Download
UI mod for Dota 2 Auto Chess that adds several QoL improvements to the UI
Stars: ✭ 65 (-96.96%)
Mutual labels:  draw
Doodle
Image doodle for Android, with functions such as undo, zoom, move, text, image, etc. Also a powerful, customizable and extensible doodle framework & multi-function drawing board. Android图片涂鸦,具有撤消,缩放,移动,添加文字,贴图等功能。还是一个功能强大,可自定义和可扩展的涂鸦框架、多功能画板。
Stars: ✭ 809 (-62.18%)
Mutual labels:  draw
React Native Sketch View
A React Native component for touch based drawing supporting iOS and Android.
Stars: ✭ 97 (-95.47%)
Mutual labels:  draw
System Alert Window Example
Example project showing use of SYSTEM_ALERT_WINDOW permission on Android 23+, with back button interception.
Stars: ✭ 39 (-98.18%)
Mutual labels:  draw
Touchable
Flutter library to add gestures and animations to each Shape you draw on your canvas in your CustomPainter
Stars: ✭ 82 (-96.17%)
Mutual labels:  draw
Jhdraw
draw line, draw dash line, draw star, draw rect, draw dash rect, gradientLayer 画线,画虚线,画五角星,画矩形,画虚线矩形,渐变色,椭圆(圆),圆角矩形
Stars: ✭ 35 (-98.36%)
Mutual labels:  draw
Shapeview
Draw your shapes without a sweat
Stars: ✭ 37 (-98.27%)
Mutual labels:  draw
Maker.js
📐⚙ 2D vector line drawing and shape modeling for CNC and laser cutters.
Stars: ✭ 1,185 (-44.6%)
Mutual labels:  draw
Unitydbgdraw
DbgDraw is an API that provides the ability to render various 2D and 3D shapes for visual debugging purposes.
Stars: ✭ 20 (-99.06%)
Mutual labels:  draw
D2dlib
A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
Stars: ✭ 84 (-96.07%)
Mutual labels:  draw
Echaloasuerte
Stars: ✭ 5 (-99.77%)
Mutual labels:  draw
Leaflet.draw.drag
Drag feature functionality for Leaflet.draw
Stars: ✭ 56 (-97.38%)
Mutual labels:  draw
Syntaxmeets
Syntaxmeets. Create rooms 🏠 Call your friends 👬🏼 Sip Chai, ☕ Chat, Create, and Code👨‍💻. A coding platform to code simultaneously 🚀 with your friends and design your algorithms on SyntaxPad.💫✨
Stars: ✭ 110 (-94.86%)
Mutual labels:  draw
Sketchpad
Sketchpad is fully customisable collaborative whiteboard plugin written in pure JavaScript.
Stars: ✭ 85 (-96.03%)
Mutual labels:  draw
Drawingboard
手绘板
Stars: ✭ 77 (-96.4%)
Mutual labels:  draw

Perfect Arrows

A set of functions for drawing perfect arrows between points and shapes.

Example

👉 Demo

Edit example

Other languages

Português (pt-BR)

Installation

npm i perfect-arrows

or

yarn add perfect-arrows

Usage

The functions in this library provide only the information needed to draw an arrow. You'll need to draw the arrow yourself using your technology of choice. See below for an example React component with SVG.

getArrow(x0, y0, x1, y1, options)

The getArrow function accepts the position of two points and returns an array containing information for:

  • three points: a start, end, and control point
  • three angles: an end, start, and center

You can use this information to draw an arc and arrow-heads. You can use the options object to tweak the return values.

const arrow = getArrow(0, 0, 100, 200, {
  bow: 0,
  stretch: 0.5,
  stretchMin: 0,
  stretchMax: 420,
  padStart: 0,
  padEnd: 0,
  flip: false,
  straights: true,
})

const [sx, sy, cx, cy, ex, ey, ae, as, sc] = arrow

Arguments

Argument Type Description
x0 number The x position of the starting point.
y0 number The y position of the starting point.
x1 number The x position of the ending point.
y1 number The y position of the ending point.
options object An (optional) object containing one or more of the options described below.

Options

Option Type Default Description
bow number 0 A value representing the natural bow of the arrow. At 0, all lines will be straight.
stretch number .5 The effect that the arrow's length will have, relative to its minStretch and maxStretch, on the bow of the arrow. At 0, the stretch will have no effect.
minStretch number 0 The length of the arrow where the line should be most stretched. Shorter distances than this will have no additional effect on the bow of the arrow.
maxStretch number 420 The length of the arrow at which the stretch should have no effect.
padStart number 0 How far the arrow's starting point should be from the provided start point.
padEnd number 0 How far the arrow's ending point should be from the provided end point.
flip boolean false Whether to reflect the arrow's bow angle.
straights boolean true Whether to use straight lines at 45 degree angles.

Returns

Argument Type Description
x0 number The x position of the (padded) starting point.
y0 number The y position of the (padded) starting point.
x1 number The x position of the (padded) ending point.
y1 number The y position of the (padded) ending point.
ae number The angle (in radians) for an ending arrowhead.
as number The angle (in radians) for a starting arrowhead.
ac number The angle (in radians) for a center arrowhead.

Example: A React Arrow Component

import * as React from "react"
import { getArrow } from "perfect-arrows"

export function PerfectArrow() {
  const p1 = { x: 64, y: 64 }
  const p2 = { x: 128, y: 96 }

  const arrow = getArrow(p1.x, p1.y, p2.x, p2.y, {
    padEnd: 20,
  })

  const [sx, sy, cx, cy, ex, ey, ae, as, ec] = arrow

  const endAngleAsDegrees = ae * (180 / Math.PI)

  return (
    <svg
      viewBox="0 0 720 480"
      style={{ width: 720, height: 480 }}
      stroke="#000"
      fill="#000"
      strokeWidth={3}
    >
      <circle cx={sx} cy={sy} r={4} />
      <path d={`M${sx},${sy} Q${cx},${cy} ${ex},${ey}`} fill="none" />
      <polygon
        points="0,-6 12,0, 0,6"
        transform={`translate(${ex},${ey}) rotate(${endAngleAsDegrees})`}
      />
    </svg>
  )
}

getBoxToBoxArrow(x0, y0, w0, h0, x1, y1, w1, h1, options)

The getBoxToBoxArrow function accepts the position and dimensions of two boxes (or rectangles) and returns an array containing information for:

  • three points: a start, end, and control point
  • three angles: an end, start, and center

You can use this information to draw an arc and arrow-heads. You can use the options object to tweak the return values.

Note: The options and values returned by getBoxToBoxArrow are in the same format as the options and values for getArrow.

const arrow = getBoxToBoxArrow(0, 0, 96, 128, 400, 200, 128, 96, {
  bow: 0,
  stretch: 0.5,
  stretchMin: 0,
  stretchMax: 420,
  padStart: 0,
  padEnd: 0,
  flip: false,
  straights: true,
})

const [sx, sy, cx, cy, ex, ey, ae, as, sc] = arrow

Arguments

Argument Type Description
x0 number The x position of the first rectangle.
y0 number The y position of the first rectangle.
w0 number The width of the first rectangle.
h0 number The height of the first rectangle.
x1 number The x position of the second rectangle.
y1 number The y position of the second rectangle.
w1 number The width of the second rectangle.
h1 number The height of the second rectangle.
options object An (optional) object containing one or more of the options described below.

Options

See options in getArrow above. (Both functions use the same options object.)

Returns

See returns in getArrow above. (Both functions return the same set of values.)

Example: A React Box-to-box Arrow Component

import * as React from "react"
import { getBoxToBoxArrow } from "perfect-arrows"

export function PerfectArrow() {
  const p1 = { x: 64, y: 64, w: 64, h: 64 }
  const p2 = { x: 128, y: 96, w: 64, h: 64 }

  const arrow = getBoxToBoxArrow(
    p1.x,
    p1.y,
    p1.w,
    p1.h,
    p2.x,
    p2.y,
    p2.w,
    p2.h,
    {
      bow: 0.2,
      stretch: 0.5,
      stretchMin: 40,
      stretchMax: 420,
      padStart: 0,
      padEnd: 20,
      flip: false,
      straights: true,
    }
  )

  const [sx, sy, cx, cy, ex, ey, ae, as, ec] = arrow

  const endAngleAsDegrees = ae * (180 / Math.PI)

  return (
    <svg
      viewBox="0 0 1280 720"
      style={{ width: 1280, height: 720 }}
      stroke="#000"
      fill="#000"
      strokeWidth={3}
    >
      <circle cx={sx} cy={sy} r={4} />
      <path d={`M${sx},${sy} Q${cx},${cy} ${ex},${ey}`} fill="none" />
      <polygon
        points="0,-6 12,0, 0,6"
        transform={`translate(${ex},${ey}) rotate(${endAngleAsDegrees})`}
      />
    </svg>
  )
}

Author

@steveruizok

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].