Archive

Archive for October, 2008

A Case for Canvas

October 30th, 2008

I recently came across this page, which shows a rudimentary rotating 3D cube made entirely of javascript. Since I’m a code geek I of course thought it deserved a kudo or two, but it got me thinking; why isn’t the canvas tag more widely used (or supported natively in Internet Explorer)? For those of you who don’t know what the canvas tag is, it’s essentially an environment for drawing things on the fly in web pages, without having to use a plug-in like Flash. It is probably something that is easiest to appreciate through some examples, so I present to you the following simple comparison of what can be done with javascript alone versus javascript plus the canvas tag (scroll your mouse over the cubes to rotate them):

Javascript Only:

Javascript and the Canvas Tag:

The top cube makes use of 18 images (for drawing the lines via the trick described here) and about 1.0kB of javascript code. The bottom cube is animated using 509 bytes of javascript code in conjunction with the canvas tag. That’s it — no auxilliary images or plug-ins of any kind.

Personally, I think that’s pretty awesome, and I wish that the usage of the canvas tag would leave the realm of the tech demo. People need to realize its potential and start really using it. It’s supported in all major current browsers (OK, you have to do some trickery to get it to work in Internet Explorer, but it still requires no work on the part of the end-user) and it does things that simply can not be done otherwise without loading a plug-in like Flash. Consider the following variation of the 3D rotating cube:

Colour Cube via Canvas Tag:

I believe that it’s flat-out impossible to replicate the above coloured cube using only CSS and javascript without the canvas tag, but even if it is possible, it certainly won’t be easy or scalable — the canvas tag is both.

Related Links

  • Canvas Tutorial - A tutorial provided by Mozilla for using the canvas tag.

Math CAPTCHAs in ASP

October 9th, 2008

The idea of math-based CAPTCHAs has been around for a while, but it still hasn’t caught on much for some reason. Personally, I think the idea of a website asking you to enter the value of 7 + 8 is much less annoying than it asking you to squint and try to make out distorted letters and numbers. Thus, I have put together four ASP math-based CAPTCHA scripts that are freely-available for download and can be used or modified however you see fit. I have outlined the pros and cons of each of the scripts to help you decide which (if any) of them is right for you. Note that all four of these scripts make use of the AspJpeg component though the scripts could easily be modified to work with other components or produce text output.

Arithmetic CAPTCHA

This is the most basic of the math CAPTCHA scripts — it asks the user to provide the answer to a simple arithmetic question (either addition, subtraction, multiplication, or division). The script could easily be modified to ask more complicated questions such as “(12 / 4) + 7 = ?” or “33 = ?”.

Features and Benefits:

  • You can select the difficulty of the questions that the CAPTCHA asks.

Downsides:

  • If the difficulty is low, most answers will be in the range 1 – 25, which means that a SPAMbot has a decent chance of randomly guessing the correct answer.

Example:

 

Download:

 

Dictionary CAPTCHA

Quite a few websites now use CAPTCHAs that display words rather than random letters and numbers, and that is definitely a step in the right direction towards making CAPTCHAs less annoying. One step further though, is to use themed word lists that fit with the content of your website. This script does exactly that; it displays three words randomly selected from word lists that you create.

Features and Benefits:

  • Won’t alienate users with no math knowledge.
  • Comes with enough math terms to generate over 25 000 unique CAPTCHAs.
  • Word lists can easily be customized to fit any website.

Downsides:

  • Defeated reasonably easily by OCR software (this could be fixed by adding lines through the image and so on).

Example:

 

Download:

 

Sequence CAPTCHA

The Sequence CAPTCHA displays a sequence of numbers and asks the user to predict the next number in the sequence. The script generates one of three types of sequences: arithmetic, geometric, or Fibonacci-type. However, you could easily edit the code to generate some really nasty sequences if you dislike the visitors of your website that much.

Features and Benefits:

  • It’s reasonably immune to being broken by SPAMbots, unless someone spends a lot of time making a script specifically for your website.

Downsides:

  • Unless your visitors are very math-oriented, they will hate you.

Example:

 

Download:

 

Word Arithmetic CAPTCHA

This is a simple twist on the Arithmetic CAPTCHA that replaces the numbers by words and thus asks questions like “Ten × Four = ?”. The questions are slightly easier by default than the questions in the Arithmetic CAPTCHA script.

Features and Benefits:

  • Accepts both numeric and word input from the user.
  • Quite resilient against being broken by SPAMbots.

Downsides:

  • As with the Arithmetic CAPTCHA, a random answer in the range 1 – 25 has a decent chance of being correct.
  • Some questions like “Forty Three – Twenty Seven” might scare away certain users. Then again, those may be precisely the types of users that you want to scare away.

Example:

 

Download:

Tags: , ,

New Website Launched

October 2nd, 2008

Well, after squatting on this domain for about a year, I finally decided that I might as well put a website up here again. The website is going to be much more math-oriented this time around since I’m a nerd like that. In that vein, my first entry here will simply be one of the only math-related things that I wrote on the old site (on November 22, 2005):

After hours of thought and consideration, I have come to the conclusion that the way in which math is taught sucks monkey fur.

Let us take, for example, a Numerical Methods assignment that I currently have sitting in front of me. One particular question (which is worth a whopping 0.0769% of my final mark) on this assignment requires to me to find eigenvalues of a 3 × 3 matrix for which the characteristic polynomial does not factor.

“But Nathan,” I can hear you say, “that’s simply a matter of plugging numbers into the cubic root formula! What’s your problem, ho?”

And though you are quite correct, allow me to print, in its entirety, said formula:

Cubic Formula

“But Nathan,” I can hear to chirp up again, “why don’t you just use the QR Algorithm or MATLAB or some other method to find the roots?”

Well, it seems that this route of escape was thought of by the prof, so she specifically states that we are to compare our answer with the one obtained from MATLAB – indicating that we are indeed actually expected to find these roots by hand and get the exact answers – to obtain a whopping 0.0769% of our final mark (actually, considerably less than that – this is only one part of a multi-part question).

“But Nathan,” I hear you say one final time, “why don’t you talk about something interesting? I don’t know what the hell the QR Algorithm is, nor could I care less.”

Shut up, I never talk about math on here, I’ve been generous until now, so let me rant. I’m getting sick and tired of so many courses managing to teach so little, while expecting so much. Why do we have to prove over and over again that we are capable of plugging numbers into longer and longer formulae, while not actually being required to demonstrate any real insight along the way?

So, tell me professors, what is the point of this? And what is the point of us having to draw nine linearizations to complete question #1 on a differential equations assignment? You don’t believe that we know how to do it after the first eight times? Why do you feel the need to ask the same questions over and over again, while giving us nothing really insightful or different on the assignments?

Maybe someday down the line if/when I become a professor I’ll understand (and perhaps even prove) that making assignments ridiculously repetitive and far more tedious than necessary is a fundamental law of the universe which keeps us all in harmony and prevents the Earth from being hurled into the sun. But, barring that realization, I make the following vow to my future students, should I become a professor:

I will (try to) make assignments for my classes (as) interesting (as possible for a math class) and will not ask you to do questions that involve exceedingly gross algebra (unless you all get on my bad side by skipping lectures) for no good reason.