Outils pour utilisateurs

Outils du site


issue102:tutoriel_4

Ceci est une ancienne révision du document !


This month we're going to start looking at Live Path Effects (LPEs). These are a way to add more powerful capabilities to paths – such as drawing a pattern that follows a path (for creating ropes and chains), or rendering a path as though it's been roughly sketched. There are 13 LPEs in version 0.48, increasing to 15 in 0.91 with a slight change of UI as well.

Let's dive straight in with a relatively simple LPE: Spiro Spline.

Draw a path using Bézier tool, consisting of straight lines forming a simple spiral type of shape. Something like this:

Now select the path and open the LPE dialog using the Path > Path Effects… menu option (Path Effect Editor… in 0.48). At this point, the user interface diverges. To add the Spiro Spline LPE to your path: • In 0.48.x, select “Spiro spline” from the drop-down list of effects at the top of the dialog, then click on the Add button next to it. • In 0.91, click the “+” button at the bottom left of the dialog. This will open another dialog listing the available effects. Scroll down and select “Spiro spline,” then click the Add button. The second dialog will close, adding the effect to the list in the main dialog.

With the Spiro Spline effect added to your path, you might be a little underwhelmed to see that there's been no change to the appearance of your spiral. This is because the spiro algorithm works only on paths where some of the nodes are smooth or symmetrical. Currently, all the nodes in our shape are corner/cusp nodes. Double-click on the path to both select it and switch to the node tool, and you should see that all the nodes have the diamond-shaped handles that represent cusp nodes. Press CTRL-A to select them all, and use the buttons on the tool control bar to change them to smooth, symmetrical or auto-smooth. Immediately you should see the effects of the spiro algorithm, as your square spiral turns into a super-smooth version.

You may be forgiven for thinking that your new spiral is just a normal result of switching to smooth nodes, but that's not the case. In the LPE dialog, you'll notice that the Spiro Spline entry has an “eye” icon next to it. Click that to toggle the effect on and off, and you'll notice that the spiro version of the path is noticeably smoother than the normal version. Here's the original (black), smooth (green), and spiro (purple) versions of the path – overlaid on top of each other so you can more easily see the differences between them.

The real difference comes when you start to manipulate the path: spiro splines are indifferent to changes in the node handles, so the most practical way to modify the path is to move the nodes themselves. The algorithm is a little unstable, and can sometimes shoot off into wild shapes as you do so; undoing your edit, or moving the nodes a little more, will generally get things back on track. For example, this image shows a green original path, plus the same path with the spiro LPE added in purple, demonstrating just how out-of-control the spiro algorithm can get!

As well as moving nodes, there's one other way to manipulate spiro paths: straighten some sections. Simply select the end nodes of a segment and use the “Make selected segments lines” button on the tool control bar to straighten it. The spiro algorithm will ensure a smooth transition between straight and curved segments. If you need to introduce a sharp transition into your path, you first have to convert one of your smooth nodes into a corner node. That alone isn't usually enough to do the job though – moving the adjacent node to one side will usually also alter the path on the opposite side in an effort to maintain the spiro path's smoothness. The secret is to move the handles of the corner node so that they're no longer co-linear, then you'll be able to move the spiro paths on either side as you would expect, with a sharp transition occurring at the corner node.

The spiro algorithm was originally created by Raph Levien for font design (see http://www.levien.com/spiro/ for more details), but it can also be useful for flowing, organic shapes such as plants, leaves, and… tentacles. It's so useful, in fact, that Inkscape has dedicated buttons on the Bézier and Pencil toolbars which automatically add the Spiro Spline LPE to any lines you draw with them. Select the Pencil tool and ensure that the smoothing is set to about 50% - a little either way won't make much difference. On the tool control bar (shown above), enable Spiro mode using the second button on the bar:

Now it's time to draw something on the canvas: the kind of shape that suits spiro mode. Try drawing a circle, keeping it as neat as you can, and finishing in the starting node. As you draw you'll see a green line indicating your path, regardless of your current fill and stroke settings – don't worry, that's just a guideline that won't be visible when you've finished. Unless you have supernatural control over your muscles, the green path is likely to be bumpy and distorted; yet, on releasing the mouse button, it will be replaced with a nicely rounded circle. If your original path was extremely rough, you might not get a perfect circle, but the final shape will certainly be a lot smoother than your hand-drawn efforts.

Select the path you've drawn, and, in the Path Effects dialog, you should see that the Spiro Spline effect has been added. Toggle the visibility button (the eye-shaped icon) to see how the spiro version compares with your original path. Now try the process again with a different shape – a figure of eight, or a spiral. As you can see, for some shapes it's a lot easier to create something neat and smooth using spiro mode.

When using the Bézier tool in spiro mode, the icon on the tool control bar is the same, but the drawing process is a little different. I usually suggest drawing Bézier paths as a series of straight line segments by single-clicking to place each node, then going back in Node Edit mode to add curves afterwards. If you take that approach with spiro mode enabled, you'll get a series of corner nodes which, as we've seen, don't really play a role in the spiro algorithm. Instead you need to click-and-drag as you place each node, in order to set the curves as you go along. Personally, I find this to be much harder to control, but give it a try to see if you're better at it than me! You can always lay down straight segments with spiro mode enabled, then explicitly change some points into cusp nodes afterwards. It's not a huge workflow improvement, but does save you a trip to the Path Effects dialog to manually add the LPE.

One big problem with having spiro buttons on these two tools it that it's easy for newcomers to Inkscape to enable them, then forget about it. A common question on the support forums is, “why can't I change the shape of my path using the node handles?” The answer is usually because the Spiro LPE has unintentionally been added, so watch out for that if you find yourself similarly stuck.

Let's move on to another LPE: Gears.

You first have to draw a path with at least three nodes – to begin, I'll use exactly three so that it's clear what the relevance of each one is. With your path drawn and selected, open the Path Effects dialog and add the Gears LPE. You should immediately see your path replaced by a gear. Double-click on it so that you can see the three nodes and move them around. It should quickly become apparent that the nodes are used to set: 1) The angle of the first gear tooth, relative to the center point. 2) The center point of the gear. 3) The radius of the gear (from the center to the mid-point of the tooth). With your gear selected, switch to the Bézier tool. The start and end nodes of your path should be visible: click on the end node, then double-click somewhere else on the canvas to add another segment to your path. Now the path has four nodes, and you should find that a second gear has been added, centered at the new end node.

You can repeat this process to add more nodes, and hence more gears. Applying the Gear LPE to any path with more than three nodes follows the same rules: the first three nodes define the parameters for the first gear, and any subsequent nodes set the center points for additional gears in the chain. Once you've got a few gears on screen, switch to the node tool to move their centers, noting how Inkscape automatically adjusts the radius and number of teeth in the process. Try dragging the first node around the second one to crank your gear train into life (after all, it is a LIVE path effect).

As well as the values that are implicitly set by the positions of the nodes, there are two additional parameters required to fully specify the effect. These can be found at the bottom of the Path Effects dialog, in fields labelled “Teeth” (the number of teeth on the first gear), and “Phi” (the “tooth pressure angle” - set it to about 20 for realistic looking teeth). Almost all LPEs populate this part of the dialog with a UI of some sort, and in some cases the number of additional parameters is rather excessive (watch out if you're working on a small screen!).

You may have guessed from the UI that it's possible to apply more than one LPE to a path. In programming terms you can think of an LPE as a function that takes a path as an input, and produces another path as an output, allowing you to chain them together. Be aware, however, that the order in which you chain them is significant. Consider this simple path, made up of cusp nodes: If we apply either the Spiro Spline or Gears LPE to the path we get the results we'd expect:

But if we apply both LPEs to the path, the effects differ greatly depending on the order. We'll start with the least surprising combination: Gears first and Spiro Spline second. It may not be easy to see, but the only real effect is that the teeth of the gears have become more rounded (though each gear also has one tooth that's misshapen). Thinking about our chain of LPEs the general effect makes some sense: the first LPE outputs a composite path in the shape of the gears, then the spiro algorithm is applied to that path, smoothing out any cusp nodes that are present in it. But what happens if we apply the Spiro Spline LPE first, and the Gears LPE second?

Now we've got a load more gears! This is because the path that is created by the Spiro Spline LPE has more nodes than our original input path. Although we drew 6 nodes, the spiro version of the path actually has 13, so when the second LPE runs it creates a lot of extra gears. We could have predicted this result had we only kept an eye on Inkscape's status bar: when an LPE is active it shows the number of nodes in the output path, not the number in the original path. Try using the Gears LPE again, and have a look at how many nodes that generates!

Why not practice drawing naturalistic curves and mechanistic gears, then next time we'll continue to look at some of the other LPEs that are available.

issue102/tutoriel_4.1446400263.txt.gz · Dernière modification : 2015/11/01 18:51 de auntiee