Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation SVG or Canvas?

I was wondering whether it's better to make an animation like this in canvas or svg (performance wise)? I'm rewriting it now in jquery but I read somewhere that a canvas is redrawn every time it changes.

like image 353
BigChief Avatar asked Mar 11 '12 14:03

BigChief


People also ask

Is canvas better than SVG?

SVG provides better performance with a larger surface or a smaller number of objects. Canvas provides better performance with a smaller surface or a large number of objects. The SVG syntax is easy to understand, but it is impossible to read the graphics object. Canvas syntax is very simple and easy to read.

What is the difference between SVG and canvas?

Differences Between SVG and CanvasSVG is a language for describing 2D graphics in XML. Canvas draws 2D graphics, on the fly (with a JavaScript). SVG is XML based, which means that every element is available within the SVG DOM. You can attach JavaScript event handlers for an element.

Can you animate on canvas?

You can create animations with HTML5 by combining HTML, CSS, and JavaScript (JS), with which you can build shapes. Also, you can control animations and edit images, video, and audio by means of JS or CSS elements, all of which you then add to a drawing board, which you set up with the <canvas> element.


1 Answers

For these "simple" animations and scene graphs it doesn't really matter if you use SVG or Canvas performance wise. Both should work fine without performance issues.

However it might be easier to create animation with SVG compared to Canvas. In Canvas you have to redraw the whole scene and in SVG you could just create the ring once and then define a transformation (rotation) on it.

For SVG check out d3.js or raphael and for canvas you can check out processingjs, fabric.js, kinetic.js or paper.js

like image 82
Ümit Avatar answered Oct 14 '22 08:10

Ümit