-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: shape morphing with non-matching points
Closes #5.
- Loading branch information
1 parent
9f02b64
commit 1e39925
Showing
11 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
client.dist.js | ||
node_modules/ | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Wilderness morph example | ||
|
||
## Usage | ||
|
||
``` | ||
npm install | ||
npm run build | ||
``` | ||
|
||
Then open `index.html` in your browser. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { shape, render, play } from '../../src'; | ||
|
||
const from = { | ||
type: 'circle', | ||
cx: 25, | ||
cy: 25, | ||
r: 25, | ||
fill: '#E54', | ||
}; | ||
|
||
const to = { | ||
type: 'path', | ||
d: 'M75,75l10-5l15,20v10h-10l-5-5l-10,5z', | ||
moveIndex: 1, | ||
reverse: true, | ||
}; | ||
|
||
const animation = shape( from, to ); | ||
|
||
render({ selector: '.svg' }, animation ); | ||
|
||
play( animation, { | ||
alternate: true, | ||
duration: 2000, | ||
iterations: Infinity, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Wilderness morph example</title> | ||
<style> | ||
html, | ||
body { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
} | ||
|
||
.svg { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<svg | ||
class="svg" | ||
height="100" | ||
preserveAspectRatio="xMidYMid meet" | ||
viewBox="0 0 100 100" | ||
width="100" | ||
> | ||
</svg> | ||
<script src="./client.dist.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"author": { | ||
"name": "Colin Meinke", | ||
"email": "hello@colinmeinke.com", | ||
"url": "www.colinmeinke.com" | ||
}, | ||
"babel": { | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
], | ||
"presets": [ | ||
"es2015" | ||
] | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/colinmeinke/wilderness/issues" | ||
}, | ||
"description": "Wilderness morph example", | ||
"devDependencies": { | ||
"babel-plugin-transform-object-rest-spread": "^6.8.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babelify": "^7.3.0", | ||
"browserify": "^13.0.1" | ||
}, | ||
"license": "ISC", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/colinmeinke/wilderness.git" | ||
}, | ||
"scripts": { | ||
"build": "browserify ./client.js -o ./client.dist.js -t babelify" | ||
}, | ||
"version": "0.0.0-semantically-released" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Wilderness basic example | ||
# Wilderness playback example | ||
|
||
## Usage | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { add, cubify, remove } from 'points'; | ||
|
||
const addCurves = ( a, b ) => { | ||
const c = []; | ||
|
||
for ( let i = 0, l = a.length; i < l; i++ ) { | ||
if ( !a[ i ].curve && b[ i ].curve ) { | ||
c.push({ ...a[ i ], curve: { | ||
type: 'cubic', | ||
x1: a[ i - 1 ].x, | ||
y1: a[ i - 1 ].y, | ||
x2: a[ i ].x, | ||
y2: a[ i ].y, | ||
}}); | ||
} else { | ||
c.push( a[ i ]); | ||
} | ||
} | ||
|
||
return c; | ||
} | ||
|
||
const normaliseCurves = ( a, b ) => ([ addCurves( a, b ), addCurves( b, a )]); | ||
|
||
const normalisePoints = ( a, b ) => { | ||
let c = cubify( remove( a )); | ||
let d = cubify( remove( b )); | ||
|
||
if ( d.length > c.length ) { | ||
c = add( c, d.length ); | ||
} else if ( c.length > d.length ) { | ||
d = add( d, c.length ); | ||
} | ||
|
||
return normaliseCurves( c, d ); | ||
}; | ||
|
||
const normalise = ( a, b ) => { | ||
const [ c, d ] = normalisePoints( a.points, b.points ); | ||
return [{ ...a, points: c }, { ...b, points: d }]; | ||
}; | ||
|
||
export default normalise; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters