You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The boid flockers example can be improved with (Solara) visualisation that includes the direction and colors for the boids. It would be nice to have an arrow-like shape to know the direction, and either random colors or to let them take the colors of a group/leader.
Here's an example, in matplotlib, from an old exam we used:
# set the colormap we will use for plottingbwr=plt.get_cmap("gist_rainbow")
defdraw_boids(model):
x_vals= []
y_vals= []
u_vals= []
v_vals= []
colors= [] # List to hold the color for each agent# Generate unique colors with saturation and transparency# Use a colormap with high saturation, such as "hsv"cmap=plt.get_cmap("hsv")
n_agents=len(model.schedule.agents)
color_indices=np.linspace(0, 1, n_agents)
fori, boidinenumerate(model.schedule.agents):
x, y=boid.posu, v=boid.direction_vectorx_vals.append(x)
y_vals.append(y)
u_vals.append(u)
v_vals.append(v)
# Assign a color with transparency; alpha value less than 1 introduces transparencycolors.append(cmap(color_indices[i])[:3] + (0.6,)) # Change 0.6 to the desired transparencyfig=plt.figure(figsize=(7, 7))
ax=fig.add_subplot(111)
# Use quiver with colorsq=ax.quiver(x_vals, y_vals, u_vals, v_vals, color=colors, angles='xy', pivot='mid',
headaxislength=8, headlength=10, headwidth=7, scale=35)
# The call to `embed_identity` is not changed.embed_identity(ax, student_name, student_number)
draw_boids(model)
The text was updated successfully, but these errors were encountered:
The boid flockers example can be improved with (Solara) visualisation that includes the direction and colors for the boids. It would be nice to have an arrow-like shape to know the direction, and either random colors or to let them take the colors of a group/leader.
Here's an example, in matplotlib, from an old exam we used:
The text was updated successfully, but these errors were encountered: