Makie user defined marker example?

Hi,

It try to set up an animation for colliding polygons with Makie.

It is OK if a use poly! and pass new polygon coordinates at each time steps but I guess that it would be more efficient If I use scatter! with user defined polygonal markers, and provide translations and rotations at each timesteps…

Any hint ?

anim-opt

3 Likes

You can plot multiple polys in one go, and then just update the whole poly array each frame, which should be fairly efficient:


p1 = decompose(Point2f0, Circle(Point2f0(0), 1f0))
p2 = Point2f0[(0, 0), (0, 1), (1, 1), (1, 0)]
polys = map(1:10) do i
    p = (p1, p2)[rand(1:2)]
    off = (rand(Point2f0) .* 5)
    size = rand()
    map(p) do point
        off .+ (point .* size)
    end
end
poly(polys, scale_plot = false, color = rand(RGBf0, 10))

You can also rotate/scale/translate any plot:


scene = Scene()
poly_plots = map(polys) do poly
    poly!(poly, color = rand(RGBf0), scale_plot = false)[end]
end
display(scene)
rotate!(poly_plots[1], 0.5)
translate!(poly_plots[1], 0.0, 0.1, 0.0).

The above could be more efficient then updating the whole poly array - depends a bit on how many points you have per poly.

This would be the most efficient, but would require that each polygon you want has a unicode representation:


vals = rand(10)
positions = rand(Point2f0, 10)
markers = [('◀', '■', '⬣', '⬤')[rand(1:4)] for i in 1:10]
scatter(positions, color = vals, rotations = vals, marker = markers)

It’s also a bit unprecise, but I think if you supply markersizes, it should be scalable to the correct size

1 Like

Thanks a lot !
I have to study your snippet. I still have some difficulties with the do construct :wink:

I already use the scatter form for the circle thus I wonder if I could define my own marker. I understand now that it must have a unicode representation.