Question about CANVAS

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about CANVAS

Jiri Znamenacek
Hi,

I was playing with <canvas> this weekend for function plotting. It's
pretty nice, BUT: The problem is it seems there's no reasonable way to
access what is on the canvas. You can paint any thing to it, but the
only one you get out of it is picture on the screen or full PNG data
via toDataURL() method. For example if I understand it well:

~ coordinates must be retrieved by adding event listener in HTML and
then recalculated by hand to incorporate current scale and transformation
~ I'm not sure if it is possible to get bitmap information for specific
coordinates (eg. "color I'm standing above") from BASE64 encoded PNG,
never worked with PNG at low-level (and it sounds pretty awkward anyway)

There is really no way of getting some usable information back from the
canvas?

   JZ
_______________________________________________
mozilla-dom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-dom
Reply | Threaded
Open this post in threaded view
|

Re: Question about CANVAS

Martin Honnen-3

Jiri Znamenacek wrote:

> I was playing with <canvas> this weekend for function plotting. It's
> pretty nice, BUT: The problem is it seems there's no reasonable way to
> access what is on the canvas.

> There is really no way of getting some usable information back from the
> canvas?

If you want structured graphics then using SVG instead of using the
canvas might be what you are looking for. There you have a DOM document
with various elements taking event listeners. So you could put a shape
like a circle in the graphics and have script react to events like click
or mouseover on the circle.

But I am new to canvas too so maybe it has some API for you to find the
information you are looking for.




--

        Martin Honnen
        http://JavaScript.FAQTs.com/
_______________________________________________
mozilla-dom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-dom
Reply | Threaded
Open this post in threaded view
|

Re: Question about CANVAS

Jiri Znamenacek
Martin Honnen wrote:
> If you want structured graphics then using SVG instead of using the
> canvas might be what you are looking for. There you have a DOM document
> with various elements taking event listeners. So you could put a shape
> like a circle in the graphics and have script react to events like click
> or mouseover on the circle.

<rant>No, that's not an option for me. I programmed graphics only at
8-bit machines years ago and the whole XML-SVG thing is just scary to me
(although XML is my daily work now): Create XML elements just to put a
pixel somewhere? Or maybe use SVG-specific DOM (never looked at it, just
expacting the same mess with C/Java patterns peeping out of every second
corner like with the classical DOM, DOM3 XPath beeing the worst
example)? Eh, no :)</rant>

I was plotting iterations of some discrete dynamic system and was using
color to distinguish between them. I hoped for something like "mouse is
over the point of this color, so look up in hash table which iteration
it was" (would work reasonably well for this task). Seems like WHATWG
canvas is primarly meant just for painting, nothing more.

   JZ
_______________________________________________
mozilla-dom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-dom
Reply | Threaded
Open this post in threaded view
|

Re: Question about CANVAS

Daniel Kirsch
Jiri Znamenacek wrote:
> Create XML elements just to put a pixel somewhere?

Of course, this sound's a bit to overloaded, but creating dynamic pages
would be the part of SVG as you may easily react on events and don't
need to save all objects and details or calculate their position etc.

Anyway, I like the canvas element but don't have much usage of it too as
long as it doesn't support the features you are asking for. Even
toDataURL() is not implement right now so creating pictures and saving
them doesn't work.


> I was plotting iterations of some discrete dynamic system and was using
> color to distinguish between them. I hoped for something like "mouse is
> over the point of this color, so look up in hash table which iteration
> it was" (would work reasonably well for this task).

Instead of asking for a defined color at a position you may calculate
the iteration by the current mouse position.


> Seems like WHATWG canvas is primarly meant just for painting, nothing more.

That's the focus. But that doesn't mean that it could be used for
something else:

   http://rig.vlad1.com/~vladimir/canvas/cdemo1.html

(yes, this could probably be done with SVG a lot easier, but that's not
the point)

Daniel
_______________________________________________
mozilla-dom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-dom
Reply | Threaded
Open this post in threaded view
|

Re: Question about CANVAS

Jiri Znamenacek
Daniel Kirsch wrote:
> Instead of asking for a defined color at a position you may calculate
> the iteration by the current mouse position.

Yeah, that's exactly what I did in the end. It's not very elegant but it
works. Well, considering that I've started playing with canvas just to
make one graph look nicer - it was fun after all :)

We will probably use it some day for interactive math reference here
since it looks rather useful for painting. May I have a question? How
stands SVG compared to canvas in something like "plot a*sin(bx+c)"?

   JZ
_______________________________________________
mozilla-dom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-dom