newLISP Fan Club

Forum => newLISP newS => Topic started by: Lutz on July 13, 2006, 05:46:27 PM

Title: Postscript module for newLISP
Post by: Lutz on July 13, 2006, 05:46:27 PM
See here for source and demos: http://newlisp.org/index.cgi?Postscript



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



Lutz
Title: Postscript production in newLISP
Post by: noah on July 14, 2006, 12:30:59 AM
Hi, Everybody.



For anyone who's interested in more postscript stuff, the Developer SDK (//http) is available. Check out the Postscript books (//http) available for free as well.



The so-called Blue Book (//http) 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 Mathematical Illustrations with Postscript (//http), 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 XSL-FO (//http), (or maybe something a wee bit simpler), that produces documents in different output formats, but particularly postscript and pdf.



-Noah
Title:
Post by: cormullion on July 14, 2006, 12:58:05 AM
Wow! That's great work, Lutz! I was going to do some work today, but I'll think I'll do this instead... :-)
Title:
Post by: newBert on July 14, 2006, 10:22:14 AM
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 ?
Title:
Post by: Lutz on July 14, 2006, 11:32:59 AM
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
Title:
Post by: m i c h a e l on July 15, 2006, 08:47:50 AM
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)


(//%3C/s%3E%3CURL%20url=%22http://www.neglook.com/images/noname1.jpg%22%3Ehttp://www.neglook.com/images/noname1.jpg%3C/URL%3E%3Ce%3E)



(//%3C/s%3E%3CURL%20url=%22http://www.neglook.com/images/noname5a.jpg%22%3Ehttp://www.neglook.com/images/noname5a.jpg%3C/URL%3E%3Ce%3E)



(//%3C/s%3E%3CURL%20url=%22http://www.neglook.com/images/noname8.jpg%22%3Ehttp://www.neglook.com/images/noname8.jpg%3C/URL%3E%3Ce%3E)



(//%3C/s%3E%3CURL%20url=%22http://www.neglook.com/images/noname9.jpg%22%3Ehttp://www.neglook.com/images/noname9.jpg%3C/URL%3E%3Ce%3E)



(//%3C/s%3E%3CURL%20url=%22http://www.neglook.com/images/noname9a.jpg%22%3Ehttp://www.neglook.com/images/noname9a.jpg%3C/URL%3E%3Ce%3E)





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
Title:
Post by: Fanda on July 22, 2006, 11:48:57 AM
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
Title:
Post by: Lutz on July 22, 2006, 12:07:05 PM
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.
Title:
Post by: Fanda on July 22, 2006, 12:19:12 PM
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
Title:
Post by: Lutz on July 22, 2006, 12:26:09 PM
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
Title:
Post by: Fanda on July 22, 2006, 12:26:27 PM
%g will work :-))))



Fanda
Title:
Post by: newdep on August 19, 2006, 10:02:35 AM
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 !!