0

I'm trying to find equivalent code in PostScript for my LOGO program:

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 )

So far I got

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

This solution is based on this question here : Logo to PostScript mini-Compiler

This code looks fine for me, however for some reason PS doesn't want to show a picture.

Community
  • 1
  • 1
user1806258
  • 87
  • 2
  • 11
  • Are you sending this straight to a printer? Have you tried it in ghostscript? – Luis Mar 27 '14 at 17:38
  • @Luis, I created a file .ps and trying to open using Preview in OSX – user1806258 Mar 27 '14 at 18:26
  • Are you sure the LOGO program does what you think? It looks like it just draws one short vertical line, which is the same output ghostscript gives me for the PS program. BTW, "LEFT 90 RIGHT 90" is a no-op, as is "RIGHT 90 RIGHT 90 RIGHT 90 RIGHT 90". – luser droog Mar 28 '14 at 04:48
  • BTW, the debugger I used (mentioned in the comment in the source) is available here: https://github.com/luser-dr00g/debug.ps – luser droog Mar 28 '14 at 07:32

1 Answers1

1

The postscript translation is correct. The problem is that the Logo program doesn't do anything interesting.

luser droog
  • 18,988
  • 3
  • 53
  • 105