Postscript module for newLISP

Notices and updates
Locked
Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Postscript module for newLISP

Post by Lutz »


noah
Posts: 36
Joined: Sat Apr 22, 2006 9:02 pm

Postscript production in newLISP

Post by noah »

Hi, Everybody.

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

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

-Noah

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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

newBert
Posts: 156
Joined: Fri Oct 28, 2005 5:33 pm
Location: France

Post by newBert »

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 ?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 394
Joined: Wed Apr 26, 2006 3:37 am
Location: Oregon, USA
Contact:

Post by m i c h a e l »

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 ;-)

Code: Select all

(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)
Image

Image

Image

Image

Image


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
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

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

I have been playing with it and I wonder if we could change:

Code: Select all

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

Code: Select all

(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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

One more thought:

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

Like this:

Code: Select all

> (format "%.3f" 12.345678)
"12.346"
> (format "%.3f" 12.3)
"12.300"
> 
Fanda

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Code: Select all

#!/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
Last edited by Lutz on Sat Jul 22, 2006 7:38 pm, edited 1 time in total.

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

%g will work :-))))

Fanda

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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))

Locked