我怎样才能旋转?

How can i rotate?

如何只旋转我的 '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

我想将我的下表冠旋转 180 度,所有内容都显示在随附的图片上

它给了我这样的东西: original

但我想要这样的东西: after rotation

您的代码至少是 'peculiar',您正在以一种奇怪且可能降低性能的方式使用过程(可执行数组)。您有这样的代码:

/depth {0} def

这将创建一个可执行数组,该数组在执行时将 0 放入操作数堆栈。它会更简单,解释器通常会更快地执行它,以放置:

/depth 0 def

我觉得你还没有真正掌握PostScript的基于栈的操作

你在一个过程中也有错误,在 /Print 你有:

向下 0 DoLine

这执行'down',然后将0放入操作数堆栈,然后执行'DoLine'。然而,没有任何东西从操作数堆栈中删除“0”。在你的程序结束时,操作数栈中有 3600 个对象(所有值为 0 的整数)。这很浪费,会减慢解释器的速度,使调试变得困难,甚至可能在一些非常有限的 PostScript 实现中导致堆栈溢出错误。

说了这么多。当然,您的问题的答案是您可以使用 'rotate' 运算符旋转绘图。从您已经在递归过程中使用 rotate 的事实来看,我本以为这是显而易见的。当然,由于您的绘图偏移了 300、300,因此您必须确保对 CTM 应用偏移并旋转它,以便第二次执行出现在正确的位置。

这是根据您的要求更新的更正版本:

%!

/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