Giter VIP home page Giter VIP logo

identikon's Introduction

a b c

identikon

A small collection of Racket scripts for generating identicons. This is very much alpha and will be changing a lot as I learn more about Racket. Identicons can be saved as PNG or SVG. Obligatory blog post.

Install

$ raco pkg install identikon

Dependencies

You will need to install sugar, quickcheck and css-tools.

Usage

Requiring identikon in Dr. Racket or Emacs with racket-mode or Geiser will give you access to the identikon function in the REPL:

(require identikon)

; Generate a default 300px identicon for "racket"
(identikon 300 300 "racket")

; Generate a q*bert style 300px identicon for "racket"
(identikon 300 300 "racket" "qbert")

; Generate a q*bert style 300px identicon for "racket" and save as an svg
(identikon 300 300 "racket" "qbert" "svg")

; start having real fun with identicons
(require identikon
         2htdp/image)

(define foo (identikon 200 200 "foo"))
(define bar (identikon 200 200 "bar"))
(beside
 (above foo bar)
 (above bar foo))

Note: Trying to use identikon in a standard CLI racket REPL will just return an (object:image% ...) instead of rendering the image. You could save an image to the filesystem this way: (identikon 300 300 "racket" "default" "svg"). If you're accessing the CLI REPL via either racket-mode or Geiser in Emacs then the images will render just fine like so:

geiser

CLI interface (via Raco)

-h  Help
-s  (multi) Size (all identikons are currently squares)
-i  String to convert to identicon
-f  File or input stream used to generate identikon
-r  (optional) Ruleset to use
-t  (optional) Filetype to save as: "png" or "svg"; defaults to png

$ raco identikon -s 300 -i "FooBarBaz"

$ raco identikon -s 300 -i "FooBarBaz" -r "squares"

$ raco identikon -s 300 -i "FooBarBaz" -r "squares" -t "svg"

$ raco identikon -s 300 -s 200 -s 100 -i "FooBarBaz" -r "stars" -t "svg"

Built-in rule sets

Each identicon has a rules file (ex: default.rkt) which is responsible for taking the input data and generating an image as it sees fit. There are a few existing rule sets to play with.

default.rkt

d

qbert.rkt

s

squares.rkt

s

circles.rkt

c

angles.rkt

a

angles2.rkt

a

nineblock.rkt

n

stars.rkt

s

rings.rkt

r

identikon's People

Contributors

bowmanb avatar darrenn avatar racket-dep-fixer avatar samth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

identikon's Issues

Create service

Wrap identikon in a small server to return images on demand.

  • Return images immediately?
  • Cache images on S3?
  • Rate limiting?
  • Front with nginx?
  • Will linode explode?

Return SVG data

Right now identikon will only handle SVG by saving to disk. Add the ability to return SVG data directly. This will allow for fun things like directly embedding SVGs into a Pollen document.

A few issues

Very cool!

A few comments/issues; apologies for lumping them into one GitHub issue.

  1. README: racket-mode also displays images in the REPL. I'd be grateful if you could mention it, too.

  2. README: A third dependency people need to raco pkg install is quickcheck.

    quickcheck seems to have a mistake -- it provides but doesn't define check-result?. After I commented out that, it built fine. I reported that to quickcheck.

  3. Your load-plug-in assumes the current directory. So when I made this little test program in my /tmp folder:

#lang racket
(require identikon/identikon)
(identikon 300 300 "racket")

I got:

; default-load-handler: cannot open module file
;   module path: #<path:/tmp/rules/default.rkt>
;   path: /tmp/rules/default.rkt
;   system error: No such file or directory; errno=2
; Context:
;  /tmp/id.rkt:1:1 [running body]
;  /Users/greg/src/racket/identikon/identikon.rkt:63:0 core16

I worked around it by setting the curdir to your collection:

#lang racket
(require identikon/identikon)
(parameterize ([current-directory "/Users/greg/src/racket/identikon"])
  (identikon 300 300 "racket"))

Then it displays an awesome identikon!

But this probably isn't the way it should work. Maybe you need define-runtime-path to reach files relative to your own source files. Let me know if you have any questions, or if you'd like me to try to submit a pull request.

Again, very cool!

Re-visit user interface

Re-visit the main function interface, perhaps using keyword arguments to make things clearer.

`save-identikon` violates its own contract

#lang racket/base
(require identikon)
(save-identikon "fourty-two"
                'png
                (identikon 1 1 "42"))

causes:

; save-identikon: broke its own contract
;   promised: boolean?
;   produced: #<void>
;   in: the range of
;       (->*
;        (string? (or/c symbol? string?) image?)
;        (#:quality number?)
;        boolean?)
;   contract from: <pkgs>/identikon/main.rkt
;   blaming: <pkgs>/identikon/main.rkt
;    (assuming the contract is correct)
;   at: <pkgs>/identikon/main.rkt:23.24

From what I can tell from a quick look at the source, this is because save-identikon calls functions that return void. Or, it raises an error.

  1. One fix would be to have save-identikon return #t.
  2. Another fix would be to change the contract (in main.rkt and the Scrbibble doc) to say it returns void?.

I think 2 better and almost went ahead and submitted a PR with that. But thought I should ask first.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.