TNS
VOXPOP
How has the recent turmoil within the OpenAI offices changed your plans to use GPT in a business process or product in 2024?
Increased uncertainty means we are more likely to evaluate alternative AI chatbots and LLMs.
0%
No change in plans, though we will keep an eye on the situation.
0%
With Sam Altman back in charge, we are more likely to go all-in with GPT and LLMs.
0%
What recent turmoil?
0%
Tech Life

Off-The-Shelf Hacker: Spin Text And Scroll Objects with Processing

Dec 5th, 2015 9:54am by
Featued image for: Off-The-Shelf Hacker: Spin Text And Scroll Objects with Processing

Following up on last week’s introduction to the Processing sketchbook, this week in the Off-The-Shelf Hacker we’ll go a little deeper and cover a couple of examples of animating text and shapes. These techniques are useful for displays, user notification and digital signage. The techniques are suitable for use on my Raspberry Pi-based presentation machine. Don’t forget that Processing maps into the Arduino and the physical computing environment so you could easily use the logic for both Raspberry Pi and Arduino projects.

processing3-move-text-shapes

Let’s Spin Some Text


The sketch opens a window on the desktop (or your Raspberry Pi connected HDMI screen) and displays text rotating around its center axis using the rotate() function. Keep in mind that rotate requires an angle measured in radians, from 0 to 2 pi. To use degrees, substitute the lines with “deg” in place of the standard rotate() measures. Change the rotation direction by decrementing the rotate angle.

You’ll also notice the delay() function at the bottom. Depending on your processor, the text may spin too quickly, to be useful. Adding a delay provides rotation speed flexibility and is measured in milliseconds.

The fullScreen() function is a new feature, appearing in Processing 3. Comment out the size() line and uncomment the fullScreen line.

An interesting addition to spinning the text might be to add logic that expands the text from small letters to large, repeat. In this case, you’d manipulate the size variable in the createFont() function.

How could you use a sensor hooked up to an Arduino that spins text on your Linux notebook screen according to the sensor measurement?

Now Let’s Scroll Some Objects

How about making text or a square move across the middle of a window?


This sketch opens a new window and moves a text string across the screen with the translate() function. The text is centered up by dividing the screen height in half and using that as the y coordinate, in the translate function.

You’ll also notice the commented-out rect() function, immediately following the text() function. Translating objects, like a rectangle, is just as easy as text. In this case, a 100 x 100-pixel box will scroll from left to right across the screen. Other objects, like circles, photos and lines could be substituted, as well.

Going Standalone

The last topic I’ll cover today is creating a standalone application, from a Processing sketch. Normally, you’d develop the code and just run it in the Processing integrated development environment (IDE). Hitting the big right arrow at the top of the edit window runs the program and the square stops it.

Sometimes, it might be nice to be able to run your sketch, without going through all the effort of starting up the IDE. It could be some animation running before a presentation. It might be a display that responds to button presses or sensor input. We’ll get to those topics in a future column.

Building a standalone application is pretty straightforward.

Start up the Processing IDE and pull up your sketch. Next, click “File” and then “Export Application”. An “export options” window will appear where you can choose your platform (Windows, Mac or Linux), whether you want the app to run full screen or have a stop button and whether you want the Java runtime bundled with the application. I usually just pick Linux and let it rip. Processing will work it’s magic and in a short time, a file manager screen will show up with several directories containing files for the X86 32 and 64-bit environments, as well as the ARM (Raspberry Pi) platforms.

Simply cd into the appropriate directory and run the script from the command line.



I like to develop my sketches on my Linux notebook and then transfer them over to the Pi, mostly because I can type a lot faster on my notebook than my Pi’s portable keyboard. Obviously, if you are going to create sketches that use the Raspberry Pi general-purpose I/O pins (GPIO), it makes sense to develop on the Pi. Keep in mind, that programs accessing the Pi’s GPIO pins, generally need to be executed using sudo, otherwise you’ll get a permission error. We’ll go a little deeper into that topic in a later article, as well.

As usual, stop the sketch by simply typing a ctrl-c.

Wrapping it Up

I like Processing because, I grew up on the C language, so it’s very familiar, structured and logical. It has tons of libraries for all kinds of visual effects and integrates well on both the Raspberry Pi and Arduino platforms.

Give it a try for a few of your animated display jobs and let me know how they work out.

Feature Image: Non-linear code visualization from Dextro, using Processing.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Shelf, Torq, Simply.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.