1 identicon% class
2 Top-level functions
3 Example

Identicons library

 (require (planet "identicons.ss" ("mk" "identicons.plt")))

This library is a PLT Scheme implementation of a graphical identification scheme created by Don Park, first described in his blog post Visual Security: 9-block IP Identification. It is capable of generating identicons from 32-bit numbers, using the same generation scheme as the one used by Don Park.

A standard way to use the library is to create an identicon using the identicon% constructor and save it to file using its save-to-file method. You can also take the generated identicon for further manipulation by converting it to a bitmap using the on-bitmap method. For DrScheme interaction window love, check out as-image-snip method.

1 identicon% class

To make an identicon from a single 32-bit value, pass it as an argument during object creation:

identicon% : class?

  superclass: object%

(make-object identicon% seed)  (is-a?/c identicon%)

  seed : integer?

Creates a new identicon using bits from the given seed.

(send an-identicon draw dc)  void?

  dc : (is-a?/c dc<%>)

Draw the identicon on given dc using all available space. Since identicons are square, that will be dc’s width or height, whichever is smaller.

Note: dc will be cleared before drawing and its properties will be altered.

(send an-identicon on-bitmap size)  (is-a?/c bitmap%)

  size : integer?

Return a bitmap of given size with this identicon drawn on it.

(send an-identicon as-image-snip size)  (is-a?/c image-snip%)

  size : integer?

Return an image-snip% of given size with this identicon inside.

(send an-identicon save-to-file













  file-path : path-string?

  size : integer?

Save this identicon of the given size under the file-path.

(send an-identicon display-in-frame size)  void?

  size : integer?

Display this identicon in a square frame of a given size.

2 Top-level functions

(random-identicon)  (is-a?/c identicon%)

Create an identicon using a random seed value.

(save-random-identicon)  path-string?

Save a random identicon under a filename derived from its seed value. Procedure returns the generated filename.

(display-random-identicon)  void?

Display a random identicon in a new 300px frame.

3 Example

As an example of how to generate and combine a number of identicons, analyze the following function identicons-grid that generates a grid of NxN identicons and saves it to grid.png file.

  (define (identicons-grid identicon-size identicons-number)

    (let* ((grid-size (* identicon-size identicons-number))

           (grid-bitmap (make-object bitmap% grid-size grid-size))

           (grid-dc (new bitmap-dc% (bitmap grid-bitmap))))

      (for* ((x (in-range identicons-number))

             (y (in-range identicons-number)))

            (let* ((identicon (random-identicon))

                   (bitmap (send identicon on-bitmap identicon-size)))

              (send grid-dc draw-bitmap bitmap (* x identicon-size)

                                               (* y identicon-size))))

      (send grid-bitmap save-file "grid.png" 'png)))