Flash and SVG...

1 отговора 44 прегледа
#1

Flash and SVG...

...нещо на което попаднах.......

тожа е скрипта за Flash

MovieClip.prototype.box = function(x1, y1, x2, y2, sColor, sWidth, fColor, fAlpha) {
this.lineStyle(sWidth, sColor);
this.beginFill(fColor, fAlpha);
this.moveTo(x1, y1);
this.lineTo(x2, y1);
this.lineTo(x2, y2);
this.lineTo(x1, y2);
this.lineTo(x1, y1);
this.endFill();
};
MovieClip.prototype.drawShape = function(x1, y1, points, sColor, sWidth, fColor, fAlpha) {
this.lineStyle(sWidth, sColor);
this.beginFill(fColor, fAlpha);
this.moveTo(x1, y1);
for (i=0; i<points.length; i++) {
this.lineTo(points.x, points.y);
}
this.lineTo(x1, y1);
this.endFill();
};
var colors = {blue:0x0000ff, green:0x00ff00, red:0xff0000, none:undefined};
var cmToPixels = 72/2.54;
function drawIt() {
var showWidth, readWidth, showHeight, readHeight, x, y, w, h, f, s, i;
var heightRatio, widthRatio;
var depth = 1;
var drawCommands = [];
var points = [];
// get overall size from main svg tag
readWidth = this.firstChild.attributes.width;
showWidth = Number(readWidth.substr(0, readWidth.indexOf("cm")))*cmToPixels;
readHeight = this.firstChild.attributes.height;
showHeight = Number(readHeight.substr(0, readHeight.indexOf("cm")))*cmToPixels;
dimensions = this.firstChild.attributes.viewbox.split(" ");
widthRatio = showWidth/dimensions[2];
heightRatio = showHeight/dimensions[3];
// draw rectangle, defined by rect tag (here this.firstChild.childNodes[2])
x = Number(this.firstChild.childNodes[2].attributes.x);
y = Number(this.firstChild.childNodes[2].attributes.y);
w = Number(this.firstChild.childNodes[2].attributes.width);
h = Number(this.firstChild.childNodes[2].attributes.height);
f = colors[this.firstChild.childNodes[2].attributes.fill];
s = colors[this.firstChild.childNodes[2].attributes.stroke];
createEmptyMovieClip("shape"+depth, depth);
_root["shape"+depth].box(Math.round(x*widthRatio), Math.round((y+h)*heightRatio), Math.round((x+w)*widthRatio), Math.round(y*heightRatio), s, 1, f, 100);
depth++;
// draw triangle, defined by path tag (here this.firstChild.childNodes[3])
drawCommands = this.firstChild.childNodes[3].attributes.d.split(" ");
i = 0;
while (i<drawCommands.length) {
if (drawCommands == "M") {
x = Math.round(Number(drawCommands[i+1])*widthRatio);
y = Math.round(Number(drawCommands[i+2])*heightRatio);
i += 3;
}
if (drawCommands == "L") {
points.push({x:Math.round(Number(drawCommands[i+1])*widthRatio), y:Math.round(Number(drawCommands[i+2])*heightRatio)});
i += 3;
}
if (drawCommands == "z") {
break;
}
}
f = colors[this.firstChild.childNodes[3].attributes.fill];
s = colors[this.firstChild.childNodes[3].attributes.stroke];
sw = Number(this.firstChild.childNodes[3].attributes["stroke-width"]);
createEmptyMovieClip("shape"+depth, depth);
_root["shape"+depth].drawShape(x, y, points, s, sw, f, 100);
depth++;
}
svgXML = new XML();
svgXML.ignoreWhite = true;
svgXML.onLoad = drawIt;
svgXML.load("w3c_triangle.svg");


а това е сорса на .svg файла w3c_triangle.svg..

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"[линк]">
<svg width="4cm" height="4cm" viewBox="0 0 400 400" xmlns="[линк]">
<title>Example triangle01- simple example of a 'path'</title>
<desc>A path that draws a triangle</desc>
<rect x="1" y="1" width="398" height="398" fill="none" stroke="blue" />
<path d="M 100 100 L 300 100 L 200 300 z" fill="red" stroke="blue" stroke-width="3" />
</svg>


copy, paste and save са достатъчни....

HowBizarre

Редактирано от PllP на

Отговор
в отговор на PllP #2

Re: Flash and SVG...

mojesh da loadvash SVG pod XML i da risyvash dosta slojni risunchici...no purvo trqbva da se zapoznaesh s SVG formata na [линк] dokolkoto si spomnqm imashe edna jena, koqto beshe sutvorila chudesni raboti po toq nachin...

|Не се изказвай за неща, които не разбираш|
Отговор