Skip navigation.

青春的岁月

——只因那胸中燃烧的理想

svg和shell脚本的结合

今天做了一个有趣的svg+shell:
原理如下,把svg图片分成三个部分,如下:
azhoulinux@azhou:~/Desktop$ cat 1 2 3
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="800"
height="600"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.44.1"
sodipodi:docbase="/home/azhoulinux"
sodipodi:docname="test.svg">
<metadata
id="metadata1901">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
inkscape:window-height="583"
inkscape:window-width="819"
guidetolerance="10.0"
gridtolerance="10.0"
objecttolerance="10.0"
borderopacity="1.0"
bordercolor="#666666"
pagecolor="#ffffff"
id="base"
inkscape:zoom="0.63"
inkscape:cx="396.40833"
inkscape:cy="300"
inkscape:window-x="4"
inkscape:window-y="67"
inkscape:current-layer="layer1" />
<defs
id="defs4" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:none;fill-rule:evenodd;stroke:blue;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:2"
d="M 120,120 L 130,120 L 120,90 L 120,500 L 750,500 L 720,490 L 720,500 "
id="path1905"
sodipodi:nodetypes="c" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect1915"
width="630"
height="30"
x="120"
y="470" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2811"
width="630"
height="30"
x="120"
y="440" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2813"
width="630"
height="30"
x="120"
y="410" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2815"
width="630"
height="30"
x="120"
y="380" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2817"
width="630"
height="30"
x="120"
y="350" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2819"
width="630"
height="30"
x="120"
y="320" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2821"
width="630"
height="30"
x="120"
y="290" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2823"
width="630"
height="30"
x="120"
y="260" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2825"
width="630"
height="30"
x="120"
y="230" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2827"
width="630"
height="30"
x="120"
y="200" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2829"
width="630"
height="30"
x="120"
y="170" />

<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="500"
id="text2778"><tspan
sodipodi:role="line"
id="tspan2780"
x="100"
y="500">0.0</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="470"
id="text2778"><tspan
sodipodi:role="line"
id="tspan2780"
x="100"
y="470">0.1</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="440"
id="text2788"><tspan
sodipodi:role="line"
id="tspan2790"
x="100"
y="440">0.2</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="410"
id="text2792"><tspan
sodipodi:role="line"
id="tspan2794"
x="100"
y="410">0.3</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="380"
id="text2796"><tspan
sodipodi:role="line"
id="tspan2798"
x="100"
y="380">0.4</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="350"
id="text2800"><tspan
sodipodi:role="line"
id="tspan2802"
x="100"
y="350">0.5</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="320"
id="text2804"><tspan
sodipodi:role="line"
id="tspan2806"
x="100"
y="320">0.6</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="290"
id="text2808"><tspan
sodipodi:role="line"
id="tspan2810"
x="100"
y="290">0.7</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="260"
id="text2812"><tspan
sodipodi:role="line"
id="tspan2814"
x="100"
y="260">0.8</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="230"
id="text2816"><tspan
sodipodi:role="line"
id="tspan2818"
x="100"
y="230">0.9</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="200"
id="text2820"><tspan
sodipodi:role="line"
id="tspan2822"
x="100"
y="200">1.0</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="170"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="100"
y="170">1.5</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="150"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="150"
y="510">1</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="180"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="180"
y="510">2</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="210"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="210"
y="510">3</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="240"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="240"
y="510">4</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="270"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="270"
y="510">5</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="300"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="300"
y="510">6</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="330"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="330"
y="510">7</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="370"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="370"
y="510">8</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="400"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="400"
y="510">9</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="430"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="430"
y="510">10</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="460"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="460"
y="510">11</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="490"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="490"
y="510">12</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="520"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="520"
y="510">13</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="550"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="550"
y="510">14</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="580"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="580"
y="510">15</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="610"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="610"
y="510">16</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="640"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="640"
y="510">17</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="670"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="670"
y="510">18</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="700"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="700"
y="510">19</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="730"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="730"
y="510">20</tspan></text>
<path
style="fill:none;fill-rule:evenodd;stroke:red;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:2"
d="
##========================================以上是文件第一部分,part1

##========================================以上为文件第二部分,part2
"
id="path1905"
sodipodi:nodetypes="c" />

</g>

##========================================以上为文件第三部分,part3

其中文件二有shell脚本生成,最后使用以下命令合成test.svg:

azhoulinux@azhou:~/Desktop$ cat 1 2 3 > test.svg

shell脚本如下:test.sh
azhoulinux@azhou:~/Desktop$ cat test.sh
#!/bin/bash
#by azhoulinux 2006-12-2

#first part init var
startx=120
starty=500
countnum=0

#second get the x y
while [ true ]
do
x=$startx
y=$starty
loadavg=`uptime |awk '{print $8}'|awk -F , '{print $1}'`
# echo $loadavg
suby=`echo "$loadavg*300"|bc|awk -F . '{print $1}'`
# echo "$suby \c"
# echo "\c"
let x="120+30*$countnum"
let y="$y-$suby"
if [ $countnum = 0 ]
then
echo "M${x},${y}" >>2
else
echo "L${x},${y}" >>2
fi
cat 1 2 3 > test.svg
let countnum="$countnum+1"
if [ $countnum = 21 ]
then
cat /dev/null > 2
countnum=0
fi

# echo $x
# echo $y
sleep 1s
done

而test.html要起到自动刷新功能,代码如下:
azhoulinux@azhou:~/Desktop$ cat test.html
<html>
<head>
<meta http-equiv=refresh content=1 />
</head>
<body>
embed src="test.svg" width="800" height="600"/
</body>
</html>

这样每一秒就会自动刷新页面,而文件二每一秒就自动更新。效果如下:

写了一个长长的脚本挑战呀!

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31