The first parameter must be the Environment
that this
CanvasRenderer
will render.
The second parameter specifies options, which can include:
autoPosition
(boolean = false
) — For Environment
s using a Network
, whether to automatically position the Agent
s.background
(string = "transparent"
) — The background color to draw before rendering any Agent
s.connectionColor
(string = "black"
) — For Environment
s using a Network
, the color of linesconnectionOpacity
(number = 1
) — For Environment
s using a Network
, the opacity of linesconnectionWidth
(number = 1
) — For Environment
s using a Network
, the width of linesheight
(number = 500
) — The height, in pixels, of the canvas on which to renderorigin
({ x: number; y: number } = { x: 0, y: 0 }
) — The coordinate of the upper-left point of the space to be renderedscale
(number = 1
) — The scale at which to render (the larger the scale, the smaller the size of the space that is actually rendered)trace
(boolean = false
) — If true
, the renderer will not clear old drawings, causing the Agent
s to appear to trace their paths across spacewidth
(number = 500
) — The width, in pixels, of the canvas on which to renderPoints to the Environment
that this
renderer is tied to. This is automatically set when the
renderer is created.
Mount this renderer to a DOM element. Pass either a string representing a CSS selector matching the element or the element itself.
// mounts the renderer to the element with the ID `container`
renderer.mount('#container');
// mounts the renderer to the element itself
const container = document.getElementById('container');
renderer.mount(container);
Generated using TypeDoc
A
CanvasRenderer
renders anEnvironment
spatially in two dimensions. Importantly, it expects that allAgent
s in theEnvironment
have numeric"x"
and"y"
values associated with them.CanvasRenderer
s will render allAgent
s that are visible in the renderedEnvironment
space, with the color of their"color"
value (defaulting to black). Depending on the"shape"
of theAgent
, additional data might be needed.Agent
"shape"
s can be:"circle"
(default) — Draws a circle centered at theAgent
's"x"
/"y"
values.Agent
has a"size"
value, uses that for the circle radius (defaults to 1px)."arrow"
— Draws an arrow centered at theAgent
's"x"
/"y"
values.Agent
s"vx"
/"vy"
values. For example, anAgent
with"vx" = 1
and"vy" = 0
will be rendered as an arrow pointing to the right."rect"
— Draws a rectangle with the upper-left corner at"x"
/"y"
.Agent
's"width"
and"height"
values for the dimensions of the rectangle."triangle"
— Draws a triangle centered at theAgent
's"x"
/"y"
values."size"
value.0.0.11