徽标到PostScript微型编译器 [英] Logo to PostScript mini-Compiler

查看:118
本文介绍了徽标到PostScript微型编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently writing a Logo to Postscript compiler. My PS output code doesn't seem to be valid. Any ideas what could be the problem? Or what the actual PostScript version for the LOGO should look like?

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


推荐答案

第一个问题是开头的注释行。 Adob​​e-3.0 部分不是代码使用的Postscript版本,而是 file 所遵循的Document Structuring Conventions版本。由于您根本没有使用任何DSC注释,因此第一行应为%!PS 或仅为%!

First problem is the opening comment line. The Adobe-3.0 part is not the Postscript version that the code uses, but the Document Structuring Conventions version that the file conforms to. Since you're not using any DSC comments at all, this first line should be %!PS or just %!.

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

Next, there are gibberish characters in left column of most lines. I'm guessing this is a an encoding for a TAB character, but it's not an ASCII tab. Safest policy is to always uses spaces for indentation.

showpage 运算符将输出当前页面。几乎可以肯定,它应该在最后而不是开始。 ...哦,我也看到它在底部

The showpage operator emits the output of the current page. It almost certainly should be at the end, not the beginning. ... Oh, I see it's at the bottom, too. The one at the top should be removed.

我看到的下一件事(尽管从技术上讲不是问题)是加法是可交换的。所以 exch add 总是可以简化为 add

Next thing I see (although not technically a problem) is that addition is commutative. So exch add can always be simplified to add.

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

There's a typo at the end of the definition of Left: defn should be def.

标题180 gt标题360 lt和始终为false。也许您打算? ...实际上,我认为这部分完全没有必要。后记的触发函数会为所有象限生成适当的带符号值。

Heading 180 gt Heading 360 lt and is always false. Perhaps you intended or? ... Actually I think this part isn't necessary at all. Postscript's trig functions yield the appropriate signed-values for all quadrants.

该部分看起来有太多的 1 s:

This part looks like it has too many 1s:

LEVEL
1
1
sub
LDRAGON

RDRAGON 未定义。 尽管功能相同,但是您可以重用相同的功能主体。 / RDRAGON / LDRAGON load def

And RDRAGON is not defined. Although since the functions are identical, you can reuse the same function body. /RDRAGON /LDRAGON load def

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

If the name LEVEL in the LDRAGON function should refer to the function's argument, then it must be explicitly defined. And it needs to define a local namespace, so it doesn't overwrite other instances of the same variable.

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

现在我们有了本地词典,重新定义了一个全局变量(例如 Heading Xpos Ypos )应该使用 store 而不是 def

And now that we have local dictionaries, re-defining a "global" variable (like Heading, Xpos, and Ypos) should use store instead of def.

后记区分大小写,因此 FORWARD 转发是两个不同的名称。

Postscript is case sensitive, so FORWARD and Forward are 2 distinct names.

正确的Postscript程序:

Corrected Postscript program:

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

这篇关于徽标到PostScript微型编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆