Search code examples
recursionpostscript

change line color by recursion in postscript


I want to make my patern to be in many colors. I mean I want my DoLine to make each time line with simmilar but not the same colour. So I did

/red 0.41 def
/green 0.1 def
/blue 0.21 def 
/incRed {/red red 0.01 add} def 
/incGreen {/green green 0.03 add} def 
/incBlue {/blue blue 0.05 add} def

and my DoLine

/DoLine 
{ 
    incRed
    incGreen
    incBlue
    red green blue setrgbcolor
    rotation rotate
    0 linelen rlineto
    currentpoint stroke 
    translate 0 0 moveto 
} def

But it output my patern in only one colour which is set as

/red 0.41 def
/green 0.1 def
/blue 0.21 def 

Is there something I missed? Here is my all code if u need it

%!

/Helvetica findfont 8 scalefont setfont
/ang1 -141 def
/ang2 {-2 ang1 mul} def
/linelen 36 def
/depth 0 def
/down {/depth depth 1 add def} def
/up {/depth depth 1 sub def} def
/red 0.41 def
/green 0.1 def
/blue 0.21 def
/incRed {/red red 0.01 add} def 
/incGreen {/green green 0.03 add} def 
/incBlue {/blue blue 0.05 add} def

/CrownPos
{
    /x 300 def
    /y 300 def
    x y moveto
} def

/DoLine 
{ 
    incRed
    incGreen
    incBlue
    red green blue setrgbcolor
    rotation rotate
    0 linelen rlineto
    currentpoint stroke 
    translate 0 0 moveto 
} def

/Print
{ 
    gsave 
    .62 .62 scale
    2 setlinewidth
    down DoLine
    depth 8 le
    {
        ang1 rotate Print
            ang2 rotate Print
    } if
    up
    grestore 
} def

/Crown
{
    /rotation 0 def
    CrownPos Print
    stroke
    /rotation 270 def
    CrownPos Print
    stroke
    /rotation 90 def
    CrownPos Print
    stroke
} def



    Crown
600 600 translate
180 rotate Crown 
    showpage

Solution

  • Two problems with these color increment routines: 1) they didn't set the new value back into the variable (i.e. missing a def) and 2) they increment too quickly, reaching white way too soon. Try these reworked versions instead:

    /incRed { /red red 0.0001 add def } def 
    /incGreen { /green green 0.0003 add def } def 
    /incBlue { /blue blue 0.0005 add def } def
    

    enter image description here