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.
TIP
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.
Spinning Wheel
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.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
News
-
Linux Mint Finally Receiving Support for Gestures
If you use the Linux Mint Cinnamon desktop, you'll be thrilled to know that 21.2 is getting support for gestures on touchscreen devices and touchpads.
-
An All-Snap Version of Ubuntu is In The Works
Along with the standard deb version of the open-source operating system, Canonical will release an-all snap version.
-
Mageia 9 Beta 2 Ready for Testing
The latest beta of the popular Mageia distribution now includes the latest kernel and plenty of updated applications.
-
KDE Plasma 6 Looks to Bring Basic HDR Support
The KWin piece of KDE Plasma now has HDR support and color management geared for the 6.0 release.
-
Bodhi Linux 7.0 Beta Ready for Testing
The latest iteration of the Bohdi Linux distribution is now available for those who want to experience what's in store and for testing purposes.
-
Changes Coming to Ubuntu PPA Usage
The way you manage Personal Package Archives will be changing with the release of Ubuntu 23.10.
-
AlmaLinux 9.2 Now Available for Download
AlmaLinux has been released and provides a free alternative to upstream Red Hat Enterprise Linux.
-
An Immutable Version of Fedora Is Under Consideration
For anyone who's a fan of using immutable versions of Linux, the Fedora team is currently considering adding a new spin called Fedora Onyx.
-
New Release of Br OS Includes ChatGPT Integration
Br OS 23.04 is now available and is geared specifically toward web content creation.
-
Command-Line Only Peropesis 2.1 Available Now
The latest iteration of Peropesis has been released with plenty of updates and introduces new software development tools.