Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
sebmarkbage committed Feb 3, 2011

Verified

This commit was signed with the committer’s verified signature.
0 parents commit f27a754
Showing 5 changed files with 151 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Demos/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Morph Demo</title>
</head>
<body>
<script src="../../mootools-core-1.3.js" type="text/javascript"></script>
<script src="../../art/Color/Source/Color.js" type="text/javascript"></script>
<script src="../../art/Source/ART.js" type="text/javascript"></script>
<script src="../../art/Source/ART.Path.js" type="text/javascript"></script>
<script src="../../art/Source/ART.VML.js" type="text/javascript"></script>
<script src="../../art/Source/ART.SVG.js" type="text/javascript"></script>
<script src="../../art/Source/ART.Base.js" type="text/javascript"></script>
<script src="../../art/Source/ART.Shapes.js" type="text/javascript"></script>
<script src="../../art/Source/ART.Font.js" type="text/javascript"></script>
<script src="../Source/ART.Path.Morph.js" type="text/javascript"></script>
<script src="morph.js" type="text/javascript"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions Demos/morph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var canvas = new ART(1000, 1000);

var square = new ART.Path()
.move(0,0)
.line(100,0)
.line(0,100)
.line(-100,0)
.close();

var circle = new ART.Path()
.moveTo(50,0)
.arc(0,100, 50)
.arc(0,-100, 50)
.close();

var morph = new ART.Path.Morph(square, circle);

var shape = new ART.Shape()
.fill('#F00')
.inject(canvas);

var fx = new Fx({ duration: 4000 });
fx.set = function(delta){
shape.draw(morph.compute(delta));
};
fx.start(0, 1);

canvas.inject(document.body);
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ART Path Morph
==============
Plugin for ART that allow you to morph between two paths.
80 changes: 80 additions & 0 deletions Source/ART.Path.Morph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
---
name: ART.Path.Morph
description: "Morph between two paths."
provides: ART.Path.Morph
requires: ART/ART.Path
...
*/

(function(){

var newPath;

function move(sx, sy, x, y){
newPath.push('M', x, y);
};

function line(sx, sy, x, y){
newPath.push('C', sx, sy, x, y, x, y);
};

function curve(sx, sy, p1x, p1y, p2x, p2y, x, y){
newPath.push('C', p1x, p1y, p2x, p2y, x, y);
};

ART.Path.Morph = new Class({

initialize: function(from, to){
this.from = newPath = new ART.Path();
from.visit(line, curve, null, move);
this.to = newPath = new ART.Path();
to.visit(line, curve, null, move);
newPath = null;

this.current = new ART.Path();

var f = this.from.path, t = this.to.path, c = this.current.path, x, y;

for (var i = 0; i < f.length || i < t.length; i++){
if (i == f.length){
x = f[i - 1][5];
y = f[i - 1][6];
f.splice(i, 0, ['C', x, y, x, y, x, y]);
} else if (i == t.length){
x = t[i - 1][5];
y = t[i - 1][6];
f.splice(i, 0, ['C', x, y, x, y, x, y]);
} else if (f[i][0] == 'M'){
if (t[i][0] == 'C'){
x = f[i - 1][5];
y = f[i - 1][6];
f.splice(i, 0, ['C', x, y, x, y, x, y]);
}
} else if (t[i][0] == 'M'){
x = t[i - 1][5];
y = t[i - 1][6];
f.splice(i, 0, ['C', x, y, x, y, x, y]);
}
var m = new Array(f[i].length);
m[0] = f[i][0];
c.push(m);
}
},

compute: function(delta){
var f = this.from.path, t = this.to.path, c = this.current.path;
for (var i = 0, l = c.length; i < l; i++){
var fi = f[i], ti = t[i], ci = c[i];
for (var j = 1; j < ci.length; j++){
ci[j] = (ti[j] - fi[j]) * delta + fi[j];
}
}
this.current.cache = {};
return this.current;
}

});


})();
21 changes: 21 additions & 0 deletions license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2010 Calyptus Life AB <http://calyptus.eu>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

0 comments on commit f27a754

Please sign in to comment.