【问题标题】:Logo to PostScript mini-CompilerPostScript 迷你编译器的徽标
【发布时间】:2014-04-23 02:14:57
【问题描述】:

我目前正在为 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

【问题讨论】:

标签: postscript logo-lang


【解决方案1】:

第一个问题是开头的注释行。 Adobe-3.0 部分不是代码使用的 Postscript 版本,而是 file 符合的 Document Structuring Conventions 版本。由于您根本没有使用任何 DSC cmets,因此第一行应该是 %!PS 或只是 %!

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

showpage 运算符发出当前页面的输出。几乎可以肯定它应该在结尾,而不是开头。 ...哦,我看到它也在底部。应该删除顶部的那个。

接下来我看到的(虽然技术上不是问题)是加法是可交换的。所以exch add总是可以简化为add

Left 的定义末尾有一个错字:defn 应该是def

Heading 180 gt Heading 360 lt and 始终为假。也许你打算or? ...实际上我认为这部分根本没有必要。 Postscript 的三角函数为所有象限产生适当的符号值。

这部分好像太多了1s:

LEVEL
1
1
sub
LDRAGON

并且RDRAGON 没有定义。 虽然函数是一样的,但是可以复用同一个函数体。 /RDRAGON /LDRAGON load def


如果LDRAGON 函数中的名称LEVEL 应该引用函数的参数,那么它必须显式定义。并且它需要定义一个本地命名空间,所以它不会覆盖同一个变量的其他实例。

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

现在我们有了本地字典,重新定义“全局”变量(如HeadingXposYpos)应该使用store 而不是def


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


更正后记程序:

%!
%(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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-21
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多