Drawing curves
Straight lines can be boring sometimes, so it might be useful to draw curved lines to make your artwork look a little more organic. In this recipe, we'll take a look at how you can draw Bézier curves and Catmull-Rom splines. If you have used vector graphics software such as Adobe Illustrator or Inkscape before, you might recognize the Bézier curves we'll draw.
How to do it...
The first thing we need to do is to import the OpenGL library. This library is usually used to draw in 3D. Although we won't be drawing in 3D in this example, we need to import it because the bezierDetail()
and curveDetail()
functions don't work with the standard 2D renderer. You can import the OpenGL library by going to the Sketch | Import Library... | OpenGL. Once you have done this, you can type the following code into the editor:
import processing.opengl.*; void setup() { size( 640, 480, OPENGL ); smooth(); }
Inside the draw()
function, we'll start with drawing some Bézier curves. The bezierDetail...