Copy command in PostScript
Asked Answered
F

3

0

I am reading algorithms by RobertSedwick at following link

http://books.google.co.in/books?id=pQRLfMngZ7sC&pg=PA213&lpg=PA213&dq=towers+of+hanoi+relation+with+trailing+zeros&source=bl&ots=gfM2UdBkNq&sig=avk5lNz7XeNODghvOlvHKSGMc8g&hl=en#v=onepage&q=towers%20of%20hanoi%20relation%20with%20trailing%20zeros&f=false

Page number: 218 Fig 5.13

What does following statement mean in PostScript.

 2 copy ge {dup 0 rlineto}
 {
    ...
 } ifelse

And also what does following means

   2 copy KochR

I am looking into PostScript first time here.

Feasible answered 11/9, 2012 at 11:54 Comment(0)
M
2

You should refer to the following four books/resources first:

  1. The "Blue Book" (PDF 0.9 MByte).
    PostScript Language Tutorial and Cookbook, Adobe Systems, Addison-Wesley 1985; ISBN 0201101793.

    This is the best introduction to the PostScript language. PostScript operators are introduced in an easy and well-paced way. Sample programs are easy to read and they print beautiful pictures. The book describes only a fraction of level 1 PostScript. By itself it is not sufficient for professional work.

  2. The "Green Book" (PDF 0.9 MByte).
    PostScript Language Program Design, Adobe Systems, Addison-Wesley, 1988; ISBN 0201143968.

    This book shows how to use PostScript in real world situations. Although the book is based on level 1 PostScript, good programming practices have not changed so much as the language itself.

  3. The "Red Book" (PDF 7.6 MByte).
    PostScript Language Reference Manual, Adobe Systems Addison-Wesley, 1999; ISBN 0201379228) 912 pages.

    This is the official description of PostScript language. Everything in the book is important; everything is explained only once. The Red Book is also available on paper for those who prefer to read in bed. An older version (dated 1999), without the necessity of registration in one of Adobe's partner programs, is available here.

  4. Thinking in PostScript (PDF 0.8 MByte).
    By Glenn C. Reid, Addison-Wesley, 1990; ISBN 0201523728.

    This book is a good introduction to PostScript. The book is available for free. Why not give it a try?


(Above info is mostly taken from the PostScript FAQ. I own and worked with all of the above books and can fully agree with the given assessment.)

Me answered 11/9, 2012 at 12:28 Comment(1)
Actually hereI am not trying to learn the language. I am looking for what above commands will mean in a program in link shown as I am a C++ programmer.Feasible
H
1

Please see Kurt Pfeifle's answer here for a corrected version of this hasty answer. Hopefully, I've somewhat redeemed myself in the followup question


To answer your question more directly, it's difficult to explain what the code does because it isn't complete.

The start of both snippets is 2 copy which pushes duplicates of the top two things on the stack. What are these things? ??!

Well, they're probably numbers. In the first example, they're almost definitely a coordinate pair: x and y. If y is greater than 2, then draw a line to (current-x + y-from-stack, 0). Why do this? ??!

In the second example, KochR is most likely a recursive procedure to draw a Koch curve where one of the parameters is almost certainly the recursion level, and the other is probably the length of a single line-segment (unless it's really sophisticated and offers a global-scaling control).

That's about all that can be guessed from the code as shown. HTH.

Horehound answered 12/9, 2012 at 5:21 Comment(4)
I have complete code at https://mcmap.net/q/244197/-understanding-recursive-koch-snowflake-function-in-postscriptFeasible
In above description it is mentioned that y is greater than 2, Can you please eloborate why we are checking with 2?Feasible
@luser droog: That's not exactly how I understand the code. After copying the 2 current top elements onto the stack, the 2 is no longer there.Me
@KurtPfeifle Yeah. My bad. Shouldn't write answers when sleepy.Horehound
M
1

(This answer is based on luser droog's one, with the different understanding I have of the code given.)

To answer your question more directly, it's difficult to explain what the code does because it isn't complete.

The start of both snippets is 2 copy which pushes duplicates of the top two things on the stack. What are these things? ??! (After this duplication the 2 is no longer on the stack.)

Well, they're probably numbers. In the first example, they're almost definitely a coordinate pair: x and y:

  • If y is greater greater than or equal to 2 x, then draw a line to (current-x + y-from-stack, 0) from the current position to (y,0). Why do this? ??!

  • Else execute the code that's represented by the ellipsis { ... }

In the second example, KochR is most likely a recursive procedure to draw a Koch curve where one of the parameters is almost certainly the recursion level, and the other is probably the length of a single line-segment (unless it's really sophisticated and offers a global-scaling control).

That's about all that can be guessed from the code as shown.

Me answered 12/9, 2012 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.