How do I control agent plotting order to place certain agents on top of each other?

70 views Asked by At

I am trying to make a plot/animation of a model with mixed agents (green patches and uav agents) and would like the uav agents to be plotted on top of the patch agents. I attached what I have for my code and an image below. Some of the UAV agents are plotted on top of the patches, while others are plotted behind them. I am wondering if there is a solution to this.

One thought I have is that has to do with the scheduling of the agents.

function agent_color(a)
    if a isa Patch
        color = "#007500" # get_color(a.prob_burn)
        if a.status == :on_fire
            color = :red
        elseif a.status == :burnt
            color = :gray55
        end
    elseif a isa UAV
        color = :blue
    else
    end
    color
end

const uav_polygon = Makie.Polygon(Point2f[(-.5,-.5), (1,0), (-.5,.5)])

function uav_marker(u::UAV)
    t = atan(u.vel[2], u.vel[1])
    shape = rotate_polygon(uav_polygon, t)
    return shape
end

function agent_shape(a)
    if a isa Patch
        shape = :hexagon
        if a.status == :on_fire
            shape = :circle
        elseif a.status == :burnt
            shape = :rect
        end
        
    elseif a isa UAV
        shape = uav_marker(a)
    else

    end
    shape
end


figure, _ = Agents.abmplot(forest; ac = agent_color,as = 24, am = agent_shape, scatterkwargs = (strokewidth = 0.1,), figure = (;resolution = (500,500)))

Example of what I am trying to avoid

I looked to see if I could find any examples of people doing this but was not able to. Closest thing would be rewriting it as a model step for the patches, but the nature of the hexagonal grid makes it difficult (unless I were to rewrite my entire model).

0

There are 0 answers