PostScript迷你编译器的徽标

时间:2014-03-17 17:54:44

标签: postscript logo-lang

我目前正在为Postscript编译器编写徽标。我的PS输出代码似乎没有效果。任何想法可能是什么问题?或者LOGO的实际PostScript版本应该是什么样的?

LOGO输入代码

PROC LDRAGON ( LEVEL )
    IF LEVEL == 0 THEN
    FORWARD 5 
    ELSE
    LDRAGON ( LEVEL - 1 )
    LEFT 90
    RDRAGON ( LEVEL - 1 )
    ENDIF 


PROC RDRAGON ( LEVEL )
    IF LEVEL == 0 THEN
    FORWARD 5 
    ELSE
    LDRAGON ( LEVEL - 1 ) 
    RIGHT 90
    RDRAGON ( LEVEL - 1 )
    ENDIF 

PROC MAIN (VOID)
   LDRAGON ( 11 )

我编译器的代码。

%!PS-Adobe-3.0
/Xpos { 300 } def showpage
/Ypos { 500 } def
/Heading { 0 } def
/Arg { 0 } def
/Right {
Heading exch add Trueheading
/Heading exch def
} def
/Left {
Heading exch sub Trueheading
/Heading exch def
} defп
/Trueheading {
360 mod dup
0 lt { 360 add } if
} def
/Forward {
dup Heading sin mul
exch Heading cos mul
2 copy Newposition
rlineto
} def
/Newposition {
Heading 180 gt Heading 360 lt
and { neg } if exch
Heading 90 gt Heading 270 lt
and { neg } if exch
Ypos add /Ypos exch def
Xpos add /Xpos exch def
} def
/LEVEL { 11 } def
/LDRAGON{
LEVEL
0
eq
{
5 FORWARD }{
LEVEL
1
1
sub
LDRAGON
90
LEFT
LEVEL
1
sub
RDRAGON
} ifelse
} def
/MAIN {
11
LDRAGON
} def
Xpos Ypos moveto
MAIN
stroke
showpage

1 个答案:

答案 0 :(得分:3)

第一个问题是开场评论行。 Adobe-3.0部分不是代码使用的Postscript版本,而是文件符合的文档结构约定版本。由于您根本不使用任何DSC评论,因此第一行应为%!PS%!

接下来,大多数行的左栏都有乱码。我猜这是一个TAB字符的编码,但它不是ASCII选项卡。最安全的政策是始终使用空格进行缩进。

showpage运算符会发出当前页面的输出。它几乎肯定应该在最后,而不是开始。 ......哦,我也看到了它的底部。应该删除顶部的那个。

我看到的下一件事(虽然技术上不是问题)是加法是可交换的。因此,exch add始终可以简化为add

Left的定义末尾有一个拼写错误:defn应为def

Heading 180 gt Heading 360 lt and总是假的。也许你打算or? ......实际上我认为这部分根本不是必需的。 Postscript的trig函数为所有象限产生适当的符号值。

这部分看起来有太多1 s:

LEVEL
1
1
sub
LDRAGON

RDRAGON未定义。 虽然函数是相同的,但您可以重用相同的函数体。 /RDRAGON /LDRAGON load def


如果LEVEL函数中的名称LDRAGON应引用函数的参数,则必须明确定义它。它需要定义一个本地命名空间,因此它不会覆盖同一个变量的其他实例。

/LDRAGON{
    1 dict begin
    /LEVEL exch def
    %...
    end

现在我们有了本地词典,重新定义了一个"全球"变量(如HeadingXposYpos)应使用store代替def


Postscript区分大小写,因此FORWARDForward是两个不同的名称。


更正的Postscript程序:

%!
%(debug.ps/db5.ps)run traceon stepon currentfile cvx debug
/Xpos { 300 } def
/Ypos { 500 } def
/Heading { 0 } def
/Arg { 0 } def
/Right {
    Heading add Trueheading
    /Heading exch store
} def
/Left {
    Heading exch sub Trueheading
    /Heading exch store
} def
/Trueheading {
    360 mod dup
    0 lt { 360 add } if
} def
/Forward {
    dup Heading sin mul
    exch Heading cos mul
    2 copy Newposition
    rlineto
} def
/Newposition {
    Heading 180 gt Heading 360 lt
    and { neg } if
    exch
    Heading 90 gt Heading 270 lt
    and { neg } if exch
    Ypos add /Ypos exch store
    Xpos add /Xpos exch store
} def
/LEVEL { 11 } def
/LDRAGON{
    1 dict begin
    /LEVEL exch def
    LEVEL
    0
    eq
    {
        5 Forward }{
        LEVEL
        1
        sub
        LDRAGON
        90
        Left
        LEVEL
        1
        sub
        RDRAGON
    } ifelse
    end
} def
/RDRAGON{
    1 dict begin
    /LEVEL exch def
    LEVEL
    0
    eq
    {
        5 Forward }{
        LEVEL
        1
        sub
        LDRAGON
        90
        Right
        LEVEL
        1
        sub
        RDRAGON
    } ifelse
    end
} def
/MAIN {
    11
    LDRAGON
} def
Xpos Ypos moveto
MAIN
stroke
showpage