(on the donkey)

The autobiography of Rand Barnett

© 2018-2019 Charles Rand Barnett
All Rights Reserved

I'm working on getting my book in Kindle form. Here is an excerpt:


I played jazz trombone in the US Navy for 7 years during the 90's. While I was in the Navy, I studied drums, slap bass, and piano. I also got up to speed with computers and hard disc recording. Right after Y2K, I left the Navy to move back to the west coast to make solo music recordings and websites. You can hear the music I was making at that time by going to the music page and clicking on the "Vintage" button.

Between 2000 and 2003, I got involved in a couple dead end and unreasonable jobs. I was living in cars/vans and couch surfing during that time. This story picks up in the summer of 2003...


I walked around for a week without shoes. My feet were a mess. One day I was walking up in the park by the museum on Capitol Hill. I got a sliver in my foot and I was walking funny on a path. There was this guy that looked exactly like the Dalai Lama and he offered me some tweezers. Nice, that did help and it was a cool experience to have. Tweezers are nice if you have them, but I've never felt like they are an essential and still don't. Toe nail clippers with a pointy file are an essential though. Yes, you can just bite your nails, but I fixed that habit in my 20's sometime. Ann taught me how to manicure my cuticles. I did keep my fingernails nice on the streets and brushed and flossed every day.

I was terrible at panhandling. I never made more than a couple bucks in a year doing that. It started getting cold in October. I was playing my pennywhistle on the streets with a hat out. I did manage to make $60 in two weeks doing that. I told people I was saving up to buy a trombone. Just mainly playing the melodies to jazz standards. Twelve tone pennywhistle. It eventually got too cold to play like that. The cold wind was really whipping through downtown. I was freezing and not prepared for that cold.

I wound up at Adriana's for November and December. I slept on the living room floor and worked full days on my programming. I became obsessed with the idea of making a game like Atari's Centipede where you could move all over the screen instead of being stuck in the bottom part of the screen. And shoot in all directions. Flash had the hitTest() function and people were making games with that. But hitTest() is very limited. It just tells you if one object is on top of the other. It gives you no information about where the collision happened. And if you are going fast enough, you may just skip over the object entirely. No, hitTest was not good enough to make a proper game. What I wanted was real collision detection.

Around Christmas time of 2003, I was obsessed with making collision detection. If I was going to get a job programming, I would have to do some big project like this. I had been answering ads on Craigslist. I almost got a job that month coding a lens flare, but I didn't get the gig. I was using math, ratios specifically. I had made a demo of this that kind of worked. About this time, I think it was New Year's Eve, Adriana kicked me out. So I grabbed my sleeping bag and a briefcase for my paper work and went to Dan's on the other side of the fence. I used Dan's phone to call my lifelong friend Sam. Sam said that I could stay with him, but I'd have to wait a few days to get a bus ticket; they were all full because of the holiday. Dan said that I could stay with him until I could get a ticket. OK, I had a plan.

So I sat down at his kitchen table with my paperwork. I was really close to proving whether this collision detection with ratios could be done. And then Dan just keeps talking to me. I told him repetitively to leave me alone, I had work to do, but he wouldn't shut up. I just couldn't take it, so I left. I went up to the store, it was dark by this time and I worked out my math on paper on the picnic table until I had proven it. And I did, my math said that I can make this collision detection using only ratios. Pretty groovy. So then I started out the long walk to Seattle in the slushy snow with my sleeping bag and briefcase.

A cop stopped me on the way out of Snohomish and asked me what I was doing. I was excited because of the math and I said “I'm going down to Seattle to live on the streets and make a video game.” He said “Sounds great, just make sure you keep going because you can't stay here!” Nice.


It was cold and snowy, but I had lots of clothes on, a thick jacket, a scarf and a sleeping bag. I had my briefcase with my essentials including two lightsabers (pennywhistles, green and blue) and a slinky. The briefcase was one of the thicker ones so I could hold a lot of stuff. I used the briefcase as a pillow and kept my hand on the handle when I slept because I didn't want anyone to take it from me. I usually slept petty good on the streets unless it was really cold out. On those days you just shiver until 3am and then walk to keep warm. I went to the library when it was open. It was quite a hike from the library to the store and I couldn't carry much food with me, so it was pretty much a daily trip. The store was by the Space Needle and the library was downtown. It was the old library, they were almost done building the new one.

I spent a few weeks working out the collision detection on paper. I was getting frustrated because it was a lot of math. I was feeling like there had to be an easier way. I had taken trigonometry in college, so I decided that it was time to brush up on my trig. So I go to the math section. This is kind of the best kept secret of Seattle, but here it is. In the math section there was a small green trigonometry book with a canvas cover called Plane Trigonometry and right next to it there was a slightly larger blue book with a canvas cover on Calculus. I read the first page of the Calculus book. It said that the main point of Calculus was to determine the area of an odd shape by methods of exhaustion. Well, I have no need for that in my video game of course. I knew I was after the trig book, but that did look like a good calculus book.

So there I was up in the middle of the night on the sidewalk studying trigonometry. Trig is a little tricky in the beginning. I think I got a C in it in college. I certainly didn't retain it. The green book was good. I didn't have a calculator, so I used the tables in the back of the book. I realized that the numbers .5, .522 and .707 were important. I was trying so hard to “get my bearings straight” about those numbers. I was dreaming about them. I was playing the mad scientist role on the streets. Then I finally got it! I woke up in the middle of the night and said “.522 is the circumference measure around the circle to 30 degrees and .5 is the sine of 30 degrees!” I get it! .707 is th length of the line if you go straight up to 45 degrees, the sine OR cosine of 45 degrees. .866 is the sine of 60 degrees, which is the lenth of the line straight up to 60 degrees. So there it is. That's called getting your bearings straight.

PI is the circumference measure around the circle. Like wrapping a radius around the outside edge of the circle. There are 3.14 radius wrapped around the circle in a half circle. Since half the circle is 180 degrees, a third of the way around the circle is 60 degrees. So 60 degrees is just slightly more than one radius wrapped around the circle. All these numbers, .5, .522, .707, .866 and PI are of a radius. 3.1418 radius, .5 or half of the radius of the circle. They call it radians. .5 radians. 3.1418 radians. PI radians.

Standard position is an important term and part of getting your bearings straight too. Zero degrees is out to the right, at 3 o'clock. 90 degrees is straight up or 12 o'clock. 180 degrees is to the left and 270 degrees is straight down. Negative 90 degrees is straight down as well and so on and so forth. And then there are quadrants. If you draw a circle in a square, the upper right is quadrant one, the upper left is quadrant 2, the lower left is quadrant 3 and the lower right is quadrant 4. Quadrants really don't matter, but it can be a helpful concept.

It took about 2 weeks, but then I knew trig. Instead of going back to the collision detection, I got interested in mapping 3d space. I wanted to make a webpage slinky with Flash.

I had a slinky with me. I spent a lot of time looking at it and thinking about how to turn it into a mathematical equation with trig. It's a circle. Trig is about circles. But trig is also about triangles. 3 points always make a perfect plane. Plane Trigonometry. I thought, OK, you need to map the slinky coordinates and then you need to view it from a camera or point of view. The camera has coordinates and viewing angles. OK, so mapping out the coordinates of the slinky.

If you are looking at it from above, it looks completely round. I always call height or elevation the z variable and x/y as the “map coordinates”. On a planet, with a sky and ground, you have North and South, East and West. X is East and West, Y is North and South. Zero on Y is the equator or wherever we want center to be. And you know, zero on X is just where we want center to be, a longitude line. OK, that might not be textbook correct, but it makes sense to me.

Looking at the slinky from above, going around the circle we have points along the circle. Dots. Perfect, I'd been using dots in my musical weirdness for years. I'll make it with dots! So you use trig to plot the x/y position around the slinky. It is more than one rotation, it keeps on going round and round, but the x/y for each dot is the same for different heights going around the slinky. For every dot around the slinky, the z becomes a little bit less.

OK, well, you get the idea. I went to Adriana's and coded the slinky easily. I put it on my Tubespace website and went back to the streets. I was feeling pretty good. It was starting to get warmer out and I was making good progress with math. I made some other dot objects and then got back to the business of collision detection.

Collision Detection

I was going through a lot of notebook paper. I would buy the loose leaf paper packs of 150 sheets for about $1.50. I just had one pen. It wasn't hard to not lose my pen, I Just had it in my briefcase. I would go to Adriana's every month or so to enter my work into the computer to see if it actually worked. I would spend about 2 days there. I'd do my laundry and take a shower. I'd do some cleaning in the apartment and she would give me $5 that I would use to buy paper and a bus ride back to Seattle. It was the only shower and cleaning that I got.

Sometimes I would wake up on the streets to find a couple twenty dollar bills next to me. Those were great days. I'd go to the little deli a couple blocks from where I was sleeping and get an egg salad sandwich and Henry Weinhard's root beer. Man was that good. It cost about $5 to get that. Most of the time I'd buy two of each. The first day the food stamp money came in I usually did that too, but I had to be really carful to limit that to just once a month. But that is about the best thing you can do for a homeless person. Just lay some money next to them while they are sleeping.

This is the part of the story where Rick comes in. He was a gay guy who offered me a shower a few times. I had several gay experiences in the previous two years. I don't identify with being gay, so at this point I was getting a little tired of it. But the reality is that it is quite possible that Rick was THE ONLY person who was nice to me while I was on the streets. He was likely the guy putting the occasional $20 bill next to me while I was sleeping. He was trying to help me and he was not overtly sexual with me. So anyway, thank you Rick! I'm sorry I was so hard to deal with back then.

So, back to the math. I could now use the trig in my collision detection. Nice! The idea is that we have two rectangles: Us and Them let's call them (I'm a big Dark Side of the Moon fan). If we are to the left of them, then we can only hit their left side.

If we are to the left and below them, we can hit their left side OR their bottom side.

I spent quite a lot of time drawing pictures like these to figure all this out. You see, when you code this, you have to figure it out from any direction. I was using a lot of conditional logic (if/else) in my code. Really, the code was very simple; it was mostly math. Let's use this last image as our base to explain this. We take the top side of US and the bottom side of THEM and call that side “a”. Little a. Big A is angle A and little a is the side opposite of it. All we know is the current position of US and THEM along with their dimensions and the direction we are going (the angle) and our velocity (our speed). From this information we know side “a” if we are below them. From this information, we can calculate side “c” by using the cosecant (reciprocal sine) of angle A times side a. That looks like this:

So great, that was easy and now we know side c. If side c is greater than our velocity, then we have not hit it. If side c is less than our velocity, then we have hit it. I call this “hit or shit!” In fact I use this terminology all over my programming for Boolean (true or false) variables (conditional logic). Hit is true, shit is false. If(hit){} else{}

So, if we didn't hit, then we loop over all the other objects and if none of them are a hit, then we just move and call it good. If it is a hit, then we need more information to see if it is really a hit. We need to know exactly where it hit and to get that information; we need side “b”. We use the side “c” to get side “b”. It is simply b = cos(A) * c.

Using sides a and b, we can now determine where we hit. We'll have to take into account the width of our rectangle which requires more math, but it is all known now. And then we have to work all that out for all the ways we can hit it from different quadrants. It takes some effort to make a computer program with all of that. Trig did make it a lot easier than using ratios though. I'm still convinced that I could have just used ratios.

Then comes “the slide.” Leave it to a trombone player to code a collision detection on the streets that slides! What you do after a collision is important. If we hit it like in this last diagram, then we are sliding to the right, straight to the right. If we hit something, it has to be their left side which simplifies the math. If we make it to the end when sliding and did not hit something, then we are back to moving in our original direction with whatever is left of our velocity. At that point we just start the whole thing over with our reduced velocity. And we keep on looping until we are either totally blocked, by sliding to the right and hitting something, or all our velocity is used up.

One day I got pulled into a long, long line of other homeless people. They were all standing in line at about 3:30 in the afternoon. I assume it was for some soup kitchen or something. I stood there for about 20 minutes. Then it was just like, look, wherever this line leads it is going to be hard to do my work, I'm going back to the library or park bench or at least the sidewalk where I can concentrate. I know I was the exception to the rule. You're probably correct in thinking that homeless people are doing drugs and I had certainly done some drugs in my life. I was completely clean and sober on the streets though. I define sobriety as “giving up the party” and being clean as simply not using. With those definitions I became sober in about 2002. Maybe I was lucky; I had always put working over drugs and made it a point to not hunt down drug dealers. If drugs found their way to me, I was down for trying them, but I'm not going to spend my time trying to find them. That definitely worked well for me over the years. I was primarily homeless because I was an anti-social musician. Musicians need a lot of connections to get gigs. I'm just not good at that. I had hoped to get out of the Navy and be a music teacher, but without a degree and a place to live, that was impossible. Jobs that I got didn't work out. You know, I could have found work, but it takes time to study and that is work too. I wasn't standing still, not in despair. Not blaming anyone for my situation, just on with the business of educating myself in hopes that I'll get into a profession that can support the way I want to live.

I also did the circle/circle collision detection needed to make a pool game. The math is a little more complicated there using arc tangent 2 and the law of sines and cosines. I think I used the law of cosines to do it. It involves solving the ambiguous case. I haven't done it in while and want to get back into it. I also coded a circle/rectangle and rectangle/circle collision detection. That was complicated and basically a waste of time, but it was a challenge and if you need it, you need it. I didn't need it, but I did eventually finish it. I've never used it or really tested it though.

Rebounding is something you can do instead of sliding. The math for that is fun. I do that with circle/circle. I have it coded into the rectangle/rectangle too.

I was thinking a lot about robotics, specifically making a robot barista. Feeding in a cad drawing of the building. The robot is behind the counter so there is no potential of things being around that it doesn't know about. The angles of the arms. The image detection algorithms. Using a special color code on the cups that tells it what size they are. Something easy to pick out in the images. You know, math!

By the end of the spring of 2004, I was a mad scientist on the streets doing a ton of math on paper, but my health was beginning to suffer. The lack of showers combined with the high sugar/oil diet was causing a crotch rot condition. I went to hospitals, but no one was too eager to help me. I did get some suppositories. Kind of a waxy substance. I remember going to an AA meeting (I was convinced I was a dry drunk because of AA crap) and putting one of these suppositories in. Temporary, minor relief. About a week before the 4th of July, it was unbearable. It was all I could do to walk to Marc's place in West Seattle. Marc then drove me to my brother's place in Olympia. Then my brother drove me to Portland. I was rolling around in agonizing pain in the back seat of his car. I think he was taking me to Sam's place. By the time we got to Portland, the pain had subsided. I don't remember him taking me to Sam's but that was probably what happened. Sam was not there, so I was just on the streets of Portland then.

I was a mess. I had my paperwork with me, but work was the last thing on my mind. I wound up walking to Marge's mother's place through the park. She wasn't there, but I waited for her. She showed up in about an hour and let me in. I talked with her a bit. She let me take a shower and gave me some clean clothes. I left my pants on her bathroom floor. I had been wearing black dress pants that had a tight corduroy weave. I always loved those pants. I got them when I was in the Navy. Then she gave me $20 and dropped me off in front of the Portland Rescue Mission. I took that $20 and went to a normal pub and got a 16oz beer and a nice big sandwich. I had been working so hard and just wanted a normal life again.

I waited a few days for Sam to show up. I was feeling a little bit better. I had never lived on the streets of Portland before. I didn't like the idea of being homeless in Portland for some reason. I was sleeping in the bushes near Sam's place just across the river in Vancouver. It turns out that Sam and his family was out of town for the 4th of July. He showed up a couple days later.

Sam said I could stay with him in his basement. That was the plan all along before I did the 6 months of math, but that math changed my life. Glad I did that. What a story!

Sam had some old computers and we were geeking out with computer stuff. We recorded some music using the Reason 1 software. And then I coded my two player, Asteroids type game, Bumper Bubbles in 4 hours.

I used the music I had made for it. The math was the circle/circle collision detection. Instead of copying it from my papers, I just coded it from scratch. I was a trig master by this point. Sam and I were playing Bumper Bubbles in no time.

I stayed with Sam for about a month and a half. Then he finally got me to seek help at the VA.

Off the Streets

I didn't think I had any benefits from the Navy, but it turns out that because I had at least one honorable discharge, I do get some healthcare benefits. The VA tracked down this information and then admitted me to 5C, the mental health hospital in Portland up on Pill Hill. I didn't want to go there. I felt that all I really need was a place to live and a job opportunity. But the other option was going back on the streets. It was a pretty tough decision for me. I chose the VA and they put me in there with the magnetically sealed door. You don't get out until they let you out.

I had all this newly found math running around my head. I was basically creating a 3d gaming engine from scratch on the streets. I would close my eyes and see all the angles and the equations. I asked for paper and pen. They gave it to me so I was like, groovy, back to work. I had a roof over my head and they were bringing me meals. I went to work on my collision detection. I had it all worked out, just need to make a final copy of it.

I was writing with a pen all this time. I don't like the wood feel of the pencils. That dry wood on my skin sends shivers up my spine. You can't erase a pen though. So a page was only complete if it had no mistakes on it. Maybe one or two characters crossed out, but if it was more than that, I would continue on making sure it was all correct and then copy it to a fresh page error free. I was going through a lot of paper and they were pretty much comfortable giving me more paper. I had a desk by the window. There was a morning group where they talked about the plan of the day or whatever. There was an art therapy class. Whatever.

One day while I was writing at my desk, a doctor popped in to look at what I was doing. I explained the whole thing to him and showed him my equations. He asked why I was using if, ifelse, else instead of a switch statement. I had heard of switch statements before, but I had never used one. If/elseif/else does the job. At the end of all my equations was the computer code that moves the "brick" and there is the code that does the loops that you feed the "bricks" into. I'm always more concerned about the business logic of a program rather than the methods of a programming language. But the doctor knew what I was doing and that it made sense. I've heard of stories before about crazy people writing math that doesn't make sense. No, I definitely knew what I was doing and they figured that out.

Some people met with me to form a plan of discharge. Jenn and Amy were assigned to me. They said that because I was living on the streets for a year, I qualified for a HUD program through Central City Concern that would get me my own one bedroom apartment. The problem was that I had lived with Adriana for 2 months in the middle. It had to be a consecutive year. But I was living in a vehicle for 3 years before that. I certainly did qualify as chronically homeless, didn't I?

I was willing to go back on the streets and do my math. They ultimately accepted me into that program. I spent 5 weeks up on 5C. I had my collision detection pretty much completed and they let me out.

Fast forward to 2012 for the linear algebra collision detection.

In the beginning of 2012, Patty Bear moved in with me. Patty was a friend of Ena's mom. She needed a place to stay. Her life had become a train wreck. She called herself a drowned rat. She was just about 60 years old and a life-long alcoholic. Her drug of choice was two 40oz beers. Honestly, she was knocking on deaths door when she moved in. People didn't like her when she drank and I was no exception. She wasn't violent, but she could be obnoxious.

I got to know her and fell in love with her. She began drinking less and less. She's actually quite wonderful when she isn't drunk. She encouraged me to do my music thing, so I started recording more. In the spring of 2012, work was slow at DHX and my freelance clients wanted me back. So I started working from home again.

We got into a happy little groove there. I met Warren online. He draws mazes which is a good counterpart to collision detection. I Googled “The intersection of two lines” to find the math to do a linear algebra collision detection that would work at any angle. I built that up into Maze-ing Earth. There was a bug in it initially where the ball would sometimes stick to a point. I eventually found that there was an incorrect pocket of code and then it became 100%. I started running my own servers so that I could ping them 12 times a second so that you could have multiple people in the maze at the same time so you could race each other. I wound up spending 300 hours on that project. It doesn't look professional, but it is kind of cool. We're still working on making it better.

Many years later...

Collision Detection Part 2

OK, well, let's talk about the collision detection going on in Maze-ing Earth here. I was spot on Googling for “The intersection of two lines.” I had been coming to that idea for years and then it finally just dawned on me that the intersection of two lines is what I needed and then I was quickly in business. Here is my Collision Detection page. Down at the bottom is the intersection of two lines. It looks like this:

The linear algebra I found on the internet was called “slope intersect form.” This example simply makes the lines red if they are intersecting. I also made the equation return where the intersection is if it is intersecting. I realized that with this equation, I can now make a pinball game. Before I became a programmer, I thought one measure of being a good programmer was to be able to code a pinball game from scratch. Well, this is it. I was finally able to do it. This is how it works...

The pinball is round, but the linear algebra collsion detection only works with straight lines. So the simplest way to make the ball is to use a pentagon.

Again, let's say that US is the one in the upper left and THEM is the one in the lower right. We are moving in a direction (angle) at a certain speed (velocity or "v"). Lines have a starting point and an ending point. The pentagon is made from five points. What we do is draw an imaginary line from each point of US at the angle we are moving in and the length of the velocity and then see if that imaginary line intersects with any of the lines of the THEM pentagon. The interesting thing here is that the lines of US cannot intersect with the lines of THEM. Think about it. Any way you try to draw one of the lines of US intersecting with a line of THEM is going to involve one of our points.

If one of our imaginary lines intersects with one of their lines, then we have hit it. But, we also have to detect collisions by drawing imaginary lines from the points on THEM to the lines on US.

To do this, we need to add 180 degrees to the angle. Then the programming logic is the same as for any collision detection. If any of them intersect, we find the closest intersecting one and then move that distance. I have also coded a slide into this collision detection. If we have a collision, then we are sliding along the line we collided with in the angle of that line we collided with. That sounds complicated and I'm sure it took some work to make that slide happen, but the slide is crucial.

Anyway. I find it interesting that we are always detecting points intersecting with lines. Now that we have this collision detection that works at any angle, we can make an elaborate maze or pinball game using lots of straight lines to make curves. For a pinball machine, we simply apply a force of gravity pulling down a little bit each frame we render. Again, I spent about 300 hours making Maze-ing Earth with this. 300 hours in my spare time. It was actually quite a bit of work. We have it working on mobile devices. You tilt the device and the ball moves around the maze. It's pretty cool. We don't have this on the stores. Truthfully, it isn't that fun from a game perspective. Phones are a little small to display a whole playable maze and when you are zoomed in and playing, you are just kind of aimlessly moving around. We have a Flash computer version (Flash is now dead :() where you just drag the ball around with your mouse. It's an older version of it and still has a bug in it that makes the ball stick to points once in a while. And then I've coded the maze part into Unity to make it 3D. That was just a quick experiemnt. The real Maze-ing Earth experience is the mobile version which we don't have available at the moment. Like I said, it would take another round of work to really make it fun and I just don't have the time/money to invest another round of work into it. Maybe someday.

2020-11-10 I ported this collision detection to javascript a couple years ago. If you want to see it in action, go to the collision-detection page. I also did end up making my Micropede game with it. After I got off the streets, I got interested in server programming with PHP and shelved the collision detection for a few years. I made the Micropede game around 2009. I hired 3 different artists to do about $1,000 work on it, but I wasn't too happy with the results that I got. It still has an unpolished vibe about it, but there is some magic to it! You can download that on the products page.

Go to my Log page to read what I'm doing now.