HomeScheme Language

Scheme as a scripting language for GD library

example.scm

GD is a graphics library especially useful for World Wide Web applications.

Scheme is a natural choice for a scripting language.

Bigloo-lib makes it possible to use Scheme as a scripting language for GD library.

Just compare this simple Scheme example with its C counterpart from GD manual:

Scheme:


(let* 
  ; Allocate the image: 64 pixels across by 64 pixels tall
  ((im (gd-image-create 64 64))

  ; Allocate the color black (red, green and blue all minimum).
  ;  Since this is the first color in a new image, it will
  ; be the background color.
  (black (gd-image-color-allocate im 0 0 0))
  
  ; Allocate the color white (red, green and blue all maximum).
  (white (gd-image-color-allocate im 255 255 255)))
       
; Draw a line from the upper left to the lower right,
;                using white color index.
(gd-image-line im 0 0 63 63 white)
 
; Output the image to the disk file.
(gd-image-write-gif im "test.gif"))

C:


int main() {
      /* Declare the image */
      gdImagePtr im;
      /* Declare an output file */
      FILE *out;
      /* Declare color indexes */
      int black;
      int white;

      /* Allocate the image: 64 pixels across by 64 pixels tall */
      im = gdImageCreate(64, 64);

      /* Allocate the color black (red, green and blue all minimum).
              Since this is the first color in a new image, it will
              be the background color. */
      black = gdImageColorAllocate(im, 0, 0, 0);

      /* Allocate the color white 
              (red, green and blue all maximum).*/
      white = gdImageColorAllocate(im, 255, 255, 255);
      
      /* Draw a line from the upper left to the lower right,
              using white color index. */
      gdImageLine(im, 0, 0, 63, 63, white);

      /* Open a file for writing. "wb" means "write binary", 
              important under MSDOS, harmless under Unix. */
      out = fopen("test.gif", "wb");

      /* Output the image to the disk file. */
      gdImageGif(im, out);

      /* Close the file. */
      fclose(out);

      /* Destroy the image in memory. */
      gdImageDestroy(im);
}

More examples

An example of GD-enabled Bigloo interpreter
This is just a precompiled (RedHat 6.2) binary of the

bigloo-lib/gd/driver
from bigloo-lib-0.15pl1. It depends on Bigloo and gd.

HomeScheme Language