Giter Site home page Giter Site logo

Comments (3)

joakin avatar joakin commented on July 21, 2024

Depending on what you are doing there may be different ways of going about it.

If you just want to read the canvas pixels and calculate things, I recommend using ports and doing so on JS, because Elm doesn't support converting Uint8ClampedArray from JS easily to elm-bytes.

If you want to paint ImageData into the canvas, either

  1. do it in JS every time after you render in Elm (with a requestAnimationFrame to let Elm flush updates to the DOM),
  2. or you can put your imageData in to a hidden canvas, make an Image with ctx.toDataURL and then pass it back to Elm and use Texture.fromDomImage to draw to the canvas in Elm.

If you explain your use case and it is important to add first class support in the library, we can talk about adding other Texture.fromXXX methods, in this case something like Texture.fromImageData or something like that.

from elm-canvas.

tortis avatar tortis commented on July 21, 2024

I'm hoping to implement a flood fill tool on top of your drawing example. I guess I could send the message through a port then implement it in javascript, but it would be nice if I could write it in elm.

Do you think using a port to pass image data as array into Elm, doing the flood fill, then passing the image data back to JS to put onto the canvas would work? Do you think that would have poor performance?

Thanks for your help!

from elm-canvas.

janwirth avatar janwirth commented on July 21, 2024

@tortis I usually monkey-patch elements to exhibit specific getters for the stuff I want in elm. Then I listen to events and use event.target to get the data.

Example:
    HTMLElement.prototype.__defineGetter__("boundingClientRect", function() {
        return this.getBoundingClientRect();
    });

Within the hander you can also call ctx.toDataURL or whatever you please.

from elm-canvas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.