Monday, 25 April 2016

First: The Living Room, Then: THE WORLD!

y now, after reading about my adventures with code thus far, I think it might be obvious that my predilection for programming is more than a mere obsession. Eventually, my passion for figuring out better ways to manipulate pixels on a screen extended way beyond that and into the REAL WORLD.

The Tandy 1000-HXThis new journey started in high school; grade 12 to be exact. Being in a small town, my school didn't have much of a budget for cool equipment and technology to play with, so much of my continued learning stemmed from imaginative uses for my old, reliable Tandy 1000-HX. I thought of many ways to apply my experience with BASIC programming, while constantly trying to push beyond simple cartoon-like images on a screen.

Believe it or not, I also broke out of my shell around this time, and I even started DATING. This was a big deal, because, until then, I had been holding onto the misconception that being smart automatically made me unattractive. But then, I realized that almost everyone my age was dealing with their own fears about self-image, and that discovery was nothing short of empowering. I made many friends, and soon learned just how wrong I was about my appeal to women...which, oddly enough, leads me to my first attempt to control the world with my computer.

No, seriously! It is probably clear to you now that I have always been a creative person. So, drawing from that creativity, I was able to harness the light from the computer screen, sectioning it off to perform different functions. My goal was to write a computer program to activate and deactivate certain lights, amplifiers, and a fan, all perfectly timed to the super-romantic epic love ballad: Nirvana's Heart Shaped Box.

Yes: romantic... Leave me alone... We were depressing teenagers, and this song really spoke to us.

So I turned my parents' living room into a dance floor for two, I lit up the whole place with colour filters, and each light would be triggered by my program during specific parts of the song. The fan was queued to blow flower pedals over us during the part about angel's hair and baby's breath. It was truly a work of art, and my girlfriend thought so too :)

At the risk of sounding like a broken record, I must now remind you all that this was 1993. MP3 files were just being invented, and with my old computer, I didn't even have experience with WAV files, which were just invented 2 years before that, so synchronizing the music with my program was challenging to say the least.

Despite the success of this geeky project, it just wasn't enough. I wanted to learn more. I needed to find out how to integrate computers with external circuitry. I wanted a program that could "talk" directly to device's own circuitry. More importantly, I wanted to learn how to design and create my own circuits that would do whatever I wanted, so as not to rely on purchased devices that might only do SOME of my bidding. The idea of settling was just not acceptable. I tried figuring this stuff out by myself with some books from the library, but it was all out of my league. I needed help.

It was soon after this when I enrolled at DeVry, and I was scheduled to start immediately after my high school graduation. At the time, Devry was on its way to becoming a very credible school, but alas, it never did develop the good reputation it had in the United States. No big deal, though, because I learned a lot while I was there. I studied how to design and build both analog and digital circuits, I learned all about control systems, micro-controllers and step motors, and most importantly, I learned another programming language: C++.

Everything came together for me when I handed in my final project. I was clearly ambitious in my choice for what to build, which was a true representation of my nerdiness: a robotic arm that could play chess. My project adviser was convinced I was biting off more than I could chew, and despite his assertion that I wouldn't likely finish it, he allowed me to try. Well, he was right. There wasn't enough time for such a huge project, but he taught me a lot about time management, and I still got an A! Essentially, what I accomplished was the following:

  • the development of a sensor grid for my chess board, which made it possible to see which pieces are moved and where
  • a computer program that was able to track each piece, and know which it was, would know if it's a valid move or not
  • the robot's "hand" which used the aperture of a camera lens to enclose around the chess piece and pick it up
  • the computer function that on command would enclose, and then when I told it to would let go again

I didn't have time to build an actual arm for it, and as a result, didn't get to write the program to calculate the angles and move that arm in order to place the "hand" over the desired chess piece. Looking back, I'm quite impressed by how much I DID finish with such a tight deadline. At the time, I thought he was just being super nice, but my project adviser understood how much work went into it, and he especially appreciated how much I LEARNED from the attempt.

My experience with all of this was like a drug, making me desperate for my next fix. Every hit needed to be stronger than the one before it. I needed to learn more, and I needed to ACCOMPLISH more. This feeling would ultimately lead to the start of my career, which was unorthodox to say the least.

Thursday, 11 February 2016

Never Enough

PREVIOUSLY ON: "The Life of a Programmer"...

"I'm a socially inept 10-year-old with a love for Star Trek... I'm gonna teach myself how to write computer programs... Oh cute! I've created an entire video game using ASCII characters to resemble ships, rooms, and people! But wait. Is that it? I want to do MORE!"


*Sigh* I honestly felt that what I had created was pretty awesome for someone just finishing grade school, but my Star Trek game was still missing something. For months, I spent much of my time learning more functions, with the singular hope of figuring out how to make my programs DRAW on the screen. As it turned out, the concept itself eluded me during those first couple of programming years because of one problem: I had barely started learning about the Cartesian Plane in school, and therefore didn't quite grasp how to make use of it.

draw by numbersThere I was. It was still 1989, and I was no less socially awkward than when I started, so not surprisingly, I was kicking ass in math class. With every passing day, I would learn more and more about coordinates, equations, and the algebra used to make lines of various types. So inevitably, I went back to re-read that manual for BASIC programming, and as soon as I did, I began to understand more functions. Some actually dealt with creating a point on the screen, as well as things like the start and end coordinates for drawing a line, the centre point and radius for drawing a circle, and so much more. I was one step closer to achieving my dream of creating a video game with actual graphics! But how do I use these strange functions to my advantage? The answer came to me when I saw my friend's younger brother solving a "draw by numbers" puzzle. It made me realize that almost any picture can be drawn using a series of straight lines. So to keep things simple, that's exactly how I would create my masterpiece of gaming technology.

Immediately following this epiphany, I realized the next major hurdle: my complete and total lack of artistic talent. I couldn't draw if my life depended on it. Even my stick people looked weird. I needed another solution.

INTERMISSION: I feel it is once again necessary to point out that the Internet was still in diapers at this time. I couldn't simply go to Google Images or to find and download pictures of ships, planets or the crew. As before, I had to use my imagination to make this work.

Enterprise DNow, anyone who knows me can tell you just how much of a nerd I am (and always have been), so it shouldn't be a surprise that I was a member of the Star Trek fan club back then. With this membership I received many amazing perks, including a monthly magazine. Having about half a dozen issues by that time gave me plenty of pictures to trace, which is exactly what I proceeded to do. I searched them all looking for the perfect side view of the Enterprise D. After all, I needed it facing left or right if I were to make it "fly" across the screen. A local craft store in my home town sold me some onion skin paper, which made it easier to see through and trace when placed over any photo. It would also prove helpful in the next step of this time-consuming-but-totally-worth-it project.

Once I had finalized my facsimile of NCC-1701-D, I could already envision the series of straight lines that would make it possible, so I drew dots all over it to make them easier to see. My next challenge was to translate those dots into coordinates on my screen. I placed the drawing on top of a sheet of graph paper, thus showing all of them on a grid. This led me to figure out a scale. Through trial and error, I determined that my monitor had 320 pixels across and 200 pixels up and down.

FYI: by comparison, that would take up less than 5% of today's 1600x900 monitors. It wasn't much to work with, but I was determined to make it happen!

My starship could not take up the entire 320 pixels across, otherwise there would be no room for anything to happen in the game, so I decided to make it about 1/4 the size of the screen. To accomplish this, I simply went to the top left of the graph paper and marked it as (0,0). I then marked the very next grid line to the RIGHT of the ship as 80, with the line at the BOTTOM of the ship being somewhere around 40. Based on that , I counted the number of grid lines between the far left and far right lines, and divided that into 80, which told me how many pixels would be between each grid line. I of course had to do the same for the lines between the top and bottom, dividing that number into 40. Then the REAL fun began. *SARCASM ALERT*

OK. This next part was extremely monotonous, and it took forever, but was still totally worth it. For each series of lines, I had to approximate where each dot was on the graph, and write down the pair, while noting which coordinates were the beginning of a line, and which were the end. I then began the data entry portion of the project. I had to enter all of these numbers into my program as pairs of numbers in an array. This part took me the longest, understandably, because I had less interest in actually doing it. I also wasn't the incredibly fast typist that I am today.

Enterprise in ASCII ArtWith the boring segment out of the way, I could finally get back to business. It was time to make use of that awesome line-drawing function, which I added to a loop that would simply go through each set of coordinates in the array, completing a line and starting a new one when needed. I saved my program, and was super excited to watch the computer create each line until it completed an exact copy of my traced Enterprise D. It was BEAUTIFUL, but the pride I felt was short-lived. It occurred to me that, as amazing as this powerhouse of circuitry was, my computer was slow enough to be a problem. The fact that I was watching it SLOWLY draw the ship meant that I couldn't instantly make it redraw the ship two pixels away to give it the illusion of movement. That's how I did it in my old ASCII Art based game, but it was apparent that I needed to rethink that part.

So once again, I went back to consult the programming guide. This time, I had no idea what I was even looking for. I just hoped that I would find a solution. I double and triple checked over any function that I hadn't really used or even tried thus far. The answer was found in two of them: PUT and GET. Yes, I actually know what they were called. I distinctly remember the descriptions of these two commands originally being very confusing. When I had first read these pages, I had no idea how I would ever use them, so I immediately ignored it all. This time, however, I had an "A-ha" moment. GET would store the contents of a rectangle that I would define myself, consisting of everything from its top-left to its bottom-right coordinates. PUT would INSTANTLY place that image anywhere on the screen. Yes, instantly. My ship could move!

Romulan WarbirdFinally! The hard part was over. All I had left to do was...the exact same process for pictures of asteroids, Romulan warbirds, the Enterprise Bridge, and a Borg cube, make the ships "fly" by making random pixels (stars) move across the screen, actually break up the ship into pieces so that the stars that were flying past wouldn't disappear behind the huge rectangle that I used with the PUT command (a consequence of the command itself), make it possible to "steer" the Enterprise with the up and down arrows on the keyboard, make it possible to turn on shields, shoot phasers, fire torpedoes, and, oh ya, show each level and scene to progress the game. Borg CubeNothing much. As it turned out, I couldn't find a decent picture of the Borg cube, which was CRITICAL to my game's plot. I was rescued by my older sister, Yvonne. Being quite the talented artist, she agreed to draw one for me, and it looked really impressive. It was the one aspect of my game that looked cool BECAUSE OF (not despite) my monochrome monitor. It's green glow was just PERFECT.

All of this took me another year or so. I had a true passion for programming, and was rarely torn away from it by things like a pesky social life. But don't worry; I eventually broke out of my shell and shed my social awkwardness sometime in 1991.

In the meantime, however, my masterpiece was still evolving. When I hit grade 10, our school had a Computer Science class, which I OBVIOUSLY joined. EVERYTHING taught in that course was stuff I already knew, so naturally I spent the time tweaking my video game. The computers they provided contained 80386 processors. Despite their maximum speed being 40MHz (which is actually 1/256 the speed of my current PHONE), it was still 8 times faster than my old Tandy. So my next challenge was to slow the game down a bit, otherwise the asteroids would fly by so quickly, you would have no time to react, the ship would be destroyed, and you would immediately lose the game. This was a small price to pay, and I took the extra time to make it work on them, because these machines had (wait for it) COLOUR MONITORS! That's right folks. With a few edits, my phasers and torpedoes would be RED! My asteroids would be BROWN! I all of a sudden had 16 distinct colours in my arsenal, and I was determined to use them.

So in the end, I was quite impressed with myself. The game started with a scene on the Bridge, where the Captain gave his famous Captain's Log to describe how the mission would start in an asteroid field. Then Level 1 would load, and the player had to navigate past or shoot the asteroids without getting destroyed. The next scene indicated that you made it to a planet, where you had to beam up a Romulan defector/scientist, who would give you further instructions... AFTER you escaped through the asteroid field again, but this time with Romulan warbirds chasing and shooting at you. That's Level 2.The next scene involved the defector explaining that the Borg were nearby, and needed to be stopped... And only she knew how. So a course is set, and you encounter the Borg cube, to which Riker transports over in order to destroy it. The Borg drones resist, so Level 3 involves getting past them to blow up the critical console described by the defector. If you make it this far, and manage to destroy it, you are beamed away, the Cube blows up, and you win the game!

It was accomplishments like this that made me think I knew it all. But as computers continued to evolve, so did programming. Soon I would discover that BASIC was becoming an extinct language (it wouldn't be the first), and I would need to get with the times. I would also spend the next few years pining over my new obsession: writing computer programs that could control THINGS. I wanted to figure out how to use my knowledge of code to affect the real world, instead of just pixels on a screen.

Hmmm... I'm starting to think that the word "obsession" isn't strong enough...

to be continued (again)

Tuesday, 15 December 2015

Memory, Monochrome and Magic - The Early Years

fancy letter I n this day and age, many of you are under the impression that computers are evolving at a mind-boggling rate, but really, you have no idea. Back in my day (I'm old, so I can say that), new types of computers were being created DAILY. It was 1985, and I was only 10 years old, which was an exciting time, as companies all raced to be the best. Amazingly, and sadly, the computers they sold were obsolete the SECOND they hit the shelves. At that time, places like Radio Shack were offering the latest and greatest, and it was there that my parents purchased my first PC. Today's post is all about my experience with that wonderful machine: The Tandy 1000-HX.
The Tandy 1000-HX "How many Gigs of RAM did it have?"

It didn't.

"OK. How many MEGS of RAM did it have?"

It didn't.

No, my hopefully-sympathetic readers, it had Kilobytes of RAM. To be more precise, it had a whopping 256KB of memory. By today's standards, that is enough memory to store about 7% of the average MP3, which MIGHT even cut out before the first chorus. Believe it or not, this was impressive for that particular week. Like I said, computers were getting better at an insane rate, and anything purchased the week after was INFINITELY better than mine. I mean, they even had HARD DRIVES, whereas mine came with a 3.5" floppy drive. That's it. Oh, and my monitor had TWO colours: black and green. These were the days of monochrome monitors, and it was a very scary time, indeed.

It came with a couple of games, which had to be run from the floppy disks, but I showed very little excitement over those. My interest was peaked when I saw a book that arrived with it. I scanned the title: BASIC Programming User's Guide and Glossary.

I was intrigued! I was mesmerized! What did it MEAN? Was this book the secret to creating my own computer programs?  I was determined to find out. I read it from beginning to end. I was fascinated by the description of these WORDS that had the power to manipulate text in any way I wanted. As I tested out more and more of the topics, I figured out how to make everything on the screen do my bidding. It was like magic. 

Now remember, boys and girls: the Internet was at its infancy back then, and the very first domains were being created and registered that very year. I couldn't do a quick Google search and find out how to do all of this. I had to figure it all out by myself. And yes, I really was only 10 years old. I was a shy kid, with only a few friends. I spent most of my spare time on this supernatural contraption, and as I learned more about programming, I would also learn just how much I DIDN'T know about programming. This made me crave more. I kept at it, creating increasingly more complex code. I could make text do whatever I wanted, and it wasn't before long that I created what I thought was an impressive video game, using what would eventually be called Text or ASCII Art.
Starship Enterprise in ASCII Art

Spock in ASCII Art At this time, it was 1989, and I was just finishing grade 8. A few years had passed since I received that first computer, and given that we weren't a wealthy family, I was still using the same one. This game that I created was naturally based on one of my true loves: Star Trek. It was even more exciting to me, because their new series, Star Trek: The Next Generation, was well into its second season, and I just HAD TO make my game about that. This masterpiece of mine used keyboard characters to "draw" the main bridge of the Enterprise, ships in space, and even crew members. 

Donkey Kong on the Atari 7800 Yes, the people I created for this game looked quite silly, but back then imagination was a true necessity. People were still buying games on the Atari 7800, and its tiny, pixelated characters required plenty of imagination, therefore, in my humble opinion, my characters were just as good. So my game took the player through a story that involved ships shooting at each other, "scenes" on the main bridge, and even the Away Team beaming down. Yes folks, I was rather impressed with myself.

But something was missing. I wanted TRUE graphics. I wanted to actually DRAW on the computer, and I wanted those drawings to come to life in a video game. As before, Star Trek: TNG would be my inspiration, but it would take another year before this dream was realized.

to be continued

- Dan Peltier