0
可重用的對象
我卡在一個簡單的問題(我只是使用的lib啓動)?創建與拉斐爾
創建中心點周圍的一幫圈:
var height = 150,
width = 150,
branchRadius = 20,
centerX = width/2,
centerY = height/2,
treeCrownCenterOffset = 10,
treeCrownRotationCenterX = centerX,
treeCrownRotationCenterY = centerY - treeCrownCenterOffset,
rotationCenter = [treeCrownRotationCenterX , treeCrownRotationCenterY],
paper = Raphael('logo', height , width),
outerCircle = paper.circle(treeCrownRotationCenterX, treeCrownRotationCenterY, branchRadius).attr({fill:'#F00'}),
innerCircle = paper.circle(treeCrownRotationCenterX, treeCrownRotationCenterY, branchRadius - 4).attr({fill:'#000'}),
branch = paper.set([outerCircle, innerCircle]),
crown = paper.set(),
numCircles = 8, rotationStep = 360/numCircles, i = 0;
for(; i < numCircles - 1 ; i++) {
//Cloning a branch and pushing it to the crown after transforming it
crown.push(branch.clone().transform('r' + ((i + 1) * rotationStep) + ',' + rotationCenter));
}
//Putting a second crown 200px right of the first crown
//Yes, I'm building a tree :-) No trunk at this point
crown.clone().transform('t200,0');
如果你喜歡小提琴,這裏是the fiddle。
這是我天真的代碼,思考了一組克隆套(克隆枝冠)的確會移動到位置(200,0),旁邊的首冠。
它不工作:看起來像一個克隆組克隆元素不能被移動:執行此線時
crown.clone().transform('t200,0');
沒有太多反應。
好像「克隆」是不是做什麼,我想到,該轉換沒有被運到第二對象(複製)集合。
的基本問題是:
一個人如何去與拉斐爾創建可重用的對象嗎?
謝謝。
太感謝您了。更多的讚賞小提琴更新。你說「我發現轉變是一個非常頭痛的問題」,我同意。連續轉換的累積效果很難「調試」。當試圖從Inkscape中「進口」的路徑,同時包含變換和矩陣,比試圖圍繞這些代碼...好:-) – BinaryDeuce
+1「送它關閉的保留。」我同意尊重轉換:它們是強大的,但有時出現意想不到的複雜性是非常令人沮喪的。 –