Postscript module for newLISP

Started by Lutz, July 13, 2006, 05:46:27 PM

Previous topic - Next topic

Lutz

See here for source and demos: http://newlisp.org/index.cgi?Postscript">http://newlisp.org/index.cgi?Postscript



linked from: http://newlisp.org/index.cgi?page=Art">http://newlisp.org/index.cgi?page=Art



Lutz

noah

#1
Hi, Everybody.



For anyone who's interested in more postscript stuff, the http://partners.adobe.com/public/developer/ps/sdk/index_archive.html">Developer SDK is available. Check out the http://partners.adobe.com/public/developer/ps/sdk/sample/index_psbooks.html">Postscript books available for free as well.



The so-called http://partners.adobe.com/public/developer/en/ps/sdk/sample/BlueBook.zip">Blue Book is a great starting point (exactly where I'm at). You'll have to agree to the license agreement to download the SDK books, and if you google for them, you'll notice that the search terms "blue book postscript", "green book postscript", and "red book postscript" turn up results.



Once you do, you'll see what I'm seeing, which is a fantastic shortcut to producing postscript graphics, courtesy of Lutz.  This might be a good time to turn to the book http://www.math.ubc.ca/~cass/graphics/manual/index.html#other">Mathematical Illustrations with Postscript, and see what newLISP postscript can do. It's a little too much geometry for me, but you graphics people out there will probably eat it up.



I'm actually interested in producing print-ready documents using newLISP, creating something like a formatting language processor in newLISP for SXML http://www.w3schools.com/xslfo/default.asp">XSL-FO, (or maybe something a wee bit simpler), that produces documents in different output formats, but particularly postscript and pdf.



-Noah

cormullion

#2
Wow! That's great work, Lutz! I was going to do some work today, but I'll think I'll do this instead... :-)

newBert

#3
Unfortunately it does not work on my Windows XP, even with the last release of Ghostscript !



newLISP.exe exits with an error ...



Where did I make a mistake ?
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>

Lutz

#4
The .lsp files as they are on the website will only work on the Mac because of the last statement which is always (ps:render) and calls a Mac utility.



On WinXP and UNIX replace the (ps:render) with (ps:save "myfile.ps") The you can use "myfile.ps" (or any other filename) together with Ghostscript.



I will put these instructions also on the webpage in a few minutes.



Lutz

m i c h a e l

#5
Hello all you happy newLISPers!



Here are a few of the pieces produced from the following code (which sometimes fails for unexplored reasons, but this is art, not science ;-)


(load "/code/lisp/postscript.lsp")

(define (rand-num)
(let
(num (+ (rand 300) 55))
(rand num)))

(ps:goto 306 351)

(dotimes (n/a 40)
(ps:bezier
(rand-num) (rand-num)
(rand-num) (rand-num)
(rand-num) (rand-num)))

(ps:render)


http://www.neglook.com/images/noname1.jpg">



http://www.neglook.com/images/noname5a.jpg">



http://www.neglook.com/images/noname8.jpg">



http://www.neglook.com/images/noname9.jpg">



http://www.neglook.com/images/noname9a.jpg">





I think they're quite beautiful already, but I'm working on adding shading, as well as gaining more control of the randomness while still maintaining a "handmade" look.



Compliments to Lutz for the great set of examples he created for the Postscript page. I know that coming up with examples, let alone interesting ones, is hard work. Oh yeah, and the module's not bad, either ;-) There is one thing that is bad, though. I've been distracted from the manual by playing around with our new newLISP toy! Okay, better get back to work.



m i c h a e l

Fanda

#6
Lutz - very beautiful! I like the examples very much!



I have been playing with it and I wonder if we could change:
(define (goto x y)
  (ps (format "%d %d goto" x y)))

to
(define (goto x y)
  (ps (format "%f %f goto" x y)))


%d -> %f.



Lines don't connect exactly when rounding %d is used. ('goto' uses %d, 'drawto' uses %f).



These functions also use %d:

bezier polygon circle ellipse pie petal translate rotate line-cap line-join



If Postscript allows using floating point numbers in all of these functions, I would prefer them.



Fanda

Lutz

#7
Yes, this definitely has to be changed to take floats, I will post a correction shortly, all numbers will accept floats.



Lutz



Ps: look also into (ps:line-join <mode>) and (ps:line-cap <mode>) for improving connections. Just posted a new postscript.lsp with all %d changed to %f.

Fanda

#8
One more thought:



To make postscript files smaller, would it be ok to round floating point numbers to 3-4 decimal points???



Like this:
> (format "%.3f" 12.345678)
"12.346"
> (format "%.3f" 12.3)
"12.300"
>


Fanda

Lutz

#9
I just changed again to %g this will only specify as much decimals as required. I also had problems with %f on some code:



#!/usr/bin/newlisp

(load "postscript.lsp")

; Background
(ps:goto 0 0)
(ps:fill-color 1.0 0.5 0.0)
(ps:shape '((0 792) (90 612) (90 792) (90 612)) true)

(ps:line-color 0.3 0.3 0.1)
(ps:line-join 2)
(ps:line-width 1)

(define (tree len)
    (if (> len 4)
        (begin
;           (ps:line-width (div len 4))
            (ps:draw len)
            (ps:gsave)
            (ps:turn -20)
            (tree (div len 1.45))
            (ps:grestore)
            (ps:turn 20)
            (tree (div len 1.45))
        )
))

(ps:angle 0)
(ps:goto 306 50)
(tree 200)

(ps:render)
(exit)


this would not translate well with %f but does well now with %g



Lutz

Fanda

#10
%g will work :-))))



Fanda

newdep

#11
Aaaaa yes... I needed to test this under OS/2 ;-)

heheh full support for 8.45 ;-) Il allworks like a charm...!!



nice work this postscript.lsp !!
-- (define? (Cornflakes))