Big Bad Beetle Blocks
A Scratch-like language for 3D
ByBeetle Blocks is an interesting twist on the “block-building programming language” idea. Instead of a flat, boring plane, you move a beetle around 3D space, drawing cubes, spheres and all sorts of other shapes.
Beetle Blocks [1] lets you build 3D objects by ordering the Beetle Blocks beetle around. You do this in true Scratch-like fashion by dropping blocks containing commands such as move
, go to
and rotate
onto the workspace. You can then chain several blocks together to build programs, just like in any block-based program (Figure 1).
The difference here is that with Beetle Blocks everything happens in 3D. In Scratch, for instance, you can turn the kitty sprite on only one axis only – it's yaw axis (see Figure 2 on the next page). In Beetle Blocks on the other hand you can rotate the beetle, three axes, on its yaw, pitch and roll axes, using a block like this:
Likewise, while you only needed two coordinates, x and y, to place your sprites in Scratch, Beetle Blocks needs three to position your beetle: x, y and z.
You can also decide to draw lines and curves, or extrude them. This in practice means that as the beetle walks it you can have it leave a 3D sausage-like trail behind it.
Beetle Pi
Despite what the main website says, Beetle Blocks works fine in Firefox. Sadly, it does not work in the Pi's default browser Chromium ; the editor site won't even load. So, if you haven't got it yet, go grab yourself Firefox for your Pi with the command:
sudo apt-get install firefox-esr
Firefox will install in the Internet submenu. Open it and go to the online editor [2].
Wait for the interface to completely appear, including the little picture of the cyan-colored beetle, before you start working. Otherwise, the interface may freeze for a few seconds.
Dragging and dropping blocks onto the workspace is generally fine on a Raspberry Pi 3, although sometimes it can be sluggish. Performance is better if you use openSUSE (included in this month's DVD) instead of Raspbian. This may be because openSUSE, being a true 64-bit operating system, makes the most of the Pi's hardware.
If you want to work offline, you can download all the Beetle Blocks framework from the project's GitHub with:
git clone https://github.com/ericrosenbaum/BeetleBlocks
Open Firefox, press [Ctrl]+[O], and navigate to the directory where you downloaded Beetle Blocks. Inside the run/ subdirectory, click on the index.html file, and a local editor will open in your browser.
Beetle Server
Beetle Blocks is written in pure JavaScript, so doesn't need a server or any external dependencies to run. However, if you want other people such as students in your classroom to access the Beetle Blocks web page, you can run your own basic web server locally.
The web server lighttpd is a good choice since, as it's name suggests, it's very light and will not overload your Pi. Besides, for serving a bunch of JavaScript it's all you'll really need.
Open a terminal window and type:
$ sudo apt-get install lighttpd
Once installation is complete, the server will launch automatically. You can check by opening Firefox on your Pi and navigating to 127.0.0.1 (or, from another computer, put your Pi's IP into a web browser). If you see something like Figure 3, everything is fine.
Next copy other the contents of Beetle Blocks' run/ subdirectory to a subdirectory under /var/www/html/ like so:
$ sudo mkdir /var/www/html/bb $ cd /download/directory/BeetleBlocks $ sudo cp -Rv run/* /var/www/bb/html/
Now, using a web browser on another computer, go to http://<RPi's IP>/bb (Figure 4).
Most of the code for Beetle Blocks runs in the browser anyway, so loading the program from a Pi for an entire classroom is quite doable.
Basic Shapes
One of the cool things you can do with Beetle Blocks is draw a shape at the beetle's position. Open the Shapes category and drag out…
… then click on it. The beetle will draw a sphere. This may not sound like much, but think of the applications: this is probably the easiest way to draw and visualize 3D objects.
Take for example, the code, in Listing 1. It uses this technique of moving the beetle and drawing an object to generate a complex 3D function. It essentially consists of a loop within a loop, the innermost counts from -10 to 10 for y the position of the beetle.
The outer does the same for the x position. z, the vertical position of the beetle, is the result of multiplying the cosine of y by the sine of x. You then use a go to
block with your x, y and z values to simply draw a sphere.
This generates the rather marvelous-looking 3D graph shown in Figure 5.
The other thing you can do is extrude. This makes the beetle leave a 3D trail as it "walks". The program in Listing 2 shows how to do this and builds the "sausage pyramid" seen in Figure 6.
Your own shapes
Beetle Blocks is based on Snap! [3] and, as we explained in issue 6 [4], this means you can combine blocks to build your own instructions. Right click on an empty region in the central workspace and a menu will pop-up. Choose Make a block and Beetle Blocks will then bring up a wizard which will allow you to create your own by combining several basic blocks. This means you can use the block editor to create more and more complex shapes from basic shapes and embed them in your own blocks to simplify your programs.
At some stage you will want to save your programs permanently to your hard disk. You can do this by clicking on the file icon in the upper toolbar and selecting Download project as…. You can then download your work as an XML file. You can open your program later in any other instance of Beetle Blocks by choosing Import project or blocks from the File menu. The XML file also saves all the custom blocks you may have created for the project.
You can also extract your custom blocks from the project and save them independently to re-use them later in other projects. Click on the File icon at the top of the screen and this time choose Download My Blocks as…. This will open a window showing the custom blocks you created for the project. You can then mark the ones you want to save. Import your blocks into a new project by selecting Importing project and blocks… from the File menu and the navigating to where you saved the XML file containing the blocks.
Another interesting entry within the File menu is the option to export your 3D object as an STL file. Click on File and go to Download 3D model as… and pick STL. STL is quickly becoming the standard file format used to exchange 3D objects between different applications (Figure 7). This has an exciting side effect; whatever you tell the beetle to draw can later be turned into a physical object thanks to the magic of home 3D printing.
Conclusion
Beetle Blocks is fun, easy and 3D. Anyone familiar with Scratch will be able produce complex shapes and visualize 3D functions in minutes. It works well on the Raspberry Pi and you can even get real, physical objects from what you design thanks to its export to STL feature. store.
Info
- Beetle Blocks: http://beetleblocks.com
- Beetle Blocks online editor: http://beetleblocks.com/run/
- Snap!: https://snap.berkeley.edu/
- A Web-based Alternative to Scratch, Issue 6: http://www.raspberry-pi-geek.com/Archive/2014/06/A-web-based-alternative-to-Scratch
next page » 1 2 3
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
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.