No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
test
.gitignore
LICENSE
README.md
index.js
package.json

README.md

Stretch Transform

Stretch Transform is a geometric transformation that distorts a plane in a rubbery way.

For a more detailed explanation of this project read this on my website.

Reference

StretchTransform

new StretchTransform() create an empty StretchTransform.

addAnchor

Adds an Anchor.

Parameters

  • x Number X coordinate for origin and target position
  • y Number Y coordinate for origin and target position

addAnchor

Adds an Anchor.

Parameters

  • xOrigin Number X coordinate for origin position
  • yOrigin Number Y coordinate for origin position
  • xTarget Number X coordinate for target position
  • yTarget Number Y coordinate for target position

addAnchor

Adds an Anchor.

Parameters

  • pOrigin Array Array [x, y] for origin position
  • pTarget Array Array [x, y] for target position

addAnchor

Adds an Anchor.

Parameters

  • p Array Array [x, y] that will be used for origin and target position

removeAnchor

Removes an Anchor.

Parameters

  • anchor Anchor Anchor to remove

removeAnchor

Removes an Anchor.

Parameters

  • i Number Index of the anchor

getAnchorCount

Returns Number of anchors added to the MultiTransform

getAnchor

Parameters

  • i Number Index of the anchor to return.

getAnchorByPos

Parameters

  • x Number x coordinate of the origin or target position of the anchor to return.
  • y Number y coordinate of the origin or target position of the anchor to return.
  • tolerance Number Radius around Anchor

Returns Number Index of the found anchor or -1 if nothing was found at the specified position

getAnchorByOriginPos

Parameters

  • x Number x coordinate of the origin position of the anchor to return.
  • y Number y coordinate of the origin position of the anchor to return.
  • tolerance Number Radius around Anchor

Returns Number Index of the found anchor or -1 if nothing was found at the specified position

getAnchorByTargetPos

Parameters

  • x Number x coordinate of the target position of the anchor to return.
  • y Number y coordinate of the target position of the anchor to return.
  • tolerance Number Radius around Anchor

Returns Number Index of the found anchor or -1 if nothing was found at the specified position

setAnchorOrigin

Parameters

  • i Number Index of the anchor.
  • x Number New x coordinate of the origin position.
  • y Number New y coordinate of the origin position.

setAnchorTarget

Parameters

  • i Number Index of the anchor.
  • x Number New x coordinate of the target position.
  • y Number New y coordinate of the target position.

setWeightingMode

Parameters

  • weightingMode String String, either 'simple' or 'directional'.

isSimple

Returns Boolean true, if weightingMode is SIMPLE

isDirectional

Returns Boolean true, if weightingMode is DIRECTIONAL

getWeightingExponent1

Returns Number

setWeightingExponent1

Exponent of the weighting function. Defines how the relations from one anchor to all others are cumulated. The closer the other anchor lies, the stronger it is weighted.

Parameters

  • val Number Usually something between 0 and 2. Default = 1.

getWeightingExponent2

Returns Number

setWeightingExponent2

Exponent of the weighting function when applying all anchor matrices to a point.

Parameters

  • val Number Usually 1 or higher. Default = 2.

getWeightingExponent3

Returns Number

setWeightingExponent3

Exponent of the weighting function that factors in, if the direction from anchor to point and from one anchor to another is quite similar. Only applicable when weightingMode is DIRECTIONAL.

Parameters

  • val Number Usually something between 0 and 2. Default = 1.

transform

Main function of the class. Transforms a point on the plane and returns its new position.

Parameters

  • x Number X coordinate of the point to be transformed
  • y Number Y coordinate of the point to be transformed

Returns Array Transformed point as an Array [x, y]

transform

Main function of the class. Transforms a point on the plane and returns its new position.

Parameters

  • p Array Point given as an Array [x, y] to be transformed

Returns Array Transformed point as an Array [x, y]

updateAnchorMatrices

It's usually not necessary to call this method. If anchors and parameters are always set with the given methods (setAnchorOrigin(), ...), this method will be called automatically. It calculates a transformation matrix for each anchor. This matrix reflects the translation of the anchor and the rotation and scaling depending on the (possibly) changed positions of all other anchors.