Image

Image shape enables users to add images in presentations. Image can be loaded from the image file of any format (.png, .jpg, .gif, .bmp, etc). 

Images can appear not only in 2D presentation, but also in 3D animation

You can add images from the Clipboard using the standard  Paste command of AnyLogic. You can also drag the image files from other applications directly onto the AnyLogic graphical diagram. In this case AnyLogic automatically adds a new image shape on the graphical diagram containing the added image.

 To add an image onto presentation
  1. Drag the  Image element from the  Presentation palette to the graphical editor.
  2. You will see a placeholder for the image created on the presentation diagram. We will call it image shape.
  1. The Open dialog will open automatically. Browse for the image file you want to add, then select it and click Open when finished.
  2. There is another way to add an image to this image shape. Go to the Properties view and add new images by clicking the Add image button. This opens the Open dialog box where you can select a file. 
  3. You will see the added image in the preview area. You can add several images and then programmatically change the displayed one at the model runtime. You can manage the list of added images using controls in the upper right corner of the Images properties.
  4. If needed, adjust the size of the image, or click Reset to original size checkbox to preserve its original size.
By default the shape is shown in both 2D animation and your 3D window. You can set the shape to be shown only in 2D, or in 3D in the Show in advanced property of the shape.

All image files added to AnyLogic image will be copied to the model folder. Thus you do not need to specify any paths to the image files. In case you copy your model elsewhere all image files will be copied as well.

One image shape may contain several images so that you can dynamically switch between them at model runtime.

Properties

General

Name – The name of the shape. It is used to identify and access the shape from code.

Ignore – If selected, the shape is excluded from the model.

Visible on upper level – If selected, the shape is also visible on the upper level where this agent lives.

Icon – If selected, the shape is considered as a part of the agent's icon. Please note that icon shapes are not shown in 3D animation.

Lock – If selected, the shape is locked. Locked shapes do not react to mouse clicks - it is impossible to select them in the graphical editor until you unlock them. It is frequently needed when you use a shape as a background image for your animation and you want to prevent editing this shape while drawing other shapes over it.

Visible – Here you specify whether the shape is visible on the animation at the model runtime, or not. Choose yes or no Using the control. If you expect visibility to change dynamically or to depend on some conditions, you may specify the expression defining the shape's visibility here. This expression will be dynamically reevaluated at the model runtime. It should return boolean value. The shape is visible when the specified expression evaluates to true, and not visible otherwise.

Reset to original size – If selected, the original image size is preserved.

Images – The property section defines images the image shape contains.
            Add image using the Add image button.
            Change images order using arrow buttons.
            Remove the selected image using the "cross" button.

Position and size

X – X-coordinate of the image's upper left corner.

Y – Y-coordinate of the image's upper left corner.

Z – Z-coordinate of the image shape.

Width – Width of the image shape (in pixels).

Height – Height of the image shape (in pixels).

Rotation – Shape's rotation angle in XY plane. 

Scale X – Here you can specify the expression returning the X-direction scale factor for the shape.*

Scale Y – Here you can specify the expression returning the Y-direction scale factor for the shape.*

* You can dynamically scale the shape at the model runtime by specifying expressions in the Scale X and ScaleY parameters.

Advanced

Show in - Here you can choose whether you want this shape to be shown both In 2D and 3D animation, or in 2D only, or in 3D only.

Image index – Dynamic expression defining the index of the image in the list to be displayed (integer, zero-based). If left blank, 0 is assumed.

Replication – The replication factor of the shape. Here you specify how many copies of the shape will be created (the integer number). If you leave this field empty, only one shape will be created.

On click – Code that will be called each time a user clicks on the shape at the model runtime.

Show name – If selected, the shape's name is displayed on the presentation diagram.

Functions

You can dynamically modify shape properties at model runtime using the API of the corresponding class   ShapeImage.

Position

Function

Description

double getX()

double getY()

double getZ()

Returns the X (Y, Z) coordinate of the shape (namely, the coordinate of its upper left corner).

void setX(double x)

void setY(double y)

void setZ(double z)

Sets the X (Y, Z) coordinate of the shape.

Parameters:
x - the new value of X coordinate
y - the new value of Y coordinate
z - the new value of Z coordinate

void setPos(double x,
double y)

Sets new coordinates for the shape.

Parameters:
x - the new value of X coordinate
y - the new value of Y coordinate

void setPos(double x, double y, double z)

Sets new coordinates for the shape. 

Parameters:
x - the new value of X coordinate
y - the new value of Y coordinate
z - the new value of Z coordinate

Size, scaling

Function

Description

void setSize
(double width, double height)

Sets the width and height of the image shape.

Parameters:
width - the new width of the image shape
height - the new height of the image shape

double getWidth()

Returns the width of the shape.

double getHeight()

Returns the height of the shape.

void setWidth(double width)

Sets the width of the shape equal to width.

void setHeight(double height)

Sets the height of the shape equal to height.

double getScaleX()

double getScaleY()

Returns the scale of the shape along X (Y) axis.

void setScaleX(double sx)

void setScaleY(double sy)

Sets the scale of the shape along X (Y) axis.

Parameters:
sx - the new value of scale along X axis* 
sy - the new value of scale along Y axis* 

* 1 = keep original size

void setScale(double sx, double sy)

Sets the scales of the shape along both axes.

Parameters:
sx - the new value of scale along X axis, 1 = keep original size
sy - the new value of scale along Y axis, 1 = keep original size

void setScale(double s)

Sets the same scale of the shape along both axes.

Parameter:
s - the new value of scale along both axis, 1 = keep original size

Rotation

Function

Description

double getRotation()

Returns the rotation of the shape in radians, clockwise.

void setRotation(double r)

Sets the rotation of the shape.

Parameter:
r - the new value of rotation in radians

Visibility

Function

Description

boolean isVisible()

Checks the visibility of the shape. If the shape is visible, returns true, otherwise returns false.

void setVisible(boolean v)

Sets the visibility of the shape.

Parameter:
v - visibility: if true - the shape is set to be visible, if false - not visible

Images

Function

Description

int getIndex()

Returns the current index of the image being displayed.

void setIndex(int index)

Sets the index of the image to display.

Parameter:
index - the index of the image to display

String getImageFileName(int i)

Returns the file name of the image with the given index.

Parameter:
i - the index

ArrayList<String> getImageFileNames()

Returns the list of image file names of this image shape.

void add(String filename)

Adds an image to the image shape.

Parameter:
filename - the file name of the image being added

void remove(int i)

Removes the image with the given index from the image shape.

Parameter:
i - the index of the image

Points inside the shape

Function

Description

boolean contains(double px, double py)

Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e. in the same system with the coordinates of this shape, x and y) . Returns true if the shape contains the point with the given coordinates.

Parameters:
px - the x coordinate relative to this shape's container
py - the y coordinate relative to this shape's container

Point randomPointInside()

Returns the randomly chosen point inside the shape area.

This function utilises Random Number Generator of the Presentable object containing this shape. (Will throw an exception if the shape has been created from code and hasn't been added to any group, - in this case use randomPointInside(Random rng)).

Returns null if the shape has no points (e.g. polyline with no points).

Point randomPointInside
(java.util.Random rng)

Returns the randomly chosen point inside the shape area. This function utilises the given Random Number Generator. 

Parameter:
rng - the random number generator.

Dynamically changing images shown by an image shape

As it was said before, one image shape can contain several images so that you can switch between them by choosing this or that one to be shown in some particular cases. This may be useful when two or more different images correspond to different (and alternative) states or modes of an object. 

To enable this feature, first you should add several images to one image shape. 

Then you should choose the mechanism of switching these images. There are two ways of dynamic switching images of an image shape. 

Please note that image indexes are zero-based: the first image has index 0, and so on.

Related topics

Moving Presentation Shapes

Resizing Presentation Shapes

Rotating Presentation Shapes

Changing Shape's Position in Stacking Order

 Aligning Shapes