In my last post, I talked about some of the things about being an “Aspie” that can be depressing.  In this one, I want to talk about one of the things that’s awesome about it– and that is the enjoyment I get out of doing something related to my “special interest.”

The past couple of weeks, I’ve been working on writing some code in Javascript for my football Web site that will generate a graphical record of every drive in a football game from a set of numbers and names.

For example, the code will create this image…

… if you enter this data:

[[“kick”, 30, “S.Hauschka”], “pit”, 14, “G.Russell”, 34, 84, 7, “3:38”, [“FG”, 34, “good”, “J.Reed”]]

The image represents a kickoff from the Baltimore 30 to the Pittsburgh 14, returned to the Pittsburgh 34.  Pittsburgh drives 50 yards in 7 plays to the Baltimore 16 using 3:38 on the game clock.  Finally, Pittsburgh tries a 34-yard field goal, which is good.

All of the data comes from the list of numbers and names.  (In case you’re wondering, the player names would show up in info boxes when you move your mouse pointer over one of the lines in the image; I didn’t demonstrate that in this example.)

There are typically 25-35 drives in a football game.  If I tried to make images like the one above manually, I could do it, but it would take me days to create the image for a single game, and I’d never be able to keep up with all the games I’d like to cover for my site.  But if I can use Javascript to generate the image automatically, all I will need are the numbers and names.

Figuring out how to write the Javascript to do this is like solving a gigantic logic puzzle.  You have to think about everything that can possibly happen in a football game.  For instance, it’s possible for a drive to go backwards if the team loses yardage.  It’s also possible for a kickoff return to go backwards.  Punts and kicks can only go forwards.  I had come up with three different kinds of lines to represent drives, returns, and kicks, and I needed to figure out all of the possible ways they could overlap:

The script builds the image for each drive by connecting lots of little pieces in the right order.  For example, the 50-yard drive above is made out of one “beginning” image:  

48 “middle” images: 

and one “end” image: 

The script needs to be able to calculate how many little images to connect based on the “beginning” and “end” yard line values the user inputs, and it needs to figure out which way the arrow should point based on whether the team that is driving is the home or away team.

One of the most complicated puzzles was figuring out how to tell the script when to use this piece: 
It’s probably hard to tell what that is by itself, but it’s used whenever the line for a return overlaps the line for the drive and extends beyond it, like this:


This could happen if a team has a return of 9 yards followed by a drive of -10 yards, or if a team has a return of -9 yards followed by a drive of 10 yards.

Most of the time, this won’t happen, but it does happen sometimes, and the script needs to allow for it.  The only input the script has to work with is the yard line the return began at (A), the yard line where the return ended and the drive began (B), and the yard line the drive ended at (C).

I had to make some sketches to figure it out, but I found that there were two situations that would require the use of this overlap piece:

1.  If C is greater than or equal to A, -and- B is greater than C:


2.  If A is greater than or equal to C, -and- B is less than C:


I don’t know if I have explained this in a way that makes sense, but it is so much fun to figure out puzzles like this.  This is one reason why I think I might finally be on the right track in looking for a career– the things I am learning about in class bring me a lot of enjoyment rather than just being a source of stress.

Well, I’m going to get back to writing Javascript!

In my last post, I talked about some of the things about being an “Aspie” that can be

depressing.  In this one, I want to talk about one of the things that’s awesome about it–

and that is the enjoyment I get out of doing something related to my “special interest.”

The past couple of weeks, I’ve been working on writing some code in Javascript for my

football Web site that will generate a graphical record of every drive in a football game

from a set of numbers and names.

For example, the code will create this image…

[image]

… if you enter this data:

[[“kick”, 30, “S.Hauschka”], “pit”, 14, “G.Russell”, 34, 84, 7, “3:38”, [“FG”, 34, “good”,

“J.Reed”]]

The image represents a kickoff from the Baltimore 30 to the Pittsburgh 14, returned to the

Pittsburgh 34.  Pittsburgh drives 50 yards in 7 plays to the Baltimore 16 using 3:38 on the

game clock.  Finally, Pittsburgh tries a 34-yard field goal, which is good.

All of the data comes from the list of numbers and names.  (In case you’re wondering, the

player names would show up in info boxes when you move your mouse pointer over one of the

lines in the image; I didn’t demonstrate that in this example.)

There are typically 25-35 drives in a football game.  If I tried to make images like the one

above manually, I could do it, but it would take me days to create the image for a single

game, and I’d never be able to keep up with all the games I’d like to cover for my site.  But

if I can use Javascript to generate the image automatically, all I will need are the numbers

and names.

Figuring out how to write the Javascript to do this is like a gigantic logic puzzle.  You

have to think about everything that can possibly happen in a football game.  For instance,

it’s possible for a drive to go backwards if the team loses yardage.  It’s also possible for

a kickoff return to go backwards.  Punts and kicks can only go forwards.  I had come up with

three different kinds of lines to represent drives, returns, and kicks, and I needed to

figure out all of the possible ways they could overlap:

The script builds the image for each drive by connecting lots of little pieces in the right

order.  For example, the 50-yard drive above is made out of one “beginning” image:

48 “middle” images:

and one “end” image.

The script needs to be able to calculate how many little images to connect based on the

“beginning” and “end” yard line values the user inputs, and it needs to figure out which way

the arrow should point based on whether the team that is driving is the home or away team.

One of the most complicated puzzles was figuring out how to tell the script when to use this

piece:

It’s probably hard to tell what that is by itself, but it’s used whenever the line for a return overlaps the line for the drive and extends beyond it, like this:

This could happen if a team has a return of 9 yards followed by a drive of -10 yards, or if a team has a return of -9 yards followed by a drive of 10 yards.

Most of the time, this won’t happen, but it does happen sometimes, and the script needs to allow for it.  The only input the script has to work with is the yard line the return began at (A), the yard line where the return ended and the drive began (B), and the yard line the drive ended at (C).

I had to make some sketches to figure it out, but I found that there were two situations that would require the use of this overlap piece:

1.  If C is greater than or equal to A, -and- B is greater than C:

2.  If A is greater than or equal to C, -and- B is less than C:

I don’t know if I have explained this in a way that makes sense, but it is so much fun to figure out puzzles like this.  This is one reason why I think I might finally be on the right track in looking for a career– the things I am learning about in class bring me a lot of enjoyment rather than just being a source of stress.

Well, I’m going to get back to writing Javascript!

Advertisements