Wednesday, May 19, 2021

Playing with Racket: random lines GIF

I'm enjoying playing with Racket. Takes me back to some good old college days writing Scheme, but I don't think creating a GIF was so easy in any of the Scheme systems we were using then. (Which ecosystem -- language + standard libraries -- provides the nicest environment for making animated GIFs?)
#lang racket

(require mrlib/gif)
(require racket/draw)

(define (random-lines-bitmap width height line-count)
  (let* ([target (make-bitmap width height)]
         [dc (new bitmap-dc% [bitmap target])])
    (begin
      (send dc draw-rectangle
       0 0   ; Top-left at (0, 10), 10 pixels down from top-left
       (- width 1) (- height 1))
      (for ([i line-count])
        (send dc draw-line
              (random width) (random height)
              (random width) (random height)))
      target)))

(define (write-random-lines-gif width height line-count frame-count filename)
  (write-animated-gif
   (for/list ([i frame-count])
     (random-lines-bitmap width height line-count))
   10
   filename
   #:loop? true))

(write-random-lines-gif 300 200 50 10 "random-lines.gif")

"Why Concatenative Programming Matters"

I enjoyed reading Why Concatenative Programming Matters. I'd like to do more with Factor sometime. Is it still under active development? I see that new binaries are still getting generated for it anyway.
"https://evincarofautumn.blogspot.com/2012/02/why-concatenative-programming-matters.html" >url http-get* length
...
261104
(This seems to work. Am I leaving extra stuff on the stack?)

Sunday, May 16, 2021

Clojure!

https://clojure.org/guides/getting_started emphasizes Homebrew, but MacPorts has it too. I also had to install OpenJDK too. I think for me, the minimal set of commands could have looked like:
sudo port install clojure +rlwrap
sudo port install openjdk11
clj
user=> (+ 1 1)
2
Woohoo!