Identicons library
(require (planet "identicons.ss" ("mk" "identicons.plt" 1 0))) |
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.
1 identicon% class
To make an identicon from a single 32-bit value, pass it as an argument during object creation:
superclass: object% |
(make-object identicon% seed) → (is-a?/c identicon%)
seed : integer?
Creates a new identicon using bits from the given seed.
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.
size : integer?
Return a bitmap of given size with this identicon drawn on it.
(send an-identicon save-to-file
file-path
size)
→
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
Create an identicon using a random seed value.
Save a random identicon under a filename derived from its seed value. Procedure returns the generated filename.
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) |
(grid-bitmap (make-object bitmap% grid-size grid-size)) |
(grid-dc (new bitmap-dc% (bitmap grid-bitmap)))) |
(y (in-range identicons-number))) |
(let* ((identicon (random-identicon)) |
(bitmap (send identicon on-bitmap identicon-size))) |
(* y identicon-size)))) |
(send grid-bitmap save-file "grid.png" 'png))) |