(archive 'newLISPer)

August 21, 2007

newLISP news

Filed under: newLISP — newlisper @ 15:56
Tags:

I’ve not been writing too much here recently, but here are a few bits and pieces to stop the page from fading away completely.

newLISP version 9.2 has just been released, containing all the graphical goodness that I wrote about previously. I’ve been learning how to use it by trying to write some simple applications. You can laugh at these over at the newLISP fan club wiki, which Ryon has kindly made available for us to play around with. After having a go at Life, the well-known cellular automaton game, I tried to write a version of Reversi, the well-known black and white counter game. There’s also a simple countdown timer, and a slideshow app which I abandoned because it didn’t work out as well as I’d hoped. (Finishing things is harder than starting them, I find.)

One of the hardest things to do, particularly if you’ve been used to writing scripts, is to remember that a graphical application is mainly event-driven – you put everything place and then just wait for things to happen, although you don’t know what order they’re going to happen in.

I’ve also been updating my Introduction to newLISP in an attempt to keep up both with the errors and omissions that I and others notice and with the never-ending succession of improvements that Lutz manages to produce for each release. I’ve added a little taster for the new graphics tools in the form of a simple color mixer.

There’s a brief line by line description of the following code in the final chapter:

#!/usr/bin/newlisp
(if (= ostype "Win32")
    (load (string (env "PROGRAMFILES") "/newlisp/guiserver.lsp"))
    (load "/usr/share/newlisp/guiserver.lsp")
)

(gs:init)

(gs:frame 'Mixer 200 200 400 300 "Mixer")
(gs:set-border-layout 'Mixer)
(gs:set-resizable 'Mixer nil)

(gs:panel 'SliderPanel)
(gs:set-grid-layout 'SliderPanel 3 1)
(gs:panel 'RedPanel)
(gs:panel 'GreenPanel)
(gs:panel 'BluePanel)

(gs:label 'Red   "Red"   "left" 50 10 )
(gs:label 'Green "Green" "left" 50 10 )
(gs:label 'Blue  "Blue"  "left" 50 10 )
(gs:slider 'RedSlider   'slider-handler "horizontal" 0 100 0)
(gs:slider 'GreenSlider 'slider-handler "horizontal" 0 100 0)
(gs:slider 'BlueSlider  'slider-handler "horizontal" 0 100 0)
(gs:label 'RedSliderStatus   "0"  "right" 50 10)
(gs:label 'GreenSliderStatus "0"  "right" 50 10)
(gs:label 'BlueSliderStatus  "0"  "right" 50 10)
(gs:add-to 'RedPanel 'Red 'RedSlider 'RedSliderStatus)
(gs:add-to 'GreenPanel 'Green 'GreenSlider 'GreenSliderStatus)
(gs:add-to 'BluePanel 'Blue 'BlueSlider 'BlueSliderStatus)
(gs:add-to 'SliderPanel 'RedPanel 'GreenPanel 'BluePanel)

(gs:canvas 'Swatch)
(gs:label 'Value "")
(gs:set-font 'Value "Sans Serif" 16)

(gs:add-to 'Mixer 'SliderPanel "north" 'Swatch "center" 'Value "south")
(gs:set-visible 'Mixer true)

(define (codes r g b)
; return codes for r g b values between 0 and 1 as newLISP and hex
  (string (list r g b) {  }
    (join
      (map
        (fn (n) (format {%02x} (mul n 255)))
        (list r g b)))))

(set 'red 0 'green 0 'blue 0)
(gs:set-color 'Swatch (list red green blue))
(gs:set-text  'Value (codes red green blue))

(define (slider-handler id value)
  (cond
     ((= id "MAIN:RedSlider")
        (set 'red (div value 100))
        (gs:set-text 'RedSliderStatus (string red)))
     ((= id "MAIN:GreenSlider")
       (set 'green (div value 100))
        (gs:set-text 'GreenSliderStatus (string green)))
     ((= id "MAIN:BlueSlider")
       (set 'blue (div value 100))
       (gs:set-text 'BlueSliderStatus (string blue)))
     )
  (gs:set-color 'Swatch (list red green blue))
  (gs:set-text  'Value (codes red green blue)))

(gs:listen)

Also, Dukester on the newLISP board convinced me that an HTML version of this PDF intro might a Good Thing. Obviously, keeping the two versions in sync would also be a Good Thing, so I’ve written a translator that converts the TEX (ConTeXt) source file to HTML. You can find a rough HTML translation of the introduction here. Be aware that the graphic images haven’t been uploaded (yet?), and that I’m not known for my HTML and CSS skills anyway. But you should be able to apply a CSS style sheet (called styles.css) to a local copy and get things looking the way you want them.

Advertisements

2 Comments »

  1. >Thanks for another fun post!BTW, I noticed your Life page at the wiki was missing (I hope it wasn’t you who deleted it ;-) so I restored it. I also password-protected it with the wiki password.m i c h a e l

    Comment by m i c h a e l — August 24, 2007 @ 04:11 | Reply

  2. >thanks!

    Comment by newlisper — August 25, 2007 @ 22:04 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: