I saw a captcha with dice thread on hacker news. The general idea
of the captcha was to find the picture of dice with the right sum on it.
I was wondering how hard it would be to generate several thousand of
these dice images, and how long it would take using POV-ray.
POV-ray is the Persistence of Vision Ray Tracer. It takes a text based
description of the scene built using various primitives like spheres and
boxes to produce a ray traced image. The POV-ray language is Turing
complete and allows some really advanced programming features, such as
macros, loops and conditionals, which I take full advantage of for this
scene. The dice are even transparent.
Benchmark and Estimation of Effort to Generate Dices for Captchas.
It took me roughly 6 hours with some exposure to POV-ray in the past to
make the above scene. It takes roughly 10 seconds wall time to render on
my 4 threaded laptop at 1600x900. Generating it at 400x400 takes
approximately 2.5 seconds.
A captcha service should have at least a 100,000 variations on images to
prevent abuse. So generation of the initial set of images would take
roughly 69 and a half hours on my laptop assuming they were run as a
batch process. Also using POV-ray would allow generation of new problems
on the fly. This does not include writing a wrapper to modify the
existing script to change the numbers on the fly.
The following code was used to generate the above image. It uses a lot
of macros and for-loops to improve understandability and brevity. Macros
allow function like creation of objects and enables hiding of what
transformations are required to put things where they need to be.
The dice body is made up of a series of intersections with cylinders on
a cube, so that the cube has some nice looking rounded edges. The dots
are spheres on each face and produced using a difference. Using these
primitive shapes enable exact calculation of geometry, unlike using a
mesh which is only an approximation. Building things like this is called
Constructive Solid Geometry. It’s super useful for when things have
to be precise.
To recreate the above image, run povray Width=1600 Height=900 dice.pov
after copying the code into a file called dice.pov.