Another feature added to Maple 15 partially in response to the MaplePrimes forums is the new/improved ?HTTP package.  It provides one-step commands for fetching data from the web: much simpler than using the ?Sockets package directly. In most cases, the command ?HTTP,Get is what you would use:

 (s, page, h) := HTTP:-Get(""):

The above fetches the HTML source of a page from Wikipedia and stores it as a string 'page'. The other two outputs are 's', and integer HTTP status code and 'h' a table of the headers returned in the HTTP response from the server.  Compare this to the amount of code needed to fetch data in my Baby Names application for Maple 12, for example.

Now, that we have imported a cool piece of data like the names of RGB codes for all the Crayola Crayon colors, we really should do something with it.  The first thing I did, was parse the data into a Maple table by parsing the HTML with ?StringTools and ?XMLTools :

    htmltable := colorpage[ts[2]..te[2]+8]:

    xmltable := XMLTools:-ParseString(htmltable):
    thedata := map(XMLTools:-GetChildByName, XMLTools:-GetChildByName(xmltable, "tr"), "td"):
    thedata := remove(x->x=[], thedata):
    thedata := map(x->map(y->XMLTools:-TextText(indets(y, specfunc(anything,_XML_Text))[1]), x), thedata):

    colourtable := table( map(x->x[2]=COLOR(RGB, op([parse(x[4])] /~ 255.)), thedata) );

This gives us the color data in a easy to use form (Maple color structures for each color looked up by name). We could use this to let use choose colors for plots by their Crayon names, for example. But, I went a little crazy and wrote a fairly eleborate worksheet to quiz you on your crayon knowledge. It looks like this:

Download the worksheet: (be sure to click "Fetch Crayon Colors", or it will default to quizing you on the X11 color names).

There are instructions in the worksheet for how to play the quiz (which also lets you try your skill on two other sets of colors as well).  The most technically interesting thing about the quiz is probably the theory of color used to make it get successively harder (it should start very easy and get harder when you answer correctly). That is done by computing the distance between the two colors presented to the user.  There a few different ways to comptue color difference, but I chose to use the CIE 1994 difference formula which compares two colors in the CIE La*b* Color Space; this distance is shown under the answer from the last quiz.  To compute a proper conversion from RGB color to La*b* color requires knowing a bunch of details about your monitor, but I just used some average numbers which seem to produce pretty good results.

And you can see, when the difficulty gets up to 100, the quiz becomes quite hard!

Enjoy and please let me know if you manage to make it to 300 points! (My personal best is around 175)

Please Wait...