Friday 3 December 2010

Electronics for Dogs 3 - everything is a number

So I mentioned last time how everything is a number. Many people might get this straight away, for others just how the web page they are currently reading isn't actually letters as you normally think of them but in fact an awful lot of numbers is a bit of a strange concept.

So let me start with it's all about context. The numbers 62, 76, 111 are equally good as letters on a page, values of sound level on an answer phone message or polygon locations on Buzz lightyears helmet; like everything in life it's what you do with them.
Again let's take a simple example. Text that I'm typing now. If you only have numbers then what do you do? Well you could start by saying 0=a, 1=b, 2=c. As it happens the most common standard is known as ASCII and a is represented by the number 97, b by 98 and so on. Lower values being used for UPPER CASE characters, punctuation, and numbers themselves. Wait, what? I hear you say, numbers for numbers?
Yes in an ASCII text file the number 12 is represented by the number 49 then the number 50. The space character is the number 32 and so on. If you want the full list have a look here.

So what about things like Microsoft Word. That allows you to do lots of things with text such as BOLD and italics, different colours and so on. Wait a minute I just did that on the web too. How does that work? Are there further numbers used for bold, maybe a bold letter a is stored as the number 165342...
The short answer is it is up to the writer of the program what they do but the web chooses a very interesting solution. (Disclaimer in the modern days of CSS and Java and the like this is far from the full story, but it'll do for now.)
Imagine a program that read in the text file as before, but if I typed some text then the brackets would be taken as an instruction to display some text. So a file containing only text (that was composed of numbers) would be displayed as something much richer.
Again don't worry too much here is a good starting place if the details interest you.

What else? Well the MP3s you listen to on your music device of choice? I'm sure you're aware that music and sound is just the movements of air. A speaker moves itself back and forth to move air back and forth. Why not represent the movement of the speaker, it's position from millisecond to millisecond with a lot of numbers? You may have heard of 20 kHz 40khz or 44 or even 48kHz mp3s. This is exactly it. In a 48kHz mp3 there are 48000 numbers used per second to represent the position of each of the speakers. Sure that's a lot of numbers but I did mention that these computers were quite fast...

What about one of the wonders of the modern age where reality and computers mix? CGI, watching Beowulf it can be hard to believe it's not real never mind that it's all a lot of numbers.
Let's start with something much simpler. Remember Terminator 2? Actually no let's go even simpler. Luxo Jr. The first feature pixar did and still a classic. How on earth do you describe that as a lot of numbers?
I assume you're happy with the concept of Cartesian co-ordinates. You know that thing from maths where a line starts at 3 across 4 up and continues to 7 across 3 up.
Well that's what you're doing with 3d graphics, and instead of line you have triangles. Corner 1 of the tiangle is at 3 across 4 up 2 deep. Corner 2 is at 7 across 3 up 24 deep. Corner 3 is at etc.
Fine you say, that describes a single triangle. That movie had spheres and cones. It had light sources and the ball had patterns on it. The short answer is again that if you use enough triangles then like you can make a football out of hexagons then you can make a sphere out of triangles. If you use enough then you can make any shape. As for the patterns on the ball, well then you just give each triangle a number to represent its colour. Or you have a picture that the rendering engine (the thing that takes this list of triangles and produces a picture) paints around the shape.
Yes it's an awful lot of numbers, yes it's a lot of work to build up a character's face from a collection of spheres cones boxes etc, but now you might have an inkling as to why CGI is so very expensive.

So now you know. Your keyboard is just sending a sequence of numbers to your computer. Your mouse is just sending numbers saying how fast and in what direction it is moving. The webpage is just a whole bunch of numbers saying the letter to use and how it should be displayed. Your webcam is just sending a stream of numbers saying what colour each pixel it sees should be at. That youTube video you watched, again more numbers saying how the pixels on your screen should change. It's all numbers and that's all the computer does; and it's all you need.
Next though we need to look at the numbers themselves because it's never as simple as you'd first hope it to be...

No comments: