canvas .v. SVG objects ?

A

Aaron Gray

I want to do an online graphical editor and am wondering if canvas could
support "editable" objects, i.e. once I create say a rectangle can I either
change the size of the rectangle from JavaScript or delete the rectangle and
create a new one ?

i.e. can I get a handle to the object and can I modify the object once
created.

Otherwise I have to use SVG.

Many thanks in advance,

Aaron
 
A

Aaron Gray

kangax said:
There are no "objects" in canvas specification/implementations. Canvas
only provides a set of low level methods for manipulating 2d context;
fill/stroke lines, rectangles, paths, etc.

Encapsulating certain drawing logic (such as drawing rectangle, circle or
a star) into your own objects is quite simple and straightforward. After
that, you can give your objects properties representing state and change
that state via objects' methods as you wish (e.g. width, height, scale,
angle, etc.). That state is what you use when rendering an object.

So I cannot manipulate canvas object once they are rendered ?
Can I delete them ?
I have actually built a pretty large library (set of "classes"
representing most of primitive shapes, as well as custom paths and a
minimal SVG-to-canvas parser) to do just that, but it's not yet public.


From what I remember, manipulating SVG elements' state is slower than that
on canvas. SVG elements are DOM objects while canvas abstractions have
nothing to do with DOM and operate on a lower level.

Yes SVG is slower but it maintains its state in DOM and is manipulatable.

Aaron
 
A

Aaron Gray

Aaron Gray said:
So I cannot manipulate canvas object once they are rendered ?
Can I delete them ?


Yes SVG is slower but it maintains its state in DOM and is manipulatable.

Yes canvas is crap you get no handles on save() and restore() functions with
no handles again.

Have to use SVG/VML !

Aaron
 
R

rf

Aaron said:
Yes canvas is crap you get no handles on save() and restore()
functions with no handles again.

Have to use SVG/VML !

I needed to do some cross browser graphs (bar, line etc). Looked at canvas,
even looked at the canvas to VML emulators.

I quickly decided canvas was crap. I also quickly decided the canvas - VML
emulators were also crap.

Looked at the various SVG/VML emulators out there. They are also crap.

I wrote my own.
 
R

RobG

Yes canvas is crap

I don't think that is what kangax was saying. The canvas element is
designed to provide some very simple, low-level drawing tools and can
therefore be much more lightweight. But it can be used to create some
quite complex effects if used effectively, it just doesn't have all
the features of SVG.

Canvas breakout game:
<url: http://billmill.org/static/canvastutorial/ >

Other games, such as Mario Cart:

You may not want to do games, but the above shows some of the things
that can be done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top