curl https://raw.githubusercontent.com/mgold/core/backbuffer/src/Graphics/Collage.elm -o elm-stuff/packages/elm-lang/core/2.1.0/src/Graphics/Collage.elm
curl https://raw.githubusercontent.com/mgold/core/backbuffer/src/Native/Graphics/Collage.js -o elm-stuff/packages/elm-lang/core/2.1.0/src/Native/Graphics/Collage.js
You can then run the example at the end of this post. Some caveats: I haven't tested it with every type of Form yet and it's possible it has some bugs for lines, text, elements, or groups. (Even in theory, all members of a group will be indistinguishable). Also, on the border between two shapes, it may infer another shape, due to interpolation.
This is a proof of concept and should not be relied on. But if there's interest, I can work on making this more stable. It would have to be merged into core eventually; it can't be a third party lib.
Incidentally, you can also use this trick for arbitrary collision detection, i.e. you get everything under the mouse, not just the topmost one. You assign each form a bit in the color space, and set it to 1 wherever the form renders. This means you can only use 24 forms (1 byte for r,g,b; I don't think you can use alpha) and you can't reuse the render pipeline without looking at each pixel you draw and doing some bit manipulation. But hey, in theory...
Example:
import Graphics.Element as E
import Graphics.Collage as C
import Color exposing (blue, red, green)
import Mouse
forms = [ C.rect 200 100 |> C.filled blue
, C.oval 40 250 |> C.filled red
, C.polygon [(20, 20), (20, 70), (80, 40), (30, 50)] |> C.filled green |> C.move (20, -50)
]
collage = C.collage 500 500 forms
bbuf = C.backbuffer 500 500 forms
hovering = Signal.map (\p -> C.getAt p bbuf |> E.show) Mouse.position
render hoverState = collage `E.above` hoverState
main = Signal.map render hovering
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.