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
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.