blogroll tags

A work of art.

(define (draw-mine-field x)
   (if (= x 0)
        '()
        (begin
            (draw-mine-line (- XX x) YY)
            (with-state
                (translate #(1 0 0))
                (draw-mine-field (- x 1))))
    ))

(define (draw-mine-line x y)
    (if (= y 0)
        '()
        (begin
             (draw-mine x (- YY y))
             (with-state
                (translate #(0 1 0))
                (draw-mine-line x (- y 1))))
    ))


(define (draw-mine x y)
    (with-state
        (let ((center-x (- (/ XX 2) 0.5))
              (center-y (- (/ YY 2) 0.5)))
            ; default size, colour
            (scale (vector 1 1 1.5))
            ;(colour (vector (gh 1) (gh 3) (gh 5)))
    
            ; scale up center mines
            (let* ((D     (* 1.3 (sqrt (+ (expt (- x center-x) 2)
                                          (expt (- y center-y) 2)))))
                   (factor (* (gh 1) (log (+ 1 (abs (/ (sin D) D)))))))
                (scale (vector 1 1 (+ 1 (* 3 factor))))
                (colour (vector (+ 0.1 factor) (- 0.8 factor) 0))
            )
    
            ; X-dependent jumping!
            (let ((factor (+ (* (gh 3) (/ 1 (+ 1 (* 0.01 XX x))))
                             (* (gh 5) (/ 1 (+ 1 (* 0.01 XX (- XX x)))))
                        ))) 
                (translate (vector 0 0 (+ 1 (* 3 factor)))))
    
            ; spread out!
            (let ((x-factor (* (gh 7) 0.5))
                  (y-factor (* (gh 6) 0.5)))
                (translate (vector (* x x-factor) (* (- y center-y) y-factor) 0)))

            ; the yy-curve!
            (let ((factor (* (gh 4) (expt (* (- y center-y) (/ 3 YY)) 3))))
                (translate (vector 0 0 factor)))
    
            (draw-cube))))

(define (show-things)
    (clear-colour (vector (* 0.15 (gh 7))
                          (* 0.15 (gh 8))
                          (* 0.30 (gh 6))))
    (draw-mine-field XX))


(start-audio "alsa_pcm:capture_1" 1024 44100)

(clear-colour #(0 0 0))

(show-fps 1)

(define XX 100) (define YY 25)

(every-frame (show-things)) 

... in a way.

hint: (fluxus).

Read more...

Lisping: IRC bots are fun

A wee while ago, I decided to learn a lisp. Randomly, my lisp of choice was Common Lisp. (though I will probably have a look at Scheme sooner or later) As if a new programming language wasn't enough, I also started using GNU Emacs (rather than my previous absolute favourite Vim) for editing the code... Why ? SLIME. Implementation-wise, I have used GNU CLISP (love it), Steel Bank Common Lisp (SBCL, quite nice) and GCL (rather pointless).

Of course, you cannot really learn a programming language without programming with it. Back in the day, I used the BWInf competition to learn the adorable Python language (along with a book), and this time, I solved a part of this years' BWInf round 1 in Common Lisp for starters. But, more importantly, as it was more fun and I can publish the code, I have written a bare-bones IRC bot in lisp using the CL-IRC library (which is very lacking in documentation, but both the IRC protocol and the library source code are open, so that wasn't a great problem).

You can get the code via Mercurial.

There is really only one aspect of the implementation worth noting here: the command-creation macros. Not really spectacular, but rather lispy, I'd say.

Instead of

(defun blah-command (connection source channel text)
  ; make sure the user is logged in
  ; parse the text into useful chunks
  ; more ))) than cool
)
(setf \*commands* (cons (list "blah" #'blah-command
                             "blah documentation) \*commands* ))

You write

(auth-irc-command admin "blah" (connection source channel) (arg1 arg2 arg3)
  ; get stuff done
)

etc.

Macro definitions are here.