Paper.js:不能设置符号实例的fillColor

时间:2012-03-17 22:07:36

标签: javascript canvas html5-canvas paperjs

我是paper.js的新手。

对于这个项目,我需要一个将在许多实例中使用的形状(具有不同的填充颜色),因此使用符号(而不是使用Path.clone()方法)显然更好。 但是,一旦我将符号实例化为placementSymbol,似乎更改fillColor属性对渲染的形状没有影响:它仍然是符号的初始颜色。

已成功设置其他属性,例如位置或不透明度。

我的问题:如何更改符号每个实例的填充颜色?

jsFiddle这里:http://jsfiddle.net/GlauberRocha/uTskY/(请注意,我已将所有代码放在HTML窗格中。似乎没有其他工作,可能因为paperscript不是简单的javascript)。

论文代码:

var
  path = new Path(),
  symbol = {},
  inst = [],
  colors = ["#1f8f81", "#c7c5a8", "#1b4a9f", "#d6a493", "#1a8879", "#599ce3", "#1a459c", "#b9a87a", "#365db2", "#2479d4", "#a46430", "#1b449a", "#a4632e", "#1a4297", "#3359ad", "#b1852b", "#1a8077", "#1b3849", "#ae832a", "#186cc9", "#1b8178"]

path.add(new Point(0, 56), new Point(56, 0), new Point(56, 40), new Point(0, 96));
path.fillColor = "red";
path.closed = true;
symbol = new Symbol(path);
path.remove();

for (var i = 0; i < 20; ++i) {
  inst[i] = symbol.place();
  inst[i].fillColor = colors[i]; // Change fill color : NO
  console.log(inst[i].fillColor); // But... the correct color value appears here
  inst[i].opacity = (i / 30) + .4; // Change opacity: OK
  inst[i].position.x = 100; // Change position: OK
  inst[i].position.y = 42 * i + 50;
}

2 个答案:

答案 0 :(得分:5)

paper.js团队的Jonathan Puckey回答:

  

这是设计的。你不能改变一个的视觉属性   符号的实例。要更改项目的颜色,您可以创建   使用path.clone()的多个路径副本。

答案 1 :(得分:0)

(venv2)xxx@server: ~/c-p $ pip install -U polyglot
Collecting polyglot
  Using cached polyglot-15.10.03-py2.py3-none-any.whl
Requirement already up-to-date: futures>=2.1.6 in /home/xxx/venv2/lib/python2.7/site-packages (from polyglot)
Requirement already up-to-date: morfessor>=2.0.2a1 in /home/xxx/venv2/lib/python2.7/site-packages (from polyglot)
Requirement already up-to-date: pycld2>=0.3 in /home/xxx/venv2/lib/python2.7/site-packages (from polyglot)
Requirement already up-to-date: six>=1.7.3 in /home/xxx/venv2/lib/python2.7/site-packages (from polyglot)
Requirement already up-to-date: wheel>=0.23.0 in /home/xxx/venv2/lib/python2.7/site-packages (from polyglot)
Collecting PyICU>=1.8 (from polyglot)
  Using cached PyICU-1.9.2.tar.gz
Building wheels for collected packages: PyICU
  Running setup.py bdist_wheel for PyICU ... error
  Complete output from command /home/xxx/venv2/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-RRIysk/PyICU/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpoQlZzFpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  copying icu.py -> build/lib.linux-x86_64-2.7
  copying PyICU.py -> build/lib.linux-x86_64-2.7
  copying docs.py -> build/lib.linux-x86_64-2.7
  running build_ext
  building '_icu' extension
  creating build/temp.linux-x86_64-2.7
  gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c normalizer.cpp -o build/temp.linux-x86_64-2.7/normalizer.o -DPYICU_VER="1.9.2"
  cc1plus: Warnung: Kommandozeilenoption "-Wstrict-prototypes" ist gültig für Ada/C/ObjC, aber nicht für C++
  /usr/include/unicode/tmutfmt.h:231: Warnung: »UBool icu_4_2::hashTableValueComparator(UHashTok, UHashTok)« als »static« deklariert, aber nirgendwo definiert
  gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c spoof.cpp -o build/temp.linux-x86_64-2.7/spoof.o -DPYICU_VER="1.9.2"
  cc1plus: Warnung: Kommandozeilenoption "-Wstrict-prototypes" ist gültig für Ada/C/ObjC, aber nicht für C++
  /usr/include/unicode/tmutfmt.h:231: Warnung: »UBool icu_4_2::hashTableValueComparator(UHashTok, UHashTok)« als »static« deklariert, aber nirgendwo definiert
  gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c search.cpp -o build/temp.linux-x86_64-2.7/search.o -DPYICU_VER="1.9.2"
  cc1plus: Warnung: Kommandozeilenoption "-Wstrict-prototypes" ist gültig für Ada/C/ObjC, aber nicht für C++
  /usr/include/unicode/tmutfmt.h:231: Warnung: »UBool icu_4_2::hashTableValueComparator(UHashTok, UHashTok)« als »static« deklariert, aber nirgendwo definiert
  gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c numberformat.cpp -o build/temp.linux-x86_64-2.7/numberformat.o -DPYICU_VER="1.9.2"
  cc1plus: Warnung: Kommandozeilenoption "-Wstrict-prototypes" ist gültig für Ada/C/ObjC, aber nicht für C++
  numberformat.cpp: In function »PyObject* t_numberformat_isLenient(t_numberformat*)«:
  numberformat.cpp:912: Fehler: »class icu_4_2::NumberFormat« hat kein Element namens »isLenient«
  numberformat.cpp: In function »PyObject* t_numberformat_setLenient(t_numberformat*, PyObject*)«:
  numberformat.cpp:923: Fehler: »class icu_4_2::NumberFormat« hat kein Element namens »setLenient«
  /usr/include/unicode/tmutfmt.h: At global scope:
  /usr/include/unicode/tmutfmt.h:231: Warnung: »UBool icu_4_2::hashTableValueComparator(UHashTok, UHashTok)« als »static« deklariert, aber nirgendwo definiert
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for PyICU
  Running setup.py clean for PyICU
Failed to build PyICU
Installing collected packages: PyICU, polyglot
  Running setup.py install for PyICU ... error
    Complete output from command /home/xxx/venv2/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-RRIysk/PyICU/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Gg7muP-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/xxx/venv2/include/site/python2.7/PyICU:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    copying icu.py -> build/lib.linux-x86_64-2.7
    copying PyICU.py -> build/lib.linux-x86_64-2.7
    copying docs.py -> build/lib.linux-x86_64-2.7
    running build_ext
    building '_icu' extension
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c normalizer.cpp -o build/temp.linux-x86_64-2.7/normalizer.o -DPYICU_VER="1.9.2"
    cc1plus: Warnung: Kommandozeilenoption "-Wstrict-prototypes" ist gültig für Ada/C/ObjC, aber nicht für C++
    /usr/include/unicode/tmutfmt.h:231: Warnung: »UBool icu_4_2::hashTableValueComparator(UHashTok, UHashTok)« als »static« deklariert, aber nirgendwo definiert
    gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c spoof.cpp -o build/temp.linux-x86_64-2.7/spoof.o -DPYICU_VER="1.9.2"
    cc1plus: Warnung: Kommandozeilenoption "-Wstrict-prototypes" ist gültig für Ada/C/ObjC, aber nicht für C++
    /usr/include/unicode/tmutfmt.h:231: Warnung: »UBool icu_4_2::hashTableValueComparator(UHashTok, UHashTok)« als »static« deklariert, aber nirgendwo definiert
    gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c search.cpp -o build/temp.linux-x86_64-2.7/search.o -DPYICU_VER="1.9.2"
    cc1plus: Warnung: Kommandozeilenoption "-Wstrict-prototypes" ist gültig für Ada/C/ObjC, aber nicht für C++
    /usr/include/unicode/tmutfmt.h:231: Warnung: »UBool icu_4_2::hashTableValueComparator(UHashTok, UHashTok)« als »static« deklariert, aber nirgendwo definiert
    gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c numberformat.cpp -o build/temp.linux-x86_64-2.7/numberformat.o -DPYICU_VER="1.9.2"
    cc1plus: Warnung: Kommandozeilenoption "-Wstrict-prototypes" ist gültig für Ada/C/ObjC, aber nicht für C++
    numberformat.cpp: In function »PyObject* t_numberformat_isLenient(t_numberformat*)«:
    numberformat.cpp:912: Fehler: »class icu_4_2::NumberFormat« hat kein Element namens »isLenient«
    numberformat.cpp: In function »PyObject* t_numberformat_setLenient(t_numberformat*, PyObject*)«:
    numberformat.cpp:923: Fehler: »class icu_4_2::NumberFormat« hat kein Element namens »setLenient«
    /usr/include/unicode/tmutfmt.h: At global scope:
    /usr/include/unicode/tmutfmt.h:231: Warnung: »UBool icu_4_2::hashTableValueComparator(UHashTok, UHashTok)« als »static« deklariert, aber nirgendwo definiert
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/home/xxx/venv2/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-RRIysk/PyICU/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Gg7muP-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/xxx/venv2/include/site/python2.7/PyICU" failed with error code 1 in /tmp/pip-build-RRIysk/PyICU

Alt,设置要更改的g:s的ID和

    // copy files
    copy: {
        img: {
            files: [{
                expand: true,
                cwd: 'src/img/',
                src: [
                    'foo/*.{png,jpg}',
                    'foo/*.{png,jpg}',
                    'foo/*.{png,jpg}',
                ],
                dest: 'img/'
            }],
        },
    },