丢失 linear_shade 输出

丢失 linear_shade 输出

我的代码有什么问题?第二次调用 SoundEnergy 时丢失了黑/白渐变。

\startMPinclusions

def SoundEnergy =

 path pr ; pr := unitsquare xscaled .3cm yscaled 2cm ;
currentpicture:=nullpicture;
for i=0 step 2 until 10:
   linear_shade(pr shifted (i*.3cm,0),0,white,black);
   linear_shade(pr shifted ((i+1)*.3cm,0),0,black,white);
      endfor;  
clip currentpicture to (0,0)--(0,2cm)--(2cm,2cm)--(3cm,1cm)--(2cm,0)--cycle;
     draw (0,0)--(0,2cm)--(2cm,2cm)--(3cm,1cm)--(2cm,0)--cycle withcolor .625red; 
     addto finalpicture also currentpicture shifted(avanco*3.5cm,0) ;
    currentpicture := nullpicture ; avanco := avanco+1 ;     
 enddef;
\stopMPinclusions


\starttext



\startMPcode

picture finalpicture ; finalpicture := nullpicture ;
numeric avanco ; avanco := 0 ; bboxmargin := 0pt ;

SoundEnergy;SoundEnergy;
currentpicture := finalpicture ;

\stopMPcode


\stoptext

在此处输入图片描述

答案1

解决了。​​感谢 fpast 的建议。

\startMPinclusions


def SoundEnergy =

 path pr ; pr := unitsquare xscaled .3cm yscaled 2cm ;
currentpicture:=nullpicture;
numeric avanc;
avanc:=avanco+1;
for i=0 step 2 until 10:
    pr := unitsquare xscaled .3cm yscaled 2cm shifted ((avanc-1)*3.5cm+i*.3cm,0);
   fill pr withshade (define_linear_shade(origin shifted ((avanc-1)*3.5cm+i*.3cm,0), origin shifted ((avanc-1)*3.5cm+(i+1)*.3cm,0),black,white));
    pr := unitsquare xscaled .3cm yscaled 2cm shifted ((avanc-1)*3.5cm+(i+1)*.3cm,0);
   fill pr withshade (define_linear_shade(origin shifted ((avanc-1)*3.5cm+(i+1)*.3cm,0), origin shifted ((avanc-1)*3.5cm+(i+2)*.3cm,0),white,black));
      endfor;  
     path dor;   dor :=  (0,0)--(0,2cm)--(2cm,2cm)--(3cm,1cm)--(2cm,0)--cycle;
     clip currentpicture to (dor shifted ((avanc-1)*3.5cm,0));

     draw dor shifted ((avanc-1)*3.5cm,0) withcolor .625red; 
     addto finalpicture also currentpicture;
    currentpicture := nullpicture ; 
    avanco := avanco+1 ;     
 enddef; 

\stopMPinclusions


\starttext

\startMPcode

picture finalpicture ; finalpicture := nullpicture ;
numeric avanco ; avanco := 0 ; bboxmargin := 0pt ;

SoundEnergy; SoundEnergy; SoundEnergy; 
currentpicture := finalpicture ;

\stopMPcode


\stoptext

在此处输入图片描述

相关内容