summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--posts/2018-09-01-guile-picture-language.md74
1 files changed, 74 insertions, 0 deletions
diff --git a/posts/2018-09-01-guile-picture-language.md b/posts/2018-09-01-guile-picture-language.md
new file mode 100644
index 0000000..3fcac51
--- /dev/null
+++ b/posts/2018-09-01-guile-picture-language.md
@@ -0,0 +1,74 @@
+title: A simple picture language for GNU Guile
+date: 2018-09-01 23:00
+tags: planet-fsfe-en, free software, guile
+---
+
+One thing that I really love about Racket is its [picture
+language](https://docs.racket-lang.org/pict/), which allows you to
+play with geometric shapes in an interactive session in Dr Racket.
+The shapes are displayed right there in the REPL, just like numbers or
+strings. Instead of writing a programme that prints "hello world" or
+that computes the Fibonacci numbers, one could write a programme that
+composes differently rotated, coloured shapes and prints those
+instead.
+
+I use [GNU Guile](https://gnu.org/software/guile) for my own projects,
+and sadly we don't have an equivalent of Racket's picture language or
+the Dr Racket editor environment. So I made something: a [simple
+picture language for GNU
+Guile](https://git.elephly.net/software/guile-picture-language.git).
+It provides simple primitive procedures to generate shapes, to
+manipulate them, and to compose them.
+
+Download the single Guile module containing the implementation:
+
+ mkdir ~/pict
+ wget https://elephly.net/downies/pict.scm
+
+To actually see these shapes as you play with them, you need to use a
+graphical instance of [GNU Emacs](https://gnu.org/software/emacs) with
+[Geiser](http://www.nongnu.org/geiser/).
+
+Start geiser in Emacs and load the module:
+
+ M-x run-guile
+ (add-to-load-path (string-append (getenv "HOME") "/pict"))
+ ,use (pict)
+
+Let’s play!
+
+ (circle 100)
+
+If you see a pretty circle: hooray! Let’s play some more:
+
+ (colorize (circle 100) "red")
+ (disk 80)
+ (rectangle 50 100)
+
+Let's compose and manipulate some shapes!
+
+ ,use (srfi srfi-1)
+ ,use (srfi srfi-26)
+ (apply hc-append
+ (map (cut circle <>)
+ (iota 10 2 4)))
+
+ (apply cc-superimpose
+ (map (cut circle <>)
+ (iota 10 2 4)))
+
+ (apply hc-append
+ (map (cut rotate (rectangle 10 30) <>)
+ (iota 36 0 10)))
+
+ (apply cc-superimpose
+ (map (cut rotate (triangle 100 300) <>)
+ (iota 36 0 10)))
+
+There are many more procedures for primitive shapes and for
+manipulations. Almost all procedures in pict.scm have docstrings, so
+feel free to explore the code to find fun things to play with!
+
+PS: I realize that it's silly to have a blog post about a picture
+language without any pictures. Instead of thinking about this now,
+get the module and make some pretty pictures yourself!