Labels:
HTML
XML
SVG
Getting to Know SVG
You might be interested in the logo on my Personal Website:
This logo is plotted with SVG (Scalable Vector Graphics).
With SVG, you can design and create your own images and let them dance and fly.
Basic SVG Tags & Attributes
One of the most important tag in SVG is path.
These commands are availble in the attribute d.
| M = moveto(M X,Y) |
| L = lineto(L X,Y) |
| H = horizontal lineto(H X) |
| V = vertical lineto(V Y) |
| C = curveto(C X1,Y1,X2,Y2,ENDX,ENDY) |
| S = smooth curveto(S X2,Y2,ENDX,ENDY) |
| Q = quadratic Belzier curve(Q X,Y,ENDX,ENDY) |
| T = smooth quadratic Belzier curveto(T ENDX,ENDY) |
| A = elliptical Arc(A RX,RY,XROTATION,FLAG1,FLAG2,X,Y) |
| Z = closepath() |
M, L, H, Z and their parameters are easy to understand. FLAG1 and FLAG2 inside of A need to be explained.
FLAG1 has only two values: 0 and 1. 1 means the larger curve plotted will be chosen while 0 means the smaller one/
FLAG2 also has only two values: 0 and 1. If it is 1, the curve will be plotted in 'clockwise' direction. On contrary, the curve will in 'counter clockwise' direction.
Another important attribute is stroke, including stroke, stroke-width, stroke-linecap, stroke-linejoin, stroke-miterlimit, stroke-dasharray, stroke-dashoffset, stroke-opacity.
stroke-dasharray='num1,num2,num3,num4...' can create dashed line. The 2nth number is the solid line length while the (2n+1)th number represents the length of empty space.
stroke-dashoffset='num' is the offset of the start of the stroke.
Creating Your Own Graphics
To transform your logo into SVG code, you have to analyze how you logo is composed and locate the coordinations of key point. Then, applying the tags and attributes as well as the coordinations to plot on your webpage.
<svg id="my_logo" version="1.1" baseProfile="full" viewBox="0 0 1088 1088" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g transform="translate(-1700 40)">
<path id="s" d="M 512 256 A 256 256 0 0 0 256 0 A 256 256 0 0 0 0 256 A 256 256 0 0 0 256 512 A 160 160 0 0 1 416 672 A 160 160 0 0 1 256 832 A 160 160 0 0 1 96 672 A 48 48 0 0 0 48 624 A 48 48 0 0 0 0 672 A 256 256 0 0 0 256 928 A 256 256 0 0 0 512 672 A 256 256 0 0 0 256 416 A 160 160 0 0 1 96 256 A 160 160 0 0 1 256 96 A 160 160 0 0 1 416 256 A 48 48 0 0 0 464 304 A 48 48 0 0 0 512 256">
</path>
<path id="u" d="M 864 48 A 48 48 0 0 0 816 0 A 48 48 0 0 0 768 48 L 768 672 A 256 256 0 0 0 1024 928 A 256 256 0 0 0 1280 672 L 1280 48 A 48 48 0 0 0 1232 0 A 48 48 0 0 0 1184 48 L 1184 672 A 160 160 0 0 1 1024 832 A 160 160 0 0 1 864 672 Z">
</path>
<path id="n" d="M 1642 0 L 1536 0 L 1536 880 A 48 48 0 0 0 1584 928 A 48 48 0 0 0 1632 880 L 1632 212 L 1952 928 L 2048 928 L 2048 48 A 48 48 0 0 0 2000 0 A 48 48 0 0 0 1952 48 L 1952 716 L 1632 -13">
</path>
<path id="rabbit_face" d="M 2662 400 A 262 262 0 0 0 2400 662 A 262 262 0 0 0 2662 928 A 262 262 0 0 0 2924 662 A 262 262 0 0 0 2662 400 M 2600 410 A 500 500 0 0 1 2400 0 A 500 500 0 0 1 2600 410 M 2724 410 A 500 500 0 0 1 2924 0 A 500 500 0 0 1 2724 410">
</path>
<path id="rabbit_eyes" d="M 2500 650 A 30 30 0 0 0 2470 680 A 30 30 0 0 0 2500 710 A 30 30 0 0 0 2530 680 A 30 30 0 0 0 2500 650 M 2824 650 A 30 30 0 0 0 2793 680 A 30 30 0 0 0 2824 710 A 30 30 0 0 0 2854 680 A 30 30 0 0 0 2824 650">
</path>
<path id="rabbit_mouse" d="M 2632 767 A 30 30 0 0 0 2662 797 A 30 30 0 0 0 2692 767">
</path>
</g>
</svg>
Letting Your Graphics Move
Applying stroke-dasharray and stroke-dashoffset to let the stroke move.
#s, #u, #n, #rabbit_face, #rabbit_mouse {
stroke: #9966ff;
stroke-width: 40;
fill: #EFEFEF;
}
#rabbit_eyes {
stroke: #9966ff;
stroke-width: 40;
fill: #9966ff;
}
#s, #u, #n {
stroke-dasharray: 5300;
-webkit-animation: s-stroke 3s ease-in-out;
animation: s-stroke 3s ease-in-out;
}
#rabbit_face {
stroke-dasharray: 2000;
-webkit-animation: rabbit-face-stroke 1s ease-in-out 3s;
animation: rabbit-face-stroke 1s ease-in-out 3s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}