In this tutorial we will show you how to explore the creative possibilities of typography with code. Using the programming environment Processing, we will be going through a wide variety of techniques and algorithms. These code examples all have one thing in common: they start with type. But while they all use typographic base forms as a starting point, they subsequently move into very different creative territories. Some use an aggregate drawing technique, much like a traditional painting. Placing layer upon layer to create subtle trails or interesting shape compositions. Other code examples show you how to export code-created visuals as high-quality vectors using Processing’s PDF support. Finally, some examples take type into the third dimension to create virtual sculptures based on the letters and words you choose to put in. Besides a great variety, these examples also cover a wide range of skill levels. Basically the complexity increases as we progress. So there is something for everyone: from novices to intermediate and even advanced coders. We hope you find these examples useful and inspiring. And remember, they are not meant as a visual end result. Instead, they are nothing more than a starting point for further exploration and creative coding. In this blog post we have included a preview image for each code example. The preview image contains the name of the sketch on the top-left and the name of the font (using the font itself!) on the bottom-right. This will also make the blog post a good reference for later, when you’re looking for that specific sketch. Now let’s get started!
Setting things up
To state the obvious, you will need Processing to run these examples! :-) All code examples were written using Processing 2.2.1 (released on May 19th 2014), which can be downloaded here. All the code examples themselves can be downloaded from this central GitHub repository. My advice is to download the complete repository using the “Download ZIP” button on the right side of the screen. In the GitHub repo’s main readme file the external library dependencies are indicated after the code example’s name. You may notice that some of the examples have dependencies such as Geomerative (by Ricard Marxer), HE_Mesh 2014 (by Frederik Vanhoutte) and/or Mesh (by Lee Byron). To run these examples, you will need these respective libraries. The Geomerative library can be installed via Processing’s library manager, which can be accessed via Sketch > Import Library > Add Libary. The HE_Mesh 2014 and Mesh libraries must be downloaded from the linked sites and installed manually. Instructions for installing libraries manually can be found here. For the rest of the tutorial, We will assume the correct version of Processing (2.2.1) has been installed on your computer, the complete repository with runnable code examples has been downloaded and the required libaries, where needed, are in place.
We have divided the code examples in four categories (read: folders in the GitHub repo) which we will cover one by one in this tutorial. The recommended order for the examples is included in the GitHub repo (tip: it is also the order of the preview images in this blog post!). We have tried our utmost to keep the code examples as short and sweet as possible. In addition, there are many comments included in the source code of all these examples. Personally we find that short, commented code examples usually make it easier to understand what is going on behind-the-scenes. Which in turn makes it much easier to tweak the examples. In that sense, the real work is in the code. This blog post is more of a walkthrough and a way to present the code examples to the world, so they may be shared among a larger group of interested people.
1. Getting Started
The “Getting Started” category is solely intended for novices. This folder in the GitHub repo contains four tiny sketches, which cover some of the essential Processing methods used in subsequent examples. Topics that are covered include displaying text, checking the available fonts on the system, using a custom font and finally creating and displaying a PGraphics, which is an offscreen graphics buffer. Those that are already familiar with Processing may either skip these examples or glance over them briefly. This tutorial won’t teach you Processing from the start, but it might get you going and see the possibilities of creative coding. For those that have never used Processing before, there are many valuable resources (such as the reference, the tutorials, the forum and the “Hello Processing” videos) that can all be found through the main Processing website.
Now things will get a lot more interesting! The “Image-Based” category contains a total of eight code examples. None of which has external library dependencies, so only Processing is needed. All of them are based on the same principle: is this point inside or outside the typography? Some of the first examples such as InsideOutsideText, GradientCutout and Waves use this principle in a fairly basic manner to get you started with as little code as possible. This will allow you to grasp the basic techniques used.
Then the same basic code is used to slightly more advanced effect in the examples AggregateDrawing, AggregateParticles, FlowField and FlowFieldVariant. None of these sketches has a background() call. This means previous drawings are not cleared or in other words: all drawings are cumulative. Actually, the technique of aggregate drawing can create some pretty nifty visual output. In fact it may be much more complicated to recreate such results, if you had to do it in one single take. Luckily, we don’t. So we can just watch points and particles flow across the screen, forming complex graphics as they leave trails on the canvas. With these kind of sketches, the most important thing is the behavior of the graphic elements. See the sketches for much more details on the algorithms used in these respective cases.
Finally, there is one oddball in the “Image-Based” category, which is the ReactionDiffusion example. Instead of agent behaviors, this example uses scientific formulas to determine pixel colors. To be a little more exact, it uses mathematical models on local chemical reactions, where the settings are based on the core principle mentioned earlier: is this pixel inside or outside the typography? This last example also comes with a slight warning, as the code related to the mathematical models (encapsulated in the example’s RD class) is more advanced than most other code examples in this tutorial. Final note with regard to these examples (and all others in this tutorial for that matter), in the code examples on GitHub I always use the word “TYPE” as the base string, making it really easy for you to find the place where to set the text that will be used to generate the visuals.
3. PDF Export
Let’s move on to the second category of code examples, namely the “PDF Export” category. Of course, the in/out principle is just as important here, but there is a new and common element that binds these examples together as a group. As the name suggests, this is of course the ability to export what you see on the screen, to a high resolution (read: vector graphics) PDF. Such a PDF may be opened in Illustrator or any other vector editing program. There the graphics can be further tweaked, moved around and most importantly exported to high quality output at resolutions much higher than those of a computer screen. For starters, the familiar Waves examples presented earlier, is recreated in the WavesPDF example. While visually identical, the ability to export to PDF has been added. This will allow you to, see the changes between the two sketches. Perhaps even by placing them side-by-side. Then you will see just how little code is actually needed to turn any sketch into a PDF-exportable sketch! The CirclePacking example builds upon this by exploring a new algorithm and combining it with the recently gained ability to export results to PDF.
The UsingGeomerative introduces you to the Geomerative library. This library is incredibly useful when it comes to working with typography (or SVG for that matter). In fact, this library will be used in every example from this point onwards. So be sure to check out this first example, because the groundwork is laid there. One important thing that can be done with the Geomerative library is extract detailed information from typography, for example points, lines or faces. This information is of incredible value, because once you and your code know these kind of details, you can (re)create the typography instead of just display it. More importantly, you can now also destroy the typography! Or to put it differently, explore new creative possibilities based on typographic form. The two examples LinesCircles and Ocean show this. They take the basic information of a font and use it in the code.
As the name suggests, the VoronoiType and VoronoiVariant examples take the font information to generate voronoi shapes using the Mesh library. Do you like ‘em better than plain ol’ lines and circles? Before we move on, a final note with regard to the Geomerative library. It requires a TrueType (TTF) font as input. In the GitHub repo a basic font is included in the Fonts folder. We have used fonts that were graciously provided by YouWorkForThem. As mentioned before, you can see the used fonts in the bottom-right of the preview images in this blog post. Also, at the end of this tutorial, We will provide a convenient list and links to more information. For now I would just like to give you one practical tip. Many fonts are distributed in the OpenType format (OTF). I found this website to be very fast and effective in converting OTF-fonts to TTF-fonts, so they can be used successfully with the Geomerative library.
And now the pièce de résistance, the code examples that take type to the third dimension. We knew we wanted to cover 3D with this tutorial as well. Even though adding a third dimension usually means adding the kind of complexity that makes code advanced. And indeed, you should consider all of these examples as intermediate or above (beginners beware! ;-). All of the examples in this category make use of the HE_Mesh 2014 library by the amazing Frederik Vanhoutte / @wblut. Fortunately much of the heavy lifting is done by this library, making our jobs a hell of a lot easier. Like the previous categories, there is a gradual build-up. So once again, it is highly recommended to follow the recommended order! :-) We start with the Basic3DType example, which shows you how to extrude type into the third dimensions using any TTF-font and any word you want. It may seem simple now (especially since we have already done the work for you), but this is actually the biggest step of all. All the other examples just build upon this basic process, that turns a word into a 2D shape and then extrudes it into a 3D shape. Once we have a 3D shape, we can manipulate it. But since mesh manipulation often creates complex shapes (read: lots of vertices) we first learn how to turn a Hemesh into a PShape with the HemeshToPShape example. The PShape is one of Processing’s most powerful advanced classes, because it allows you to store and display geometry on the GPU.
Now that we have set up the 3D basics, we can move on to bigger and better things! The MeshManipulation, Deconstructed and SlicedUp examples show you just a few of many interesting ways to manipulate and destroy meshes using the Hemesh library. The two final examples FlowField3D and SpherePacking take the in/out principle referenced earlier and apply it to 3D. In fact not only the names, but also the techniques are very similar to their 2D counterparts. If you hadn’t noticed yet, the FlowField3D example is featured quite prominently in the opening and ending of the promo video for this tutorial. One word of warning, manipulating shapes with the Hemesh library can be computationally costly. Especially when you use subdivision. In other words, be patient. To give an idea of what’s going on behind-the-scenes, we have added console output to most of the 3D sketches. That way you’ll have some insight in how long it might take. Tip: more letters = more geometry = slower sketch. Use that knowledge to your advantage!
Here are a couple of suggestions on things you can do when the console turns red.
- The following warning message “WARNING: Unevenly distributed hash code – Degraded Performance” is caused by the Hemesh library when you are doing heavy calculations (read: complex geometry). It’s basically a sign that you’ll have to be patient. Other than that, the message is harmless and can be ignored.
- The following warning message “Stroke path is too long, some bevel triangles won’t be added” is caused by Processing’s OpenGL renderer. It usually occurs when there is a lot of complicated, intersecting geometry on the screen. The message is harmless and can be ignored.
- Many of the sketches use a smooth(16) setting to make the sketches look awesome. The maximum smooth setting depends on your graphics (for example in my case it is 32). If your graphics card cannot handle the smooth setting, it will be fixed automatically and the highest possible smooth setting on your system will be used instead. In addition the following warning message will be printed to the console: “Smooth level [##] is not available. Using [##] instead”. You can leave the code as-is and ignore the message or you can change the code to adapt to your computer’s maximum smooth setting in order to remove the console warning altogether.
- The error message “Cannot find a class or type named WB_Point” indicates you are using a different version of Hemesh than the one required to run these code examples. Follow the link in this blog post or on GitHub to download the correct version of Hemesh, namely HE_Mesh 2014.
- When you get a NullPointerException error message stating “The file “../../Fonts/FreeSans.ttf” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.”, this means that you are not pointing to a TTF file on your computer. Either download the GitHub repo as a whole, which includes a default font and correct relative paths, or point to a full path on your computer where there is a TTF file.
- There are different types of error message like this: “Error: OpenGL error [####] at top endDraw(): [some error message]”. As a general guideline, number 1280 can usually be ignored without impact, while 1281, 1282 and higher will have a bigger impact. Especially 1285 and 1286 are known to be show-stoppers. If the sketch runs fine, the error can be ignored. If your screen remains black, then it needs to be solved. These errors can be caused by older graphics cards, outdated drivers or issues in the Processing OpenGL-related source code. Since all of these things are out of my control and go far beyond the scope of this tutorial, We cannot provide assistance with regard to these types of errors. Luckily many of these issues have been discussed on both the Processing forum and Processing’s GitHub issue tracker, so the best remedy is to search for the specific error and see what causes and solutions have come up.
The above are all known warning messages and errors you may encounter. When you see real bugs/issues with the code examples, please report them using the GitHub repo issue tracker. Please note that the issue tracker is for bugs in the code examples only! Do not use it as a helpdesk for support (for that you can use the Processing forum) or if you have questions that go beyond the scope of this tutorial.
As mentioned before, we have used many beautiful fonts provided by YouWorkForThem for the preview images in this blog post and the visuals shown in the movie. From big bulky fonts to thin and graceful ones. Depending on the base shape you get from the typography, the resulting visuals will be very different as well. Here is an overview of all the fonts that were used and for which sketches we used them. When you click the font’s name, you can see its information page on YouWorkForThem:
- Agafia – LinesCircles, SpherePacking
- Borden regular – WavesPDF, CirclePacking
- BreakersSlab Bold – Basic3DType, Deconstructed
- Dobra Black – GradientCutout, HemeshToPShape, SlicedUp
- Good News Sans Black Extended – InsideOutsideText, Waves, FlowField3D
- Knul Light Italic – FlowFieldVariant, MeshManipulation
- Leksa Black – AggregateParticles, ReactionDiffusion
- Mandevilla Regular – UsingGeomerative, VoronoiType
- Selly Light – VoronoiVariant
- Shiva Regular – Ocean
- YWFT Motown – AggregateDrawing, FlowField
This tutorial has taught you several important building blocks that you can use to experiment with generative typography in Processing. Now we challenge you to take these code examples one step further if you can. Use them as a stepping stone for your own creative vision! In many ways, this tutorial has actually been quite conservative with regard to the settings. We wanted the preview results to still look like type (mostly). Of course, with code it’s very easy to go all out. Change one value from 0.10 to 10.0 and you can make the end result completely unrecognisable. Then it won’t be so clear that type was used as the base form. That might be something to look into. Besides the settings, you might also wanna change the code itself. There are a thousand things to tinker with! Perhaps you want to combine two techniques into one sketch? Or take a 2D sketch into the third dimension? Like we did with the FlowField3D and SpherePacking examples. In our view, that is one of the greatest things about code. The infinite possibilities, especially since you decide where you want to take this. Feel free to let me know on twitter via @AmnonOwed what great things you made or maybe just what you thought about this tutorial on generative typography. And please spread the word through social media, so more people can check it out and hopefully create awesome projects and beautiful visuals. As always, have fun and happy creative coding! :-)