用 JSFL 填充图形

Posted

技术标签:

【中文标题】用 JSFL 填充图形【英文标题】:Fill figure with JSFL 【发布时间】:2011-01-16 17:45:40 【问题描述】:

我用JSFL方法在Flsh ID中画图,例如

// draw rectangle
doc.addNewLine(x:0, y:0, x:2000, y:0);
doc.addNewLine(x:2000, y:0, x:2000, y:500);
doc.addNewLine(x:2000, y:500, x:0, y:500);
doc.addNewLine(x:0, y:500, x:0, y:0);
// how can I fill it, because this way doesn't work
doc.setFillColor('#0000ff');

【问题讨论】:

【参考方案1】:

我发现另一种在舞台上填充形状很有用的方法。这包含了您的矩形形状和“#0000FF”颜色:

// Create Rectangle With Fill - Andrew Doll

var dom = fl.getDocumentDOM();
if (dom == null)

    alert('Please open a file.');

else

    // Declare variables.
    var tl = dom.getTimeline();
    var curLayer = tl.currentLayer;
    var curFrame = tl.currentFrame;
    var lockStatus = tl.layers[curLayer].locked;
    var myElements = tl.layers[curLayer].frames[0].elements;

    if (lockStatus)
    
        alert('Unlock the layer.');
    
    else
    
        // Draw rectangle.
        dom.addNewLine(x:0, y:0, x:2000, y:0);
        dom.addNewLine(x:2000, y:0, x:2000, y:500);
        dom.addNewLine(x:2000, y:500, x:0, y:500);
        dom.addNewLine(x:0, y:500, x:0, y:0);

        // Sets the current layer as selected.
        tl.setSelectedLayers(curLayer);
        tl.setSelectedFrames(0, 0, true);

        // Checks to see if there is artwork selected.
        var mySelectedFrames = tl.getSelectedFrames();

        // Selects current frame.
        tl.setSelectedFrames(curFrame, curFrame, true);

        // Sets the fill color for the inside of the object.
        var insideContour = dom.selection[0].contours[0]; 
        var insideFill = insideContour.fill;
        insideFill.color = '#0000ff';
        dom.setFillColor('#0000ff');
        dom.selectNone();
    

【讨论】:

【参考方案2】:

试试这个:

var doc = fl.getDocumentDOM();
// draw rectangle
doc.addNewLine(x:0, y:0, x:2000, y:0);
doc.addNewLine(x:2000, y:0, x:2000, y:500);
doc.addNewLine(x:2000, y:500, x:0, y:500);
doc.addNewLine(x:0, y:500, x:0, y:0);
//fill
fl.getDocumentDOM().selectAll();
fl.getDocumentDOM().union();

var fillA = fl.getDocumentDOM().getCustomFill();
fillA.style = 'radialGradient';
fl.getDocumentDOM().setCustomFill(fillA);

var fillB = fl.getDocumentDOM().getCustomFill();
fillB.style = "solid";
fillB.color = 0x0000FF;
fl.getDocumentDOM().setCustomFill(fillB);

功劳实际上归于 Christian Guirreri,而不是我。 这是完整的jsfl article。

【讨论】:

以上是关于用 JSFL 填充图形的主要内容,如果未能解决你的问题,请参考以下文章

替换 JSFL 中的填充颜色

Objective-c 用模式填充视图

visio 怎么填充自己画的图形啊

计算机图形学中的种子填充算法c++程序实现

计算机图形学输出图元_10_多边形填充区_7_OpenGL多边形填充区函数(上)

怎样在matlab中画矩形并填充颜色?