views:

205

answers:

3

Hey guys,

I'm doing some animations and I want to implement something like this on the web. I was thinking that the HTML canvas can do this kind of job. Because I can scale part of an image. I just need the algorithm to actually make it work.

The effect is elastic, if the window is small, the greater the elasticity of the window when you restore it. I was thinking that I can make this work in web images.. if the user click the image it will scale with this kind of effect, not the boring way of scaling.

This is ubuntu, I know that we can look at the source code maybe to see how it actually implements the animation. But I dont know where to find it. Or i don't even understand codes written in linux because I just understand php, javascript. Basically I'm not a software developer, My core expertise is in web development.

http://www.youtube.com/watch?v=hgQP-aFragQ

+2  A: 

Your not going to find a web based solution that is going to do this for you. If you need something like this done it will have to be in flash or some other application (Lenni mentioned Java) that runs in a separate media box embedded in a web page.

People don't want big flashy animations, seeing something that is 'boring' is much better if it becomes more usable.

Sam152
I think canvas can do this kind of animation.
rymn
Nah, don't be a pessimist. Using canvas, splitting the image into component squares, deforming the grid, all possible, especially in chrome. Performance will need to be tuned.
Jim T
+3  A: 

I believe your best bet is having a look at John Resig's Processing.js.

Processing is a animation language for Java; John has ported it to the browser using canvas.

Lenni
IC, I'll try to figure out how I can imitate this kind of animation then.I was thinking that I can clone some part of the image object then make the borders of the image looks like very soft. The only problem I have is figuring out the algorithm of it. I'll just do some experimentation..
rymn
+1  A: 

First up - I don't know the actual algorithm they use here.

However, I'd attack this by creating a grid of points (say 10x10), each point attached to it's neighbors by damped springs. It might be worth anchoring the edge/corner points to the screen with springs too.

By deforming the grid (stretching and compressing the springs) and then modeling the spring responses, you'd get some interesting effects like those shown. You might then be able to record the patterns so that the points can follow a pre-computed path for faster animation if your animations are predictable.

Then you need to work out how to split the image and map it onto the grid. The splitting may be better done once on the server, but the client can do it if you use canvas.

svg & vml is a possibility - they'll work without plugins and are similar enough to code for, but I don't think you'll get correct enough image deformation. However, you can scale and rotate with impunity (and quickly) so if you just anchor 2 cell image points to the grid rather than all 4, you'll get an interesting animation - not quite like the video, but pretty good.

As for how to model damped springs, you'll need to keep track of the mass of each point (how heavy it is), how much force the spring is exerting on each point (scalar of how compressed/stretched it is and it's vector) and a damping force on the points (resistive force to the square of the velocity of the point).

It's physics modeling, to be sure, but quite possible.

The response may well be slow. Especially on IE. Canvas needs a plug-in on IE, so if you use canvas, IE folk wont see it. SVG works on almost everything except IE, but it does have VML which is similar. http://raphaeljs.com/ is a library that uses whatever's available. This will be a challenge to tune up :)

However you do this, it will always look best in chrome, the V8 javascript engine outstrips everything else for this kind of work. IE has the slowest javascript engine.

Jim T
IC, the problem is splitting the image in Canvas. So I need multiple Canvas. Because I tried clipping the image and it doesn't stack up. And of course, the rendering is slow.
rymn
Are you sure that canvas is ok for what you need? Keep in mind that IE doesn't support it, unless you can convince your visitors to install a plugin. If so, this might be an opportunity for me to look at it :)
Jim T