Visual programming with Alice
Lost in Space
Other than the fish, a few more objects are in the scene: In addition to the background, you have a camera through which you look straight into the ocean. In the upper left corner of the window, Alice lists all of the objects, highlighting the currently selected object in yellow.
The camera and the ground also have properties you can modify. To do so, click on the name of the corresponding object in the top left corner or select it on the right edge of the drop-down list, which is currently labeled this.Nemo. This action lets you retroactively modify the background. The 3D world is also an object in its own right, with the less than intuitive name this. However, this does let you change the lighting for the entire environment or envelop it in fog: In the drop-down list, click once on this and look at the properties. The names of the other objects start with this because they are located in the environment.
If you want Nemo to swim back and forth, you need a matching sequence. Press the Edit Code button or select Window | Perspectives | Edit Code to return to the previous view, where you see Nemo in the top left corner. Directly below, you find a list of all actions and tricks that Nemo has up his sleeve. You could talk to him (say) or move him, for example. Alice refers to all of these actions as procedures.
If you want to get rid of a procedure from the code editor, just drag it back into the list on the bottom left. A trash can icon appears, and you can release the mouse button over it.
Next, I want Nemo to swim across the screen to the right. At the moment, he is looking straight ahead, so the first step is to point him to the right. In the list, find the procedure turn (in the orientation section), then drag this action to a spot on the still empty page on the right side that reads drop statement here (in Alice 2: Do nothing).
Alice now wants to know in which direction to turn Nemo. For the fish to look to the right, it has to rotate left. In other words, say Left. Then, you can fill in the amount to rotate Nemo. In this case, the value is 0.25 (Figure 6), which is a quarter rotation about Nemo's own axis. To check, click the Run button. This will open a new window in which Nemo looks to the right (Figure 7). Close the window again.
Note that you could have turned Nemo to the right in the Scene view by clicking Rotation in the top right-hand corner and then dragging one of the hoops around Nemo to the right with the mouse.
Next, I want Nemo to swim to the right. You can do this with the move procedure. Drag the procedure out of the list on the left edge to the right below the turn action. If you want Nemo to swim straight ahead, select Forward from the list. A value of 2.0 would cause Nemo to float into the middle of the screen, whereas 10.0 would let him disappear from sight. Thus, you need to press Custom DecimalNumber, enter a value of 3.5 in the pop-up calculator, and then press OK.
Now, when you press Run, Nemo swims to the right. However, the whole thing still runs relatively quickly. To change this, click add detail in the move action. To influence the duration of swimming, you can choose duration and then 2.0. This will slow down the animation by half.
Forever and Ever
At the end, Nemo needs to turn around. To make this happen, drag the turn procedure to a position below the other two in the editor. Nemo needs to rotate clockwise (right) by a value of 0.5. He is then looking left again. With a further move action, Nemo floats straight back to his starting position (forward) with a value of 3.5. Again, enter this as a Custom DecimalNumber. For simplicity's sake, you can keep the default value for the speed.
Finally, Nemo should look straight ahead again. To accomplish this, drag the turn procedure into the editor once again and rotate Nemo left by 0.25. The program should now appear as shown in Figure 8. Once you launch the code by pressing Run, Nemo swims to the right, turns around, swims back, and looks straight back at you.
To tell Nemo to swim to the right again, you would normally have to restart the program. Fortunately, Alice can also run procedures in a loop. To do this, close the preview window and take a look at the control tiles on the bottom right, where Alice hides a few special moves. Drag while into your editor to a position above all the previous procedures. Alice indicates this with a green line, where it would insert the action, if you let go of the mouse button.
From the drop-down menu, select true (more on this later). Move all the existing procedures to a position between while and loop. The result should be as shown in Figure 9. You have defined an infinite loop: while the value of true is equal to true (i.e., always) Alice will perform all the procedures up to loop. Nemo thus swims endlessly back and forth. You can verify this by pressing Run. To stop the program, simply close the window.
Buy this article as PDF
Innovative system adds a hard drive and Ubuntu Core to the RPi for an IoT hub.
Linux is two weeks younger than we thought!
The Apache Software Foundation considers retiring OpenOffice
Adobe won’t kill the plugin in 2017
Linux Foundation's big event celebrates the 25th anniversary of Linux
Linux has evolved from “won’t be a professional” project to one of the most professional software projects in the history of computers.
Competitors get in the game with RHEL without Red Hat
Security researchers have already notified Microsoft; some fixes are available
The company is collaborating with Google and Intel to use Kubernetes as an engine for Fuel