Outils pour utilisateurs

Outils du site


issue67:tutoriel_-_inkscape_p._7

Ceci est une ancienne révision du document !


Table des matières

1

At the end of last month's article, I promised that we would take a look at the too pristine hat that's adorning our now-lumpy snowman. The hat was added way back in the second instalment of this series, when all we could draw were ellipses and rectangles, and is a good example of how a few carefully chosen objects can fool the eye into seeing shapes that aren't really there. Here's how it looks when removed from the snowman's head and rotated a little: There's obviously an ellipse at the top, and another for the brim, but what of the main body of the hat? With your new knowledge from last month, it would be easy to create by just converting a rectangle to a path, and curving the top and bottom segments, but this version pre-dates that insight by several months. Exploding the hat into its constituent parts makes things a little clearer: The body is just a rectangle with an ellipse peeking out from beneath it. By giving them matching gradients we could create the illusion of a single object. The curve at the top doesn't exist at all, it's just an optical effect created by putting the rectangle behind the ellipse that forms the top of the hat.

Fooling the eye for artistic effect can be very useful, but, in this case, it was really just a workaround for our lack of Inkscape skills. It would be better if the body of the hat was just one object with one gradient. Our complete hat would then consist of an ellipse for the top, an ellipse for the brim, and a path for the body. We could do that by converting the rectangle to a path and changing the bottom edge to a Bézier curve: But we've already got the shape we want in the outline formed by the rectangle and ellipse. What we really want to do is to combine those objects into a single path. In order for Inkscape to know which items we want to combine, our first step is to select them both. Switch to the selection tool, click on the rectangle, and then hold down SHIFT while clicking on the ellipse. The status bar should tell you that you have “2 objects of types Rectangle, Ellipse” selected. If not, use Edit > Deselect (or just click on the background, away from any other objects) in order to clear your selection, then try again. Once you're happy that you've got the right two objects selected, use the Path > Union menu entry (CTRL-+) to combine your objects into a single path:

2

If you zoom in closely you'll notice that our new path isn't quite as perfect as we would like. Some misalignment of the ellipse to the rectangle has resulted in extra nodes being created that we'll need to manually edit using the Node tool. Creating paths from other objects in this way can be a fast way to get the basic outline of a shape, but usually you'll need to do some manual editing afterwards. As well as adding shapes together to form a single path, we can also subtract them, cutting one shape out from another. Looking at the top of the hat, we could use the ellipse to cut away a curved section. You don't need to be a mathematical genius to understand that 1-2 doesn't give you the same result as 2-1. Similarly subtracting a rectangle from an ellipse won't give you the same result as subtracting an ellipse from a rectangle, so Inkscape needs some way of knowing which object is the one we're removing, and which is the one we're removing it from. This is done using the stacking order. The stacking order was briefly mentioned back in the first part of this series: objects within Inkscape can sit 'on top of' each other, with ones at the top of the stack obscuring those below (assuming they're all fully opaque). When you've got an object selected using the Selection tool you can move it up and down the stack using these four buttons on the tool control bar:

To cut one object from another, the shape that is being removed must be on top of the other object – in our case the ellipse needs to be on top of the rectangle-with-a-curved-base. It's probably already on top in the stack, but it doesn't hurt to get into the habit of always moving your cutting object on top of the object to be cut. This is easy to achieve by selecting the ellipse and using the last of the four buttons to bring it right to the top of the stacking order. Now you need to position the ellipse to cut out the shape you want – in this case overhanging the edge of the rectangle. With that done it's a simple case of selecting both objects and using Path > Difference menu entry (or CTRL and the minus key) to subtract the ellipse from the rectangle: Unfortunately there are a couple of problems with the result: the first is that, once again, we have some rogue nodes that will need to be manually tidied up; the second is that our ellipse has now completely disappeared! That's a side effect of the Path > Difference operation: the object you are cutting out is also removed in the process. Press CTRL-Z (or use Edit > Undo) to restore your ellipse back to its pre-cut status. Now select just the ellipse and use Edit > Duplicate (CTRL-D). This will create a copy of the selected object(s) at exactly the same location on the canvas, but at the top of the stack. It's worth getting used to the keyboard shortcut for this as it's a particularly useful feature – it not only gives you a disposable copy of your cutting object to use, but also saves you having to manually move it to the top of the stack. It even leaves the new object selected, so you just have to SHIFT-click on the object to be cut, then use Path > Difference. Now our former rectangle has a curved base and a curved top, and we still have an ellipse to form the lid.

3

But still there's a problem. A close look at the join between the curved rectangle and the lid shows a thin line showing through from the canvas or objects below. Inkscape uses “anti-aliasing” when it draws your objects. This tries to approximate edges that don't fall precisely on pixel boundaries by drawing a thin, translucent line to give the visual impression of a smooth curve. Usually it works well, but when two such boundaries meet it can lead to a slight gap where you don't really want one. There are a couple of solutions to this anti-aliasing issue: we could add a stroke to one or both of the objects to cover up the gap, but that's not always appropriate and doesn't help if the problem objects already have strokes; alternatively we could avoid relying on our objects perfectly abutting one another by making one of them overlap the edge of the other. In this case we don't really need the rectangle to have a curved top – we already had the visual effect we were looking for with the ellipse sitting on top of the rectangle. Let's CTRL-Z back to our straight-topped hat. It may seem that we've gone round in circles, but, along the way, you've learned about Path > Difference, the visual issues that anti-aliasing can sometimes cause, and the fact that sometimes it's better to draw something that looks right, even if its underlying structure isn't as pure or correct as you might like. Before finally reassembling the hat it might be worth adding some creases and crumples using the path tools from last month:

While you were in the Path menu looking for Union and Difference, you probably noticed the other entries grouped alongside them: Intersection, Division, Exclusion and Cut Path. Together all these form the “Boolean” path operations – named after 19th Century mathematician George Boole who formulated the rules for combining binary data that underlie these operations. They all require two objects (though Union can work with more than two), with the result usually differing based on which of the objects is higher in the stack. The above table demonstrates the effect of applying each of these operations to an overlapping square and circle, and shows the difference in results depending on which of these objects is on top of the other (in the case of Division and Cut Path the resultant objects have been separated slightly to make it easier to see the effect of these operations). With a bit of practice these Boolean operations will allow you to produce complex paths from a few simple shapes. They provide a fast way to produce rough initial outlines that you can then tweak with the node tool into something more refined. But don't dismiss them solely as a blunt instrument for coarse construction work: they can also be used to sculpt and shape with the precision of a scalpel.

issue67/tutoriel_-_inkscape_p._7.1358360037.txt.gz · Dernière modification : 2013/01/16 19:13 de frangi