issue151:inkscape
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue151:inkscape [2019/12/08 09:03] – d52fr | issue151:inkscape [2019/12/09 17:59] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
**Over the past few months, we’ve looked at ways to manipulate SVG in a web browser, using JavaScript, culminating in some simple animation. The code we used last time let us move an object horizontally on screen by manipulating its “x” attribute. By extension, we could also do the same with the “y” attribute to move it vertically. This time we’ll look at an alternative method of moving objects up, down, left and right, using an attribute that also opens up the ability to rotate or skew the element at the same time. The attribute in question is “transform”, | **Over the past few months, we’ve looked at ways to manipulate SVG in a web browser, using JavaScript, culminating in some simple animation. The code we used last time let us move an object horizontally on screen by manipulating its “x” attribute. By extension, we could also do the same with the “y” attribute to move it vertically. This time we’ll look at an alternative method of moving objects up, down, left and right, using an attribute that also opens up the ability to rotate or skew the element at the same time. The attribute in question is “transform”, | ||
- | Dans ces derniers mois, nous avons regarder | + | Dans ces derniers mois, nous avons regardé |
**Open Inkscape, with a fresh, blank document. Draw a simple square or rectangle – it doesn’t matter about the fill and stroke at this point, though it will be useful if you can actually see and interact with it. Now open the XML Editor dialog (Edit > XML Editor…). | **Open Inkscape, with a fresh, blank document. Draw a simple square or rectangle – it doesn’t matter about the fill and stroke at this point, though it will be useful if you can actually see and interact with it. Now open the XML Editor dialog (Edit > XML Editor…). | ||
Ligne 9: | Ligne 9: | ||
Leaving the XML editor open, you should also open the Inkscape Preferences (Edit > Preferences…). Navigate to the Behaviour > Transforms screen, and ensure that the “Store transformation” option is set to “Optimised”.** | Leaving the XML editor open, you should also open the Inkscape Preferences (Edit > Preferences…). Navigate to the Behaviour > Transforms screen, and ensure that the “Store transformation” option is set to “Optimised”.** | ||
- | Ouvrez Inkscape, avec un nouveau document vierge. Dessinez un simple carré ou rectangle ; nous ne nous soucions pas du contour et de remplissage pour le moment | + | Ouvrez Inkscape, avec un nouveau document vierge. Dessinez un simple carré ou rectangle ; nous ne nous soucions pas du contour et du remplissage pour le moment bien que ce soit utile si nous voulons vraiment le voir ou interagir avec lui. Maintenant, ouvrez l' |
- | Maintenant, vous comprenez la partie droite de ce dialogue. Vous pouvez voir l' | + | À ce stade, vous comprenez la partie droite de ce dialogue. Vous pouvez voir l' |
En laissant l' | En laissant l' | ||
Ligne 21: | Ligne 21: | ||
You should notice that, this time, the “x” and “y” attributes remain unchanged. Instead a new “transform” attribute is added, with a value that takes the form “translate(x, | You should notice that, this time, the “x” and “y” attributes remain unchanged. Instead a new “transform” attribute is added, with a value that takes the form “translate(x, | ||
- | Vous avez ces deux dialogues ouverts ainsi que la fenêtre principale d' | + | Les deux dialogues |
Maintenant, retournez dans les Préférences d' | Maintenant, retournez dans les Préférences d' | ||
Ligne 28: | Ligne 28: | ||
**That’s all very interesting, | **That’s all very interesting, | ||
+ | |||
+ | Tout ça est très intéressant, | ||
**Another key use for the transform attribute is in combination with groups. The SVG <g> element doesn’t have its own “x” and “y” attributes, so moving a group of objects (as one) would require code to update the attributes of each and every element in the group on each step of the animation. By setting a transform attribute on the group, you can obtain the same effect with far less work. | **Another key use for the transform attribute is in combination with groups. The SVG <g> element doesn’t have its own “x” and “y” attributes, so moving a group of objects (as one) would require code to update the attributes of each and every element in the group on each step of the animation. By setting a transform attribute on the group, you can obtain the same effect with far less work. | ||
So the transform attribute is a useful, if not essential, way of moving objects around in your drawing. But it offers more than that. Consider how you might incorporate rotation into your animation. If you’re animating a path – and you’re sufficiently mathematically astute – you could recalculate the coordinates of each node and handle in the path. But us mere mortals need an easier way to manage such tasks and the transform attribute offers that capability.** | So the transform attribute is a useful, if not essential, way of moving objects around in your drawing. But it offers more than that. Consider how you might incorporate rotation into your animation. If you’re animating a path – and you’re sufficiently mathematically astute – you could recalculate the coordinates of each node and handle in the path. But us mere mortals need an easier way to manage such tasks and the transform attribute offers that capability.** | ||
+ | |||
+ | Un autre usage fondamental de l' | ||
+ | |||
+ | Aussi, l' | ||
**To see how it works, revert your rectangle back to a point where there’s no transform attribute showing in the XML editor, and change the “Store transformation” setting back to “Optimised”. With the selection tool active, click the rectangle a second time to switch to the rotate and skew handles. Use the corner arrows to rotate the rectangle and you should see a transform attribute appear, but this time with a value of “rotate(r)”, | **To see how it works, revert your rectangle back to a point where there’s no transform attribute showing in the XML editor, and change the “Store transformation” setting back to “Optimised”. With the selection tool active, click the rectangle a second time to switch to the rotate and skew handles. Use the corner arrows to rotate the rectangle and you should see a transform attribute appear, but this time with a value of “rotate(r)”, | ||
Notice that rotating the object not only adds a transform() with the rotation amount, but also changes the “x” and “y” values. Once again, set “Store transformation” to “Preserved”. Now the transform() function has three parameters: the rotation angle and the x and y coordinates of the center of rotation.** | Notice that rotating the object not only adds a transform() with the rotation amount, but also changes the “x” and “y” values. Once again, set “Store transformation” to “Preserved”. Now the transform() function has three parameters: the rotation angle and the x and y coordinates of the center of rotation.** | ||
+ | |||
+ | Pour voir comment il fonctionne, ramenez votre rectangle au point où l' | ||
+ | |||
+ | Notez que la rotation de votre objet, non seulement ajoute un transform () avec la valeur de la rotation, mais aussi modifie les valeurs « x » et « y ». Une fois encore, réglez « Enregistrement de la transformation » sur « Préservé ». Maintenant, la fonction transform() a trois paramètres : l' | ||
**There are four other functions that can be used in the transform attribute: | **There are four other functions that can be used in the transform attribute: | ||
Ligne 46: | Ligne 56: | ||
skewX() and skewY() transform your element in the same way as the skew handles in the Inkscape UI. They each take a value, in degrees, that specifies the angle of skew.** | skewX() and skewY() transform your element in the same way as the skew handles in the Inkscape UI. They each take a value, in degrees, that specifies the angle of skew.** | ||
+ | |||
+ | Quatre autres fonctions peuvent être utilisées dans l' | ||
+ | scale(x, y) | ||
+ | skewX(a) | ||
+ | skewY(a) | ||
+ | matrix(a, b, c, d, e, f) | ||
+ | |||
+ | Je les ai listés séparément du fait de la façon dont Inkscape les traite. La fonction scale() augmente ou diminue simplement la taille de l' | ||
+ | |||
+ | skewX() et skewY() transforment votre élément de la même manière que les poignées de déformation dans l' | ||
**These three functions map fairly obviously to the select tool in Inkscape, which can be used to stretch, scale and skew an object. So you might expect to see these functions appear in the XML editor as you manipulate your object. Instead you’ll get the matrix() function appearing. | **These three functions map fairly obviously to the select tool in Inkscape, which can be used to stretch, scale and skew an object. So you might expect to see these functions appear in the XML editor as you manipulate your object. Instead you’ll get the matrix() function appearing. | ||
Without going into too much detail, the matrix() function lets you supply a series of six numbers that are used to fill the first two rows in a 3×3 matrix. This is used via standard mathematical matrix multiplication to map the original coordinates of the object to the transformed coordinates. In non-mathematical terms, a single matrix can not only produce the same output as all the other transformation functions, but can also produce output that is equivalent to any combination or mixture of them. Want to skew, rotate, scale and translate all at once? A matrix() transform will do the trick.** | Without going into too much detail, the matrix() function lets you supply a series of six numbers that are used to fill the first two rows in a 3×3 matrix. This is used via standard mathematical matrix multiplication to map the original coordinates of the object to the transformed coordinates. In non-mathematical terms, a single matrix can not only produce the same output as all the other transformation functions, but can also produce output that is equivalent to any combination or mixture of them. Want to skew, rotate, scale and translate all at once? A matrix() transform will do the trick.** | ||
+ | |||
+ | Ces trois fonctions cadrent plutôt bien avec l' | ||
+ | |||
+ | Sans trop rentrer dans les détails, la fonction matrix() vous permet de fournir une série de 6 nombres qui sont utilisés pour remplir les deux premières lignes d'une matrice 3x3. Celle-ci est utilisée via la multiplication matricielle des mathématiques pour faire correspondre les coordonnées d' | ||
**Working out the six numbers that need to be passed to the matrix() function is not for the faint-hearted. They don’t correspond to simple values such as x, y and rotation. So although Inkscape likes to use the matrix() function internally, it’s probably not something you want to be manipulating in JavaScript. Fortunately there are a couple of ways to work with the individual functions, rather than being forced to combine everything into a single matrix(). | **Working out the six numbers that need to be passed to the matrix() function is not for the faint-hearted. They don’t correspond to simple values such as x, y and rotation. So although Inkscape likes to use the matrix() function internally, it’s probably not something you want to be manipulating in JavaScript. Fortunately there are a couple of ways to work with the individual functions, rather than being forced to combine everything into a single matrix(). | ||
Ligne 56: | Ligne 80: | ||
When loaded into Inkscape the result looks like this:** | When loaded into Inkscape the result looks like this:** | ||
+ | |||
+ | Calculer les six nombres qui doivent être transmis à la fonction matrix() n'est pas une mince affaire. Ils ne correspondent pas à de simples valeurs telles que x, y et la rotation. Aussi, bien qu' | ||
+ | |||
+ | La première est de simplement regrouper vos objets dans des groupes SVG (l' | ||
+ | |||
+ | Quand il est chargé dans Inkscape, le résultat ressemble à cela : | ||
**Opening the XML editor shows that the transform on the outer group remains intact – it’s still a skewX() and doesn’t get automatically converted to a matrix() when loading it into Inkscape. As soon as you make a change via the GUI, however, the transform’s value will be replaced with a matrix(). If you just want to change the value in the existing function (eg. changing the angle of skew in this case), then you can make the modification in the XML editor. But remember that a <g> doesn’t have its own x and y attributes, so even something as trivial as moving the object slightly will mean Inkscape converts the attribute to a matrix() that combines the skew with the translate. | **Opening the XML editor shows that the transform on the outer group remains intact – it’s still a skewX() and doesn’t get automatically converted to a matrix() when loading it into Inkscape. As soon as you make a change via the GUI, however, the transform’s value will be replaced with a matrix(). If you just want to change the value in the existing function (eg. changing the angle of skew in this case), then you can make the modification in the XML editor. But remember that a <g> doesn’t have its own x and y attributes, so even something as trivial as moving the object slightly will mean Inkscape converts the attribute to a matrix() that combines the skew with the translate. | ||
Ligne 61: | Ligne 91: | ||
This is an important thing to be aware of. It’s easy to set up a file for animation with some nicely hand-coded transform attributes, then absent-mindedly open it in Inkscape to make a minor change, only to find that your hand-coded values have all been replaced with matrix() functions instead.** | This is an important thing to be aware of. It’s easy to set up a file for animation with some nicely hand-coded transform attributes, then absent-mindedly open it in Inkscape to make a minor change, only to find that your hand-coded values have all been replaced with matrix() functions instead.** | ||
- | **There is a second way to apply multiple transformations to an object: you just list them all in a single transform() element. Here’s a version of the previous file, but this time there’s no need for the < | + | Quand l' |
+ | C'est une chose importante à laquelle il faut être attentif. C'est facile de paramètrer un fichier pour une animation avec quelques attributs transform codés à la main, puis, sans plus réfléchir, | ||
+ | |||
+ | **There is a second way to apply multiple transformations to an object: you just list them all in a single transform() element. Here’s a version of the previous file, but this time there’s no need for the <g> elements, since the transformation can be applied directly to the square (below). | ||
Note that the transform attribute is now a list of transformations to apply. The white-space isn’t important: I’ve listed the functions one-per-line for clarity, but you could just put them onto a single line with a space character between them. When viewed in Inkscape, they appear in the XML editor on a single line, with every space and tab included between them, but none of the carriage returns: | Note that the transform attribute is now a list of transformations to apply. The white-space isn’t important: I’ve listed the functions one-per-line for clarity, but you could just put them onto a single line with a space character between them. When viewed in Inkscape, they appear in the XML editor on a single line, with every space and tab included between them, but none of the carriage returns: | ||
Once again, there’s no real surprise with the appearance of the file when it’s loaded into Inkscape (see above).** | Once again, there’s no real surprise with the appearance of the file when it’s loaded into Inkscape (see above).** | ||
+ | |||
+ | Une seconde façon existe d' | ||
+ | |||
+ | Notez que l' | ||
+ | |||
+ | Encore une fois, il n'ya pas de grande surprise dans l' | ||
**Yet again, with this approach we face the same issue of Inkscape’s desire to convert the value into a single matrix(). This time we do have x and y attributes (since we’re working on the < | **Yet again, with this approach we face the same issue of Inkscape’s desire to convert the value into a single matrix(). This time we do have x and y attributes (since we’re working on the < | ||
It’s annoying that Inkscape doesn’t offer a third option beyond “Optimised” and “Preserved”. A “Verbose” option that stores transforms in a more human-friendly form. Instead of a composite matrix() function, you would get a list of separate functions in the attribute. Moving would add or update the translate(), | It’s annoying that Inkscape doesn’t offer a third option beyond “Optimised” and “Preserved”. A “Verbose” option that stores transforms in a more human-friendly form. Instead of a composite matrix() function, you would get a list of separate functions in the attribute. Moving would add or update the translate(), | ||
+ | |||
+ | Je me répète, mais avec cette approche, nous faisons face au même problème du souhait d' | ||
+ | |||
+ | C'est ennuyeux qu' | ||
**As it stands, for most Inkscape users the internal details of how objects are moved, rotated, scaled and skewed is irrelevant. “Preserved” or “Optimised” has no bearing on how you work with elements in the GUI, or how the image is rendered in a web browser. If you do wish to alter the transform attribute using JavaScript, then there’s a slight advantage to “Preserved” – but only if the x and y attributes are set correctly in the first | **As it stands, for most Inkscape users the internal details of how objects are moved, rotated, scaled and skewed is irrelevant. “Preserved” or “Optimised” has no bearing on how you work with elements in the GUI, or how the image is rendered in a web browser. If you do wish to alter the transform attribute using JavaScript, then there’s a slight advantage to “Preserved” – but only if the x and y attributes are set correctly in the first | ||
** | ** | ||
+ | |||
+ | À ce qu'il semble, pour la plupart des utilisateurs d' | ||
+ | n'a aucune incidence sur la manière dont fonctionnent les éléments dans l' |
issue151/inkscape.1575792208.txt.gz · Dernière modification : 2019/12/08 09:03 de d52fr