How can i rotate?

Adrian Wróbel

How can I rotate only one part of my 'code'

my code:

%!

/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


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

/DoLine 
{ 
    rotation rotate
    0 linelen rlineto 
    currentpoint stroke 
    translate 0 0 moveto 
} def

/Print
{ 
    gsave 
    .62 .62 scale
    2 setlinewidth
    down 0 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
    0 -25 translate
    Crown 
    showpage

i want to rotate my lower crown by 180 degrees, all is shown on included pictures

it gives me something like this: original
enter image description here

but i want something like this: after rotation
enter image description here

KenS

Your code is 'peculiar' at least, you are using procedures (executable arrays) in an odd and potentially performance decreasing way. You have code like this:

/depth {0} def

This creates an executable array which, when executed, puts 0 on the operand stack. It would be simpler, and the interpreter will usually execute this faster, to put:

/depth 0 def

I don't think you have really grasped the stack-based operation of PostScript.

You also have a fault in one procedure, in /Print you have :

down 0 DoLine

This executes 'down', then puts 0 on the operand stack, then executes 'DoLine'. However nothing ever removes the '0' from the operand stack. At the end of your program there are 3600 objects (all integers with the value 0) on the operand stack. This is wasteful, can slow down the interpreter, makes debugging difficult and may even, in some very limited PostScript implementations, cause a stack overflow error.

Having said all that. The answer to your question is, of course, that you can rotate your drawing using the 'rotate' operator. I would have thought from the fact that you were using rotate already in a recursive procedure, that this would be obvious. Of course, since your drawing is offset by 300, 300 you must be sure to apply an offset to the CTM, as well as rotating it, so that the second execution appears in the correct position.

Here is a corrected version updated to draw as you requested:

%!

/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


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

/DoLine 
{ 
    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 rotateCrown 
    showpage

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related