【问题标题】:LOGO to PostScriptLOGO 转 PostScript
【发布时间】:2014-03-27 17:06:56
【问题描述】:

我正在尝试在 PostScript 中为我的 LOGO 程序找到等效代码:

PROC FRACTAL( SIZE )
IF SIZE < 1 THEN
FORWARD 5
ELSE 
LEFT 90
RIGHT 90
RIGHT 90
RIGHT 90
RIGHT 90
RIGHT 90
FORWARD 60
ENDIF

PROC MAIN( VOID )
FRACTAL( 5 )

到现在为止

%!
%(debug.ps/db5.ps)run traceon stepon currentfile cvx debug
/Xpos { 300 } def
/Ypos { 500 } def
/Heading { 0 } def
/Arg { 0 } def
/RIGHT {
Heading exch 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 def
Xpos add /Xpos exch def
} def
/SIZE { 5 } def
/FRACTAL{
1 dict begin
/SIZE exch def
SIZE
1
lt
{
5
FORWARD
}{
90
LEFT
90
RIGHT
90
RIGHT
90
RIGHT
90
RIGHT
90
RIGHT
60
FORWARD
} ifelse 
end
} def
/MAIN{
5
FRACTAL
} def
Xpos Ypos moveto
MAIN
stroke
showpage 

此解决方案基于此问题:Logo to PostScript mini-Compiler

这段代码对我来说看起来不错,但是出于某种原因 PS 不想显示图片。

【问题讨论】:

  • 您是直接发送到打印机吗?你在 ghostscript 中试过了吗?
  • @Luis,我创建了一个文件 .ps 并尝试在 OSX 中使用预览打开
  • 您确定LOGO程序按照您的想法进行吗?看起来它只是画了一条短的垂直线,这与 Ghostscript 为 PS 程序提供的相同输出。顺便说一句,“LEFT 90 RIGHT 90”和“RIGHT 90 RIGHT 90 RIGHT 90 RIGHT 90”一样是无操作的。
  • 顺便说一句,我使用的调试器(在源代码的评论中提到)可以在这里找到:github.com/luser-dr00g/debug.ps

标签: compiler-construction postscript logo-lang


【解决方案1】:

后记翻译是正确的。问题是 Logo 程序没有做任何有趣的事情。

【讨论】:

    猜你喜欢
    • 2016-12-02
    • 2011-03-30
    • 2011-03-31
    • 2016-11-07
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 2016-01-19
    • 1970-01-01
    相关资源
    最近更新 更多