Clones - SVG Optimization 02
by SunKing2 - uploaded on January 13, 2018, 11:05 pm
Lesson 02: Clones
(Download the drawing and examine the code:)
line 1: Add xlink to svg tag so we can do clones
line 3: Create a mountain shape, an inverted "V", then move to a new location, and create a little "v" shape. Give this an id
line 5: Make a clone by referring to the id. Move the clone to this X,Y coordinates. "Translate" does not operate in in intuitive way, it actually moves the entire grid to the new coordinates.
line 6: Make a clone, move it, and scale it too.
lines8-10: Create some big mountain clones beside each other
lines 12-13: Create some small mountain clones between them
line 15: You can clone a set of objects too. This is called a group. Create a group, named "myeye" consisting of a big circle and a small black circle inside it.
line 19: create a clone to make the second eye, and move it.
line 21: You can rotate, move and scale a clone all at once; this creates a rotated eye, moved, and scaled. The rotation is 30 degrees, and it rotates around centerX and centerY of 0,0. Since the translates works so strangely, I had to experiment with it to find coordinates of 700,-250.
To maintain a 2px stroke width for each mountain, you can also create the original with no stroke width, and then specify a stroke width on each clone. I did not do that, so you see scaled strokes also.
Comments
Log in to comment.
@Manuela
2018-01-18 08:37:50+00Thank you very much for that. I am planning to draw Haberdasher's puzzle http://www.craftsmanspace.com/free-projects/haberdashers-problem-puzzle-plan.html. As a first step I neet to draw a equilateral triangle which I already did, but the labels are missing. Can you help me with that?
@SunKing2
2018-01-18 16:06:07+00I think you can do this, but you'll need to use Inkscape as a temporary step, so that you can get the code for the path of the text. In Inkscape, create the text of the right size and rotation. Then use ctrl-k (Combine) to generate a path from the text. Now press ctrl-alt-x (XML dialog). This dialog will open up to the object that is currently selected (the text), and show you its path. The attribute you are looking for is "d". Click on d in the right hand side, and copy its contents. Now you are done with Inkscape. In your text editor, create a path tag with a d attribute and paste the contents into the d attribute.
@Manuela
2018-01-18 16:38:22+00Ok thank you for the hint, I will try this method. In the meantime I have posted the Haberdasher's puzzle as a request.
@Manuela
2018-01-18 16:48:00+00In my Inkscape version XML-Editor is Shift+Ctl+X, is there another dialog?
@SunKing2
2018-01-18 16:50:28+00Oops, you are right. XML editor is shift-ctrl-x. I wasn't paying attention.