Prerequisites:
This discussion assumes that you already have a basic understanding of how to set and use labels, as well as how to associate an image with a work item. For more complete information on these topics, see our book, Learning SIMUL8: The Complete Guide or ask about our training programs.
Example Model:
To follow along with this example, download and open the Image.s8 model.
Description:
Animation is often an important model element, especially when it comes to explaining the system's behavior to stakeholders. Having the means to dynamically change graphics can be a key factor in the effectiveness of any animation. This week's topic demonstrates how to use a special reserved system label called "Image:" to make your work items follow a specified on-screen path.
First, let's review a bit about the "Image:" label. The "Image:" identifier is a reserved system label that SIMUL8 interprets in a very specific way. To set up SIMUL8 to use this label, you must first create a label that begins with the letters "Image:" There are a couple of important things to keep in mind:
- The label you set up must have a name in the form of "Image:Base." The word 'Base' would be replaced by a name that makes sense in your model. For example, in our model, we'll be using a label named "Image:Truck" since the pictures will be of, well, trucks. Note that there is no space after the colon.
- Though it may seem odd at first glance, you must make sure that you set the label type to 'number'.
- Once you have set up the name and type of your label, you need to embed your graphics. Once again, it is all in the name. If your label is named "Image:Base", then SIMUL8 will look for images named "BaseX", where X is a number. As with the label name, you must check that there is no space in the graphic name.
- OK, now here's where you get to put it all together: If your label named "Image:Base" has a value of 3 for a particular work item, then SIMUL8 will represent the work item in question with the graphic called "Base3". If, instead, the "Image:Base" label has a value of 1, you'll see the "Base1" graphic, and so on.
Still with us? Hang in there for a minute. It is easier to understand when you watch a concrete example in action. Returning to our example, then, we have named our label "Image:Truck". That means that SIMUL8 will look for graphics with names like "Truck1" and "Truck2." We use this simple trick in many of our models as a way to indicate visually that work items with different properties (empty trucks vs. full trucks, for example) are floating through the system.
In the case of the Image.s8 model, there are two types of trucks:
(1) Red flat bed trucks hauling steel pipes
(2) Blue tanker trucks
So, the first thing our little example model does is to set an initial image for our truck work items as they arrive in the model. If you open the Label Actions properties for Work Entry Point 1, you'll see that we have defined a label named "Image:Truck" and that, for each work item (truck) generated, this label takes on an initial value of either 1 or 2. The model includes two basic, leftward facing icons for the red and blue trucks, which are named Truck1 and Truck2 respectively.
Now that we've got the basics set up, we are ready for the following-a-path part. Each truck is supposed to follow a given path on the screen. We can emulate this movement by placing work centers at each 'turning point' in the animated road, then using these work centers to change the value of the "Image:Truck" label for each truck as it passes by. If the road makes a clockwise 90 degree turn, we will want our icon to make a clockwise 90 degree turn too. The trouble is, it can get confusing keeping track of which direction our icons are going, and which label name goes with which direction.
We have found it convenient to handle this by using a simple little trick that, once again, is tied to naming the series of graphics cleverly. Have a look at the Images dialog (under the Graphics menu). If you scroll down, you'll find embedded images named Truck1, Truck10, Truck100 and Truck1000. From the thumbnails you can see that the truck images vary only by their rotation, and have suffixes that are multiples of 10.
Using a Work Center to multiply the current value of the Label "Image:Truck" by 10, will cause either truck type to rotate clockwise 90 degrees. Dividing by 10 will rotate the truck counter-clockwise 90 degrees. To explore how this all works, first run the animation. Then examine how the label values are modified in each of the work centers to achieve this effect.
Reader Comments