3

What is wrong with my code? The second call of SoundEnergy lost the black/white gradient.

\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

enter image description here

  • 1
    This phenomenon seems to be thoroughly documented p.187 à 189 of the Metafun manual (2010). I've never use such shading myself, so I can't be of more help… – Franck Pastor Feb 14 '14 at 18:42
  • Thanks. No solution for that. I read the manual and have not found the answer for that. – Jorge Feb 15 '14 at 19:05
  • If I quote this manual, p. 187, "due to the way we have implemented shading in ConTeXt, we do indeed copy the circles, but the shade definition is frozen and the same one is used for all the circles. This means that the center of the shading stays at the first circle". If we replace "circle" by your "SoundEnergy" figure, it would explain your problem. The workaround would be not to made pictures copies via addto procedures and the like, but to act like the non-problematic example on the top of page 187 (shifting the shaded figure while staying inside the same picture). – Franck Pastor Feb 15 '14 at 20:16
2

Solved. Thanks to fpast for the sugestions.

\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

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.