Outils pour utilisateurs

Outils du site


issue67:tutoriel_-_inkscape_p._7

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.

À la fin de l'article du mois dernier, j'ai promis que nous irions nous intéresser au chapeau trop parfait qui orne notre bonhomme de neige désormais grumeleux. Le chapeau a été ajouté il y a longtemps lors de la deuxième phase de cette série d'articles, lorsque tout ce que nous pouvions dessiner était des ellipses et des rectangles, et c'est un bon exemple de la façon dont quelques objets soigneusement choisis peuvent tromper l’œil qui voit des formes qui ne sont pas vraiment là. Voici à quoi il ressemble lorsqu'il est retiré de la tête du bonhomme de neige et un peu tourné :

Il y a évidemment une ellipse en haut et une autre pour le bord, mais quid du corps principal du chapeau ? Avec vos nouvelles connaissances du mois dernier, il serait facile à créer en convertissant un rectangle sur un chemin et en courbant les segments du haut et du bas, mais cette version est antérieure de plusieurs mois à la version actuelle. Exploser le chapeau en ses parties constituantes rend les choses un peu plus claires :

Le corps est simplement un rectangle avec une ellipse pointant furtivement par dessous. En leur donnant des dégradés correspondants, nous pourrions créer l'illusion d'un objet unique. La courbe du haut n'existe pas du tout, c'est juste un effet d'optique créé en mettant le rectangle derrière l'ellipse que forme le haut du chapeau.

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:

Tromper l'œil pour faire un effet artistique peut être très utile, mais, dans ce cas, c'était vraiment une solution de contournement de notre manque de compétences en Inkscape. Ce serait mieux si le corps du chapeau était juste un objet avec un dégradé. Notre chapeau complet consisterait alors en une ellipse pour le haut, une ellipse pour le bord et un chemin pour le corps. Nous pourrions faire cela en convertissant le rectangle en chemin et en changeant le bord inférieur en une courbe de Bézier :

Mais nous avons déjà la forme que nous voulons dans la zone formée par le rectangle et l'ellipse. Ce que nous voulons faire c'est combiner ces objets en un seul chemin. Pour qu'Inkscape sache quels éléments nous voulons combiner, notre première étape consiste à sélectionner les deux. Passez à l'outil de sélection, cliquez sur le rectangle, puis maintenez la touche MAJ enfoncée tout en cliquant sur l'ellipse. La barre d'état doit vous dire que vous avez « 2 objets de type Rectangle, Ellipse » sélectionnés. Sinon, utilisez Edition> Désélectionner [Edit>Deselect] (ou cliquez simplement sur le fond, loin de tous les autres objets) afin d'effacer votre sélection, puis essayez à nouveau. Une fois que vous êtes satisfaits d'avoir sélectionné les deux bons objets, utilisez le menu Chemin> Union [Path>Union] (CTRL-+) pour combiner vos objets en un seul chemin :

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:

Si vous zoomez très près, vous remarquerez que notre nouveau chemin n'est pas aussi parfait que nous le souhaiterions. Certains défauts d'alignement de l'ellipse dans le rectangle ont créé des nœuds supplémentaires que nous devrons modifier manuellement en utilisant l'outil Nœud. Créer de la sorte des chemins à partir d'autres objets peut être un moyen rapide pour obtenir le schéma de base d'une forme, mais en général, vous aurez besoin de faire un peu de modifications manuelles par la suite. De la même manière que pour l'agrégation de formes pour former un seul chemin, nous pouvons aussi les soustraire, en découpant une forme dans une autre. En regardant le haut du chapeau, nous pourrions utiliser l'ellipse pour découper une section incurvée. Vous n'avez pas besoin d'être un génie en mathématiques pour comprendre que 1-2 ne vous donne pas le même résultat que 2-1. De même soustraire un rectangle d'une ellipse ne vous donnera pas le même résultat que soustraire une ellipse d'un rectangle, donc Inkscape a besoin d'un moyen de savoir quel objet est celui que nous enlevons et quel est celui duquel nous l'enlevons. Ceci est fait en utilisant l'ordre d'empilement.

L'ordre d'empilement a été brièvement mentionné dans la première partie de cette série : les objets dans Inkscape peuvent s'empiler les uns « au-dessus » des autres, avec ceux qui occupent le sommet de la pile occultant ceux en-dessous (en supposant qu'ils sont tous complètement opaques). Lorsque vous avez sélectionné un objet avec l'outil Sélection vous pouvez le déplacer vers le haut et vers le bas de la pile à l'aide de ces quatre boutons sur la barre d'outil de contrôle :

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.

Pour découper un objet dans un autre, la forme à supprimer doit être au-dessus de l'autre objet : dans notre cas, l'ellipse doit être au-dessus du rectangle incurvé. Elle est sans doute déjà au sommet de la pile, mais il ne fait pas de mal de prendre l'habitude de toujours déplacer l'objet à découper au dessus de l'objet à couper. Ceci est facile à réaliser en sélectionnant l'ellipse et en utilisant le dernier des quatre boutons pour l'amener jusqu'au sommet de la pile. Maintenant, vous devez positionner l'ellipse pour découper la forme que vous voulez : dans ce cas, il dépasse un peu le bord du rectangle. Une fois que c'est fait cela devient un cas simple de sélection des deux objets et d'utilisation du menu Chemin> Différence (ou CTRL et la touche moins) pour soustraire l'ellipse à partir du rectangle : Malheureusement, il y a quelques problèmes avec le résultat : le premier est que, une fois de plus, nous avons quelques nœuds récalcitrants qui devront être remis en place manuellement, le second est que notre ellipse a maintenant complètement disparu ! C'est un effet secondaire de l'opération Chemin>Différence : l'objet que vous découpez est également supprimé dans le processus.

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.

Appuyez sur CTRL-Z (ou utiliser Edition> Annuler) pour restaurer votre ellipse à son état d'avant la coupe. Maintenant, sélectionnez simplement l'ellipse et utilisez la commande Edition>Dupliquer (CTRL-D). Cela va créer une copie de l'objet sélectionné exactement au même endroit sur le fond, mais au sommet de la pile. Cela vaut la peine de s'habituer au raccourci clavier car c'est une fonctionnalité particulièrement utile : non seulement elle vous donne une copie à usage unique de l'objet à découper, mais elle vous évite aussi de devoir manuellement le déplacer vers le haut de la pile. Cela laisse même le nouvel objet sélectionné, il vous suffit de faire MAJ-clic sur l'objet à couper, puis d'utiliser Chemin> Différence. Maintenant, notre ancien rectangle a une base arrondie et un dessus incurvé et nous avons encore une ellipse pour former le haut.

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:

Mais il y a toujours un problème. Un examen attentif de la jointure entre le rectangle et le couvercle courbe montre une ligne mince montrant le fond ou les objets en dessous. Inkscape utilise l'« anti-aliasing » quand il dessine vos objets. Il tente de remplir approximativement les bords qui ne coïncident pas précisément sur les limites des pixels en traçant une fine ligne translucide pour donner l'impression visuelle d'une courbe lisse. Habituellement, il fonctionne bien, mais lorsque deux de ces limites se rencontrent, ça peut conduire à un léger écart là où vous n'en voulez pas vraiment.

Il y a quelques solutions à ce problème d'anti-aliasing : on pourrait ajouter un bord à l'un ou aux deux objets pour couvrir le déficit, mais ce n'est pas toujours approprié et ne résout pas le problème si les objets ont déjà des bords, ou alors on peut éviter de placer les objets parfaitement en butée d'un autre en faisant chevaucher le bord de l'autre. Dans ce cas, nous n'avons pas vraiment besoin que le rectangle ait un dessus incurvé : nous avons déjà l'effet visuel que nous recherchions.

Par CTRL-Z revenons à notre chapeau au sommet droit. Il peut sembler que nous avons tourné en rond, mais, en cours de route, vous avez appris le Chemin>Différence, les problèmes visuels que l'anti-aliasing peut parfois causer et le fait que parfois, il est préférable de dessiner quelque chose qui présente bien, même si sa structure sous-jacente n'est pas aussi pure ou correcte que vous auriez pu vouloir. Avant de finalement ré-assembler le chapeau, il pourrait être utile d'ajouter quelques plis et froissements en utilisant les outils de chemin du mois dernier :

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.

Pendant que vous étiez dans le menu Chemin à la recherche de l'Union et de la Différence, vous avez probablement remarqué les autres entrées groupées à côté d'elles : Intersection, Division, Exclusion et Chemin de Coupe. Ensemble, tout ceci forme les opérations « booléennes » de chemin : nommé d'après le mathématicien George Boole du 19e siècle, qui a formulé les règles permettant de combiner des données binaires qui sous-tendent ces opérations. Elles exigent toutes deux objets (même si l'Union peut travailler avec plus de deux), avec un résultat généralement différent selon l'objet qui est plus élevé dans la pile. Le tableau ci-dessus montre l'effet de l'application de chacune de ces opérations sur un carré et un cercle qui se chevauchent et montre la différence de résultats selon que l'un de ces objets est au-dessus de l'autre et lequel (dans le cas de la Division et du Chemin de coupe, les objets qui en résultent ont été séparés un peu pour rendre plus facile à voir l'effet de ces opérations).

Avec un peu de pratique, ces opérations booléennes vous permettront de produire des chemins complexes à partir de quelques formes simples. Ils fournissent un moyen rapide pour produire les premières grandes lignes que vous pouvez ensuite travailler avec l'outil nœud en quelque chose de plus affiné. Mais ne les considérez pas uniquement comme des instruments contondants pour les travaux de construction grossière : ils peuvent aussi être utilisés pour sculpter et façonner avec la précision d'un scalpel.

issue67/tutoriel_-_inkscape_p._7.txt · Dernière modification : 2013/01/27 17:04 de mna