A few days ago, I read about Robohash, a website for creating unique images (of robots) from any text. The author was thinking of using it for icons on a forum, but there are probably other use-cases for this. For example, as a variation of the color password hash to help users avoid typos in their passwords or, perhaps, as a visual representation of a user-submitted "secret code".
The code for this is on my Github.
First, we need to create URLs of the formUSING: images.http kernel sequences urls urls.encoding ;
http://robohash.org/YOUR_TEXT
, as instructed:Next, we would like to support the different "image sets" that Robohash supports.: robohash-url ( str -- url ) url-encode "http://robohash.org/" prepend >url ;
Using this, we can create image loaders for each set (currently three sets: "set1", "set2", and "set3"):: (robohash) ( str type -- image ) [ robohash-url ] [ "set" set-query-param ] bi* load-http-image ;
You can try it out and see that it works:: robohash1 ( str -- image ) "set1" (robohash) ; : robohash2 ( str -- image ) "set2" (robohash) ; : robohash3 ( str -- image ) "set3" (robohash) ;
Robohash also supports custom backgrounds, changing image sizes, and varying image formats (e.g., JPG or BMP). Adding support for that is an exercise to the reader.
The code for this is on my Github.
Eh, nice, I didn't know robohash
ReplyDeleteerror message from "load-http-image":
ReplyDeleteGeneric word length does not define a method for the url class.
@iamhuzhe: You might be using an older version of Factor. I made a commit six months ago that allows URLs to be used with load-http-image.
ReplyDeleteYou can get this to work on your version by calling "present" before load-http-image to turn it into a string. (Remember to USE: present).
Hi mrjbq7
ReplyDeleteI was using the Development release on Windows X86 (2011-02-27). Judging from the date, it does lag behind the Mac Os X version.