AnyLogic
Expand
Font size
All Implemented Interfaces:
com.anylogic.engine.internal.Child, Locatable2D, AggregatableAnimationElement, HasLevel, LevelElement, SVGElement, Serializable, Cloneable

public class ShapeCanvas
extends Shape
A raster image whose pixels can be modified dynamically at runtime. Maps directly to HTML5 canvas element and exposes a part of its API. In contrast with vector graphics, any shapes drawn on the canvas become a part of a raster image and cannot be accessed afterwards. After creation (and after clearing), the canvas is transparent.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Field Summary

Fields inherited from class com.anylogic.engine.presentation.Shape

UNKNOWN_NAME

Constructor Summary

ConstructorDescription
ShapeCanvas(boolean ispublic, double x, double y, double rotation, double width, double height)
Constructs a canvas with specific attributes.
ShapeCanvas(double width, double height)
Constructs a canvas with given width and height, public visibility, x and y coordinates and rotation set to 0.

Method Summary

Modifier and TypeMethodDescription
voidclear()
Clears the whole canvas (makes it fully transparent).
voidclearRectangle(double x, double y, double width, double height)
Clears a rectangle on the canvas (makes it fully transparent)
booleancontains(double px, double py)
Tests if the canvas contains the point with the given coordinates
voidfillCircle(double cx, double cy, double radius, Paint color)
Fills a circle with the given color on the canvas, preserving transparency
voidfillRectangle(double x, double y, double width, double height, Paint color)
Fills a rectangle with the given color on the canvas, preserving transparency
doublegetHeight()
Returns the height of the canvas.
doublegetWidth()
Returns the width of the canvas.
voidpostSVGShapeSpecificAttributes(List<String> att, List<String> val, boolean publicOnly)
Posts general properties specific to a particular shape class.
voidsetGlobalCompositeOperation(String type)
Sets the type of composing operation to apply when drawing new shapes, where type is a string identifying which of the composing or blending mode operations to use.
voidsetHeight(double height)
Sets the height of the canvas.
voidsetSize(double width, double height)
Sets the width and height of the canvas.
voidsetWidth(double width)
Sets the width of the canvas.

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods inherited from interface com.anylogic.engine.markup.AggregatableAnimationElement

initializeInternal, postInitialize

Constructor Details

ShapeCanvas

public ShapeCanvas(double width,
 double height)
Constructs a canvas with given width and height, public visibility, x and y coordinates and rotation set to 0.
Parameters:
width - the width of the canvas
height - the height of the canvas

ShapeCanvas

public ShapeCanvas(boolean ispublic,
 double x,
 double y,
 double rotation,
 double width,
 double height)
Constructs a canvas with specific attributes.
Parameters:
ispublic - if true, the shape is visible on container's presentation
x - the x coordinate of the canvas upper left corner
y - the y coordinate of the canvas upper left corner
rotation - the rotation of the canvas around Z-axis from +X to +Y, in radians
width - the width of the canvas
height - the height of the canvas

Method Details

getWidth

public double getWidth()
Returns the width of the canvas.
Returns:
the width of the canvas

setWidth

public void setWidth(double width)
Sets the width of the canvas.
Parameters:
width - the new width of the canvas

getHeight

public double getHeight()
Returns the height of the canvas.
Returns:
the height of the canvas

setHeight

public void setHeight(double height)
Sets the height of the canvas.
Parameters:
height - the new height of the canvas

setSize

public void setSize(double width,
 double height)
Sets the width and height of the canvas.
Parameters:
width - the new width of the canvas
height - the new height of the canvas

contains

public boolean contains(double px,
 double py)
Tests if the canvas contains the point with the given coordinates
Specified by:
contains in class Shape
Parameters:
px - the x coordinate
py - the y coordinate
Returns:
true if the canvas contains the point, false otherwise

setGlobalCompositeOperation

public void setGlobalCompositeOperation(String type)
Sets the type of composing operation to apply when drawing new shapes, where type is a string identifying which of the composing or blending mode operations to use. The valid types are:

  • "source-over" - This is the default setting and draws new shapes on top of the existing canvas content.
  • "source-in" - The new shape is drawn only where both the new shape and the destination canvas overlap. Everything else is made transparent.
  • "source-out" - The new shape is drawn where it doesn't overlap the existing canvas content.
  • "source-atop" - The new shape is only drawn where it overlaps the existing canvas content.
  • "destination-over" - New shapes are drawn behind the existing canvas content.
  • "destination-in" - The existing canvas content is kept where both the new shape and existing canvas content overlap. Everything else is made transparent.
  • "destination-out" - The existing content is kept where it doesn't overlap the new shape.
  • "destination-atop" - The existing canvas is only kept where it overlaps the new shape. The new shape is drawn behind the canvas content.
  • "copy" - Only the new shape is shown.
  • "xor" - Shapes are made transparent where both overlap and drawn normal everywhere else.
  • "lighter" - Where both shapes overlap the color is determined by adding color values.
  • "multiply" - The pixels are of the top layer are multiplied with the corresponding pixel of the bottom layer. A darker picture is the result.
  • "screen" - The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply)
  • "overlay" - A combination of multiply and screen. Dark parts on the base layer become darker, and light parts become lighter.
  • "darken" - Retains the darkest pixels of both layers.
  • "lighten" - Retains the lightest pixels of both layers.
  • "color-dodge" - Divides the bottom layer by the inverted top layer.
  • "color-burn" - Divides the inverted bottom layer by the top layer, and then inverts the result.
  • "hard-light" - A combination of multiply and screen like overlay, but with top and bottom layer swapped.
  • "soft-light" - A softer version of hard-light. Pure black or white does not result in pure black or white.
  • "difference" - Subtracts the bottom layer from the top layer or the other way round to always get a positive value.
  • "exclusion" - Like difference, but with lower contrast.
  • "hue" - Preserves the luma and chroma of the bottom layer, while adopting the hue of the top layer.
  • "saturation" - Preserves the luma and hue of the bottom layer, while adopting the chroma of the top layer.
  • "color" - Preserves the luma of the bottom layer, while adopting the hue and chroma of the top layer.
  • "luminosity" - Preserves the hue and chroma of the bottom layer, while adopting the luma of the top layer.

Parameters:
type - the type of composing to be applied from now

fillRectangle

public void fillRectangle(double x,
 double y,
 double width,
 double height,
 Paint color)
Fills a rectangle with the given color on the canvas, preserving transparency
Parameters:
x - the x coordinate of the top left corner of the rectangle
y - the y coordinate of the top left corner of the rectangle
width - the width of the rectangle
height - the height of the rectangle
color - the color or texture to use

fillCircle

public void fillCircle(double cx,
 double cy,
 double radius,
 Paint color)
Fills a circle with the given color on the canvas, preserving transparency
Parameters:
cx - the x coordinate of the circle center
cy - the y coordinate of the circle center
radius - the radius of the circle
color - the color or texture to use

clearRectangle

public void clearRectangle(double x,
 double y,
 double width,
 double height)
Clears a rectangle on the canvas (makes it fully transparent)
Parameters:
x - the x coordinate of the top left corner of the rectangle
y - the y coordinate of the top left corner of the rectangle
width - the width of the rectangle
height - the height of the rectangle

clear

public void clear()
Clears the whole canvas (makes it fully transparent).

postSVGShapeSpecificAttributes

public void postSVGShapeSpecificAttributes(List<String> att,
 List<String> val,
 boolean publicOnly)
Description copied from class: Shape
Posts general properties specific to a particular shape class. Is triggered by SVG_DIRTY_SHAPE flag. Made public for occasional posting of additional SVG properties from outside engine (e.g. from libraries)
Overrides:
postSVGShapeSpecificAttributes in class Shape
Parameters:
att - attribute names
val - attribute values
publicOnly - TODO