Category:SVG simplification by cloning
Cloning is a mighty instrument for generation of repeated objects (SVG fragments) with reduced effort.
The SVG "use" element can be provided with any required transformation attribute, as translate, scale, rotate, skew.
Only for cloning the xmlns:xlink namespace definition is required
A useful description can be found at de:Wikibook:Transformations.
Especially rotations will lead to very odd coordinate values, while clone-transfomations avoid that. For very simple objects with no need for high accuracy cloning can be avoided, see Das Pentagramm als manuelle SVG-Grafik (de); but when exactness and perfect symmetry is desired, only cloning can care for that easily.
Accurate construction
The following code generates a perfectly symmetrical five-pointed star (like ):
<?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" xmlns:xlink="http://www.w3.org/1999/xlink"> <path id="c" fill="#FF0" d="m72,100 28-85 28,85"/> <use xlink:href="#c" transform="rotate(72 100,100)"/> <use xlink:href="#c" transform="rotate(144 100,100)"/> <use xlink:href="#c" transform="rotate(216 100,100)"/> <use xlink:href="#c" transform="rotate(288 100,100)"/> </svg>
(with three instead of four transformations when cascaded)
This is a lot of coding instructions for such a simple structure.
The same picture is drawn much shorter by the path
<?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"> <path fill="#FF0" d="m51,168 49-152 49,152-129-94h160"/> </svg>
bearing suffient exactness.
Cascaded cloning
Large numbers of repeated objects (SVG fragments) can be generated with repetitive use of cloning; it is possible always to double the count with each use. The number increases in a geometric progression, first doubling an object to two instances, then 4, 8, 16, 32, 64, 128, 256, 1024... (a typical example)
This can be very helpful to generate e.g. fractal structures. This category contains selected examples where the method of nested cloning helped to create multiple occurences of objects.
Cloning for symmetry check (mirroring)
During development of hand edited SVG, temporary cloning may be a help for checking whether an object is really accurat.
As an example, the mirrored red path shows that the black path is correctly drawn:
<?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" width="260" xmlns:xlink="http://www.w3.org/1999/xlink" height="300"> <path fill="none" stroke="#000" stroke-width="5" d="m5,5h250l-10,10v220c0,69-99,30-115,60-16-30-115,9-115-59V15z"/> <path fill="none" stroke="#F00" stroke-width="2" id="r" d="m5,5h250l-10,10v220c0,69-99,30-115,60"/> <use xlink:href="#r" transform="matrix(-1,0,0,1,260,0)"/> </svg>
Another example for mirroring is e.g. the code for file BSicon CSTRag.svg.
Examples

Haigerloch sketch
The first version did not use any cloning, each element of the sketch is drawn for itself.
- Every one of the 14 cubes is coded in a primitive manner like

<g id="g2510" style="fill:#000000;stroke:none" /> <g id="g2534" style="fill:#ff0000;stroke:none" /> <g transform="matrix(0.1491359,0,0,0.1406997,91.406269,63.033462)" id="g3498"> <path d="M -177.89576,71.34841 L -109.02632,117.34031 L -64.211774, 48.135815 L -133.08122,2.1439186 L -177.89576,71.34841" id="path3500" style="fill:#acacac;fill-opacity:1;stroke:#ff0000;stroke-width: 0.60093284;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0" /> <path style="fill:#575757;fill-opacity:1;fill-rule:evenodd;stroke: #00ff00;stroke-width:0.60093284;stroke-linecap:butt;stroke-linejoin: miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="M -201.72291,84.7638 L -178.09589,71.367102 L -133.11653, 2.1071298 L -156.94923,15.622398 L -201.72291,84.7638 z" id="path3502" /> <path style="fill:#7f7f7f;fill-opacity:1;fill-rule:evenodd;stroke: #0000ff;stroke-width:0.60093284;stroke-linecap:butt;stroke-linejoin: miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="M -201.72291,84.7638 L -132.73915,130.70408 L -108.9643, 117.27815 L -178.03805,71.277778 L -201.72291,84.7638 z" id="path3504" /> </g> </g> </g>
needing about 1300 bytes, repeated 13 times with other transformation for the other cubes.
The second version draws this cube only once, with
<g stroke="#000" stroke-linejoin="bevel" stroke-width=".1"> <path fill="#AAA" d="m29,15-17-11-11,17 17,11"/> <path fill="#777" d="m29,15-17-11 6-3 17,11"/> <path fill="#555" d="m29,15-11,17 6-3 11-17z"/> </g>
needing about 212 bytes. All further occurrrencies are cloned, in a cascading manner.
- There are 46 ellipses in the first drawing, every one of them is coded like
<path sodipodi:type="arc" style="opacity:1;fill:#575757;fill-opacity:1;stroke-width:2.5; stroke-miterlimit:4;stroke-dasharray:5, 5;stroke-dashoffset:0" id="path3359" sodipodi:cx="17.296402" sodipodi:cy="5.2840905" sodipodi:rx="0.72443181" sodipodi:ry="0.69128788" d="M 18.020834,5.2840905 A 0.72443181,0.69128788 0 1 1 16.57197, 5.2840905 A 0.72443181,0.69128788 0 1 1 18.020834,5.2840905 z" transform="matrix(-0.9662745,0,0,-0.6369863,117.49973,129.66582)" />
The simplified drawing omits these ellipses, replacing them by the linecap='round' attribute, which seems quite enough accuracy for this simple sketch.
Category:SVG simplification techniques#%20C
Pages in category "Category:SVG simplification by cloning"
- File:11 of hearts.svg
- File:1o5dots.svg
- File:4-regular matchstick graph with 60 vertices.svg
- File:5proc s.svg
- File:5whiteStar.svg
- File:6whiteStar.svg
- File:7-segment.svg
- File:7사단.svg
- File:Abe no Seimei Hann (No background and black color drawing).svg
- File:Aegishjalmr.svg
- File:Alternattiva Demokratika.svg
- File:Ashoka Chakra.svg
- File:Asian Games Gold medal blank.svg
- File:Astigmatismus-Sonne.svg
- File:Auroville symbol.svg
- File:Bandeira do Tocantins.svg
- File:Black Sun.svg
- File:BlueGear3.svg
- File:Cantor dust clone.svg
- File:Cantor dust.svg
- File:Card back 02.svg
- File:Centered hexagonal = 1 + 6triangular.svg
- File:Chemistrybondstar.svg
- File:Chinese-army Wuhan flag (1911-1928) 18 dots.svg
- File:Chinese-army Wuhan flag (1911-1928) 19 dots.svg
- File:Civil Flag of Serbia variant.svg
- File:Clock 06-00.svg
- File:Clock 09-18.svg
- File:COA Christiern af Oeland.svg
- File:Coa Illustration Elements Plant Chrysanthemum.svg
- File:Color square cm.svg
- File:DistribEixampleBCN.svg
- File:DrSuper super super super.svg
- File:DST begin.svg
- File:Emblem of Daejeon.svg
- File:End CEST.svg
- File:EPP-EVP-Logo-German-2011.svg
- File:Eye icon 04.svg
- File:F22 1 1.svg
- File:Flag of Belarusian Steamship Line.svg
- File:Flag of Biaroza-Kartuskaja.svg
- File:Flag of Des Moines, Iowa.svg
- File:Flag of Mahiloŭ.svg
- File:Flag of Orocovis.svg
- File:Flag of the Chechen Republic.svg
- File:Flag of the U.S..svg
- File:Flag of Uruguay.svg
- File:Flag Thai Admiral of the Fleet.svg
- File:Forschungsreaktor Haigerloch Gitter.svg
- File:Frame-01.svg
- File:Gennji kuruma (No background and Black color drawing).svg
- File:GER-FRA 2016-07-07.svg
- File:Hachiyounitsuki.svg
- File:Hdp middenvlak.svg
- File:Hex board 11x11.svg
- File:HexaFlake 5th Iteration Center.svg
- File:Honma clans family crest circle (No background and Black color drawing).svg
- File:How to use icon.svg
- File:Icons8 flat services.svg
- File:Inflorescences Spike Kwiatostan Kłos.svg
- File:Japanese Crest Kagome.svg
- File:Japanese Crest Kawarijuunihiashi.svg
- File:Kanji - 興x4.svg
- File:Kawarijuunihiashi (No background and Black color drawing).svg
- File:Korean Traffic sign (Rotary - Mandatory sign).svg
- File:Kuomintang Emblem.svg
- File:Kuyo.svg
- File:Kyokkou (No background and Black color drawing).svg
- File:Kätzchen (inflorescence).svg
- File:Legenda zabytek techniki.svg
- File:Logo Grand Site de France sans texte.svg
- File:MFrey LED Matrix.svg
- File:Migi mitsudomoe.svg
- File:Mitu Yama (No background and Black color drawing).svg
- File:National Cockade of Uruguay (civilian).svg
- File:Nibelle - Composition de la population.svg
- File:Noto Emoji KitKat 1f505.svg
- File:Ohene aniwa.svg
- File:Oota Kikyou (No background and Black color drawing).svg
- File:Op-art-4-sided-spiral-tunnel-8.svg
- File:Optical illusion 03 pg.svg
- File:Optical-illusion-diamonds-C.svg
- File:P-pentomino Symmetry.svg
- File:Peroxisome.svg
- File:Polygon-032VC.svg
- File:Portuguese EU presidency 2021.svg
- File:Rio de Janeiro 2016 Summer Olympics bid icon (blue) 00s.svg
- File:Rio de Janeiro 2016 Summer Olympics bid icon (orange) 00.svg
- File:Rio de Janeiro 2016 Summer Olympics bid icon-s.svg
- File:ROK recycling symbol.svg
- File:Russia-2C Flag of Border Guard district commanders 2008.svg
- File:Sept cercles dans un.svg
- File:Septimani iuniores shield pattern.svg
- File:Shield Trinity (blank).svg
- File:SierpinskiTriangle.svg
- File:Simple wave pattern.svg
- File:Sol de Mayo-Bandera de Uruguay.svg
- File:Stroke pattern.svg
- File:Teilchenmodell Feststoff.svg
- File:Teilchenmodell Gas.svg
- File:Template-protection-shackle-brackets-rtl.svg
- File:Template-protection-shackle-brackets.svg
- File:Tor Snowflake logo.svg
- File:TriSquare36.svg
- File:United States Gay Pride flag.svg
- File:Very good resistance to light.svg
- File:Wakatsuki ju roku hachiju ken kiku (No background and Black color drawing).svg
- File:Wappen Friedensdorf.svg
- File:Wikipedia progress icon.svg
- File:Yatsuhiashi (No background and Black color drawing).svg
- File:Êzîdxan Protection Force.svg
- File:大日本帝國陸軍 軍旗.svg