Outils pour utilisateurs

Outils du site


issue126:inkscape

Ceci est une ancienne révision du document !


Last month’s look at the Live Path Effects added in 0.92 included a section on the Simplify effect. This adds a “live” version of one of Inkscape’s existing tools (Path > Simplify), whereas the older tool modifies the original path. The next LPE we’ll look at fills a similar niche – it’s another live version of an existing feature. It’s the “Roughen” LPE.

The go-to tool for adding some randomness to the shape of a path is the Tweak tool, described in detail in parts 22 and 23. The latter article describes using the tool to modify the nodes of an existing path, including the ability to roughen the path by adding new nodes and slightly randomizing their positions. As with Path > Simplify, the procedure modifies the original path, so there’s no way to subsequently tweak the settings to retrospectively alter the result. The Roughen LPE does the same job, but, being a Live Path Effect, allows you the flexibility to go back and change its parameters after the fact. One trade-off for this capability is that the effect applies to the whole of the path, whereas the Tweak tool is interactively “sprayed” onto the path, allowing you to confine its effects to a particular area, should you need to. But, if you need to work on an entire path, it’s well worth further investigation.

To demonstrate this LPE, I’ve created a simple five-pointed star using the Stars and Polygons tool, then added the effect via the Path > Path Effects dialog. As you might expect, the dialog gains a number of parameters that can be adjusted to alter the result.

With the settings shown in the screenshot, my simple star was immediately distorted into something more random.

To get a better idea of what’s happening, I’m going to add another new LPE to the chain: Show Handles. This draws representations of the path’s nodes and handles, which can be invaluable when trying to gain an understanding of exactly how your input path has been changed by the applied LPEs (more on this later). The first thing to notice is that our five-pointed star (which, if converted to a path, would have had 10 nodes) now has 20 nodes:

This is due to the top section of the Roughen effect’s controls which adds extra nodes. More specifically, it adds nodes to each segment of your path, spacing them evenly along it. The number of nodes added is either determined directly by choosing the “By number of segments” option and setting a value in the “Number of segments” field; or indirectly by choosing the “By max segment size” option, and filling a value in the “Max segment size” field. The difference is clearer when you have a path with different segment lengths; consider this example of a right-angled path where the horizontal arm is about twice as long as the vertical one.

The top image shows the effect of using “By number of segments” to divide each path segment into two. The bottom picture uses “By max segment size”, resulting in two new nodes on the vertical arm, but three new ones on the longer horizontal arm. Returning to our star, therefore, the default settings split each segment into two, doubling the number of nodes.

Once you’ve created more nodes to work with, it’s time to jiggle their positions a bit. The “Jitter nodes” section lets you define the maximum amount that each node will be displaced – although the precise value for each is random. You can set different values for the X and Y directions, and the dice buttons will re-seed the random number generator, adjusting the node positions in either the X or Y directions accordingly. The “Extra roughen” section provides an additional displacement factor. This value acts as a multiplier – setting it to zero will cancel any displacement, regardless of how large the X and Y values are, whilst larger numbers increase the amount of displacement that takes place. This time, the die button re-randomizes the nodes’ positions in both the X and Y directions at once.

It’s worth noting that the random seed for each of these controls defaults to 1 when the LPE is first added to a path. If you have several similar paths that you wish to roughen differently, therefore, it’s worth clicking each of these buttons a few times. The actual seed isn’t visible in the UI, but can be found via the XML editor. The settings for LPEs are stored in the <defs> section near the top of the file, and if you’ve applied several to your page, you might need a little trial-and-error to find the relevant entry (tip: put an easy to spot value, such as 9.999 into one of the fields so that it stands out more in the XML dialog). Here you can see that I’ve clicked the randomize buttons for the X displacement and the global randomization, but left the highlighted Y displacement with its default value. The seed in each case is the part after the semicolon, which you can copy and paste if you wish to use the same non-default seed across multiple objects.

To roughen a path, inserting new nodes and randomizing their positions may be sufficient. But this effect also provides a few options about what to do with the node handles. Our pointed star, with its straight line segments, offers little of interest when it comes to node handles, so, to demonstrate the possibilities, I’ll switch to a curved shape with a sharp transition in the middle. Once again, I’ve applied the Show Handles LPE, but I’ve put a duplicate of the original path on top (in red) for clarity. Here’s how it looks before the Roughen LPE is applied.

To isolate the effects on the handles, without adding extra nodes to complicate matters, I’ve used the “By number of segments” mode, with that number reduced to 1. This effectively neuters the top part of the dialog, and no new nodes are added, though the existing ones will still be moved. The “Handles” pop-up towards the bottom of the dialog determines what will happen to the nodes’ handles. With the default setting of “Along nodes”, the handles simply move along [with the] nodes, maintaining their relative sizes and positions.

The “Rand” option randomises the position of the handles. Unfortunately, there’s no button to set a random seed, and no seed value appears in the XML file, so I guess you’re stuck with whatever random positions the LPE gives you.

“Retract”, as its name suggests, retracts the handles completely, converting your path segments into straight lines, whilst “Smooth” ensures that the handles on either side of each node form a straight line, with the result that the path transitions smoothly from one segment to the next, even if doing so drastically changes the shape of your path. Adding extra nodes using the top section can help to reduce the amount of distortion that takes place.

At the bottom of the dialog are three checkboxes, starting with “Shift Nodes”. With this unchecked, the nodes won’t move, regardless of the X, Y and Global settings. At first, this seems to rather defeat the point of the dialog, but it opens up a couple of possibilities that aren’t immediately obvious. With this unchecked, you can use the top section of this LPE as a means to subdivide your path into smaller sections without affecting its shape. This might be handy as a “pre-processing” step before sending the result to another effect. Another option is to uncheck this but to change the “Handles” pop-up, so that the nodes don’t move but the handles are still randomised, retracted or smoothed.

The second checkbox seems less useful to me. It fixes the amount of allowed displacement to 1/3 of the length of the line segment, regardless of the X, Y and Global values. Why this should be a particularly good idea escapes me. I can understand that there might sometimes be a benefit to having the amount of displacement related to the length of the path segment, but, in that case, I would prefer to have a control to set that factor, rather than have it hard-coded as 1/3 of the segment size.

The last checkbox, “Spray Tool friendly”, is a mystery to me. The tooltip suggests it’s “for use with the spray tool in copy mode”, but my own experimentation of using the Spray tool on roughened shapes suggests that it has no obviously useful effect on the result. With this checked, some of my “copies” were slightly distorted compared to their peers, but not by enough to recommend this as a way of producing randomized copies.

So far, I’ve concentrated on using this effect to produce small changes to a path. In practice, an LPE called “Roughen” might be expected to have more dramatic effects in most situations. Returning to my original star shape, increasing the number of path segments, adjusting the X, Y and Global values, and randomizing the handles, produces arguably the output most people would expect from this effect.

Having briefly introduced the Show Handles LPE earlier on, I’ll finish this month by delving into a little more detail. The UI for this effect is so straightforward that it barely warrants a mention: the three checkboxes toggle the visibility of nodes, handles, and the path itself, whilst the spinbox lets you set the size of the rendered nodes and handles.

Compared with many LPEs, this UI is a model of simplicity. But what the UI doesn’t reveal is that there is a major problem with this effect which you really need to be aware of before using it: it completely wipes out any fill or stroke styles you might have applied to the original path. If your final aim is to render the nodes and handles – as in the images in this article – that’s perhaps not so much of a concern. But if you merely want to temporarily see what your chain of effects has done to the path, be aware that turning this LPE off, or even removing it entirely, won’t reinstate your original style settings. To be fair, the first time you try to add this effect in each session you are presented with the chance to back-out:

If you press ahead, you’ll find that your path is reduced to a thin, black stroke, with no fill. You can subsequently set a fill or change the stroke, but remember that the output from any LPE is itself a single path (albeit one with sub-paths, in this case), so you can apply only one set of styles to the entire output. In other words, you can’t color the path differently to the handles or nodes – not without using multiple copies or clones of the path, at least.

What to do, then, if you do want to use this effect without altering the style of your original path? If you just want to view the results temporarily, perhaps duplicating the original and applying the LPE to the new copy would be sufficient. But if you want the results to hang around a little longer, and therefore stay in sync with any changes to the original, you will have to work on a clone. That might sound simple, but making clones work with LPEs isn’t without its problems.

The obvious approach is just to clone the original (select it and press Alt-D). With the clone selected, opening the Live Path Effects dialog will show a message at the bottom saying “Click add button to convert clone” or similar. As soon as you click the “+” button in the dialog to add a new LPE, you’ll find that a “Fill between many” effect is automatically added, and your clone’s fill and stroke become unset. I won’t go into the details of this effect now (but its appearance in this role has promoted it to the subject of next month’s column), but suffice to say that it offers one way to link an existing path into a new LPE chain. You can go ahead and add other effects if you wish – including “Show handles” – but as soon as you try to move the clone to another location, you’ll have problems. It tends to jump back to the position of the original path and although there are ways to persuade it to sit elsewhere, the slightest nudge will send it scurrying back to its parent again. I note in a related bug report that the main developer of LPEs has recently committed some improvements to this effect into the Inkscape trunk, so hopefully we’ll see this addressed in the next release.

In the meantime, you can use the “Clone original path” LPE that was described in Part 47. In short, the steps you need to perform are: • Select your original path and copy it to the clipboard. • Create a sacrificial path to attach the new LPE to. A simple two-node line will do. • Add the “Clone original path” LPE to the sacrificial path. • Click the “Link to path” button in the LPE dialog (the first of the two buttons in the effect’s UI). • You can freely drag this clone wherever you need to on the page. • Add the “Show handles” LPE to the chain (or, indeed, other LPEs if you wish).

Part 47 also describes a shortcut, using Edit > Clone > Clone Original Path (LPE), but that now also applies the “Fill between many” effect, so, until the issues with it are ironed out, it’s probably best to stick with the steps above.

Next month, I’ll continue looking at the new LPEs in 0.92, including a closer look at the “Fill between many” effect, and what it can more usefully be used for.

issue126/inkscape.1509297666.txt.gz · Dernière modification : 2017/10/29 18:21 de auntiee