I finally found a time to play with the canvas capability of iPhone's browser. I have started with a set of simple benchmark programs to see the animation capability of iPhone, but I eventually came up with a javascript library, ianime.js, which allows me to add wide ranges of animations to my web pages easily.
Note on cross-browser comaptibility: Because this is a javascript library for iPhone, making it compatible with other browsers is not important - I rather optimize it for iPhone. At this moment, it does not run on IE because it heavily relies on <canvas> tag, and runs well on latest version of Firefox and Safari (I am testing them only on Mac). I would like to keep the compatibility with those two browsers as much as possible, as long as I don't need to sacrifice the performance under iPhone browser.
If you wants to see the actual demos on your iPhone or iPod touch first, go to the following URL, and click links to sample pages.
http://satoshi.blogs.com/ianime/
Animating an image from one location to another is quite straightforward. You need to place an image tag with "position:absolute" style, create an iAnime object when the page is loaded, then call "iAnime::add" function with appropriate parameters (image, new location, and duration) when you want to start the animation. Here is an example.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=320; user-scalable=0;"/>
<script src="ianime010.js"></script>
<script type="text/javascript">
var anime;function init() {
anime = new iAnime();
}function click(obj) {
param = { element:obj, x:(300-obj.offsetLeft), y:obj.offsetTop, msec:1000 };
anime.add(param);
}
</script>
</head>
<body onload="init()" style="margin:0">
<img src="images/feed-icon-28x28.png" onclick="click(this)"
style="position:absolute; left:20px; top:20px" />
</body>
</html>
Note that you need to package parameters into a hash object. The "element" specifies the image object to be animated, "x" and "y" specifies the new location, and the "msec" specifies the duration. Those four parameters are required.
I pasted this sample in <iframe>, which is supposed to run if you are running latest version of Safari or Firefox. Click the feed icon to see how it works. After the animation, you may click it again to animate it back to the original location.
The example above moves the specified image at a constant speed. You can control the speed by providing a callback function, which maps value between 0.0 and 1.0 to another value between 0.0 and 1.0.
Here is an example that demonstrate three different formulas.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=320; user-scalable=0;"/>
<script src="ianime010.js"></script>
<script type="text/javascript">
var anime;function init() {
anime = new iAnime();
}function click1(obj) {
param = { element:obj, x:(300-obj.offsetLeft), y:obj.offsetTop, msec:1000 };
param.callback = function(r) { return r*r; };
anime.add(param);
}function click2(obj) {
param = { element:obj, x:(300-obj.offsetLeft), y:obj.offsetTop, msec:1000 };
param.callback = function(r) { return 1-(1-r)*(1-r); };
anime.add(param);
}function click3(obj) {
param = { element:obj, x:(300-obj.offsetLeft), y:obj.offsetTop, msec:600 };
param.callback = function(r) {
return (r < 0.8) ? (r / 0.8) : (1.04 - 4 * (r-0.9) * (r-0.9));
};
anime.add(param);
}
</script>
</head>
<body onload="init()" style="margin:0">
<img src="images/feed-icon-28x28.png" onclick="click1(this)"
style="position:absolute; left:20px; top:20px" />
<img src="images/feed-icon-28x28.png" onclick="click2(this)"
style="position:absolute; left:20px; top:60px" />
<img src="images/feed-icon-28x28.png" onclick="click3(this)"
style="position:absolute; left:20px; top:100px" />
</body>
</html>
And here is the actual page. Click each icon and see how the speed changes during the animation.
By the way, click an icon while another icon is animating. You can animate multiple images concurrently, by simply adding iAnime::add function.
It is also possible to animate images along non-linear path. You can achieve it by providing optional parameter, adjustX and adjustY as functions, which alters the position during the animation. Here is a simple example, that emulates a thrown object in vacume.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=320; user-scalable=0;"/>
<script src="ianime010.js"></script>
<script type="text/javascript">
var anime;function init() {
anime = new iAnime();
}function click(obj) {
param = { element:obj, x:(300-obj.offsetLeft), y:obj.offsetTop, msec:600 };
param.adjustY = function(y,r) {
return y - 60 * 4 * (0.25 - (r-0.5) * (r-0.5));
};
anime.add(param);
}
</script>
</head>
<body onload="init()" style="margin:0">
<img src="images/feed-icon-28x28.png" onclick="click(this)"
style="position:absolute; left:20px; top:80px" />
</body>
</html>
And here is the actual demo.
The next example involves the rotation. Just like other callback functions, you just need to provide an optional parameter "rotate" to specify the orientation of the image during the animation. The example below shows you how to rotate the icon 360 degree during the animation.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=320; user-scalable=0;"/>
<script src="ianime010.js"></script>
<script type="text/javascript">
var anime;function init()
{
anime = new iAnime();
}function click(obj)
{
param = { element:obj, x:(300-obj.offsetLeft), y:obj.offsetTop, msec:600 };
param.adjustY = function(y,r) {
return y - 60 * 4 * (0.25 - (r-0.5) * (r-0.5));
};
if (obj.offsetLeft < 150) {
param.rotate = function(r) { return Math.PI * 2 * r; };
} else {
param.rotate = function(r) { return -Math.PI * 2 * r; };
}
anime.add(param);
}
</script>
</head>
<body onload="init()" style="margin:0">
<img src="images/feed-icon-28x28.png" onclick="click(this)"
style="position:absolute; left:20px; top:80px" />
</body>
</html>
Notice that I am changing the direction of the rotation based on the starting point, so that it rotates into a natural direction. Here is the actual demo.
There are a few more features I would like to explain (such as custom canvas, and multiple animation contexts), but I think this is enough for a single blog entry.
Please try those sample on your iPhone or iPod touch to see the actual performance (which is not bad at all), and create your own sample pages. I appreciate feedback, including feature requests, bug reports, and idea to optimize the code further via comments or trackbacks (I am going to post another entry for Japanese readers to accepts comments in Japanese).
Enjoy!
perucas em goiania Another great artist named Lane Patterson creates junk art from reclaimed or recycled pieces to create meaningful and unique pieces of art. One piece called Dragonfly, offers a sculpture from plumbing and electrical parts as well as resin grapes from long ago with other vintage objects incorporated. He offers many pieces that are all created from reclaimed or recycled pieces to create junk art that gives the viewer an idea of exactly what he felt when he created each piece.
best hair extensions One was a fourteen year old Prussia who was completely unimpressed because her best friend who takes her to cons is 37. I'll get straight to the point: can you please stop wearing really ugly wigs in your relatively mediocre movies ? Don't get me wrong.
red hair extensions Madagaskar. Malawi. Malezja. For the maintenance of a healthy head and scalp biotin hair growth is necessary, and can be used as a topical product or taken as a supplement. Biotin which is also well-known as vitamin B-complex or B7 plays an important role in transforming food and stored body fat into energy that is necessary for the body. Since Biotin is soluble in water it makes it almost impossible to be accumulated in the body.
perruque naturelle pour black Imagine if a woman with a short hair wants to have a hairstyle for a party. Heavy hairstyles cannot be proceeded with short hair and it needs at least an average hair length to go ahead. This is where hair extensions come in to play. You can try easy hairstyle ideas with hair extensions.
http://wigsjp.tumblr.com
Posted by: Piessmitycync | May 17, 2013 at 06:13 AM
A fascinating discussion is definitely worth comment. There's no doubt that that you need to publish more on this subject, it may not be a taboo subject but typically folks don't discuss these issues. To the next! Cheers!!|
アグ ブーツ メンズ http://www.vivendadelmar.com/アグ-ブーツ-レディース-c-2.html
Posted by: アグ ブーツ メンズ | November 01, 2013 at 01:17 AM