Comments (3)
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
- do it in JS every time after you render in Elm (with a
requestAnimationFrame
to let Elm flush updates to the DOM), - or you can put your imageData in to a hidden canvas, make an
Image
withctx.toDataURL
and then pass it back to Elm and useTexture.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.
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.
@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)
- Improve transform docs
- Improve arc docs
- Document the canvas coordinate system
- Add making textures from DOM images HOT 1
- Canvases get blank on deleting one of them from a List HOT 2
- DOM images textures break in Firefox HOT 6
- High CPU load with many canvases HOT 7
- Text Color Support HOT 1
- Use `Result` rather than `Maybe` for texture loading HOT 1
- Use elm-geometry types? HOT 1
- Support for "groups" or similar batching of settings to multiple `Renderable` HOT 4
- Runtime crash with `arc` function and negative radius
- Regression: text without fill or stroke is rendered with both fill and stroke
- Not working HOT 3
- Unexpected scene HOT 1
- Question about filter HOT 1
- Please support `roundRect` HOT 2
- Margin bug: canvas and elm-canvas don't share the same height HOT 4
- closePath operation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elm-canvas.