Week 9 & 10: More Project Work

The project phase of term is in full flow at this stage. While this is an exciting time for everyone, it does make it a little difficult to summarise what they're all up to. This is a lovely problem to have though, caused as it is by everyone doing something interesting, and all moving forward at their own pace.

This is what we really hoped to achieve when we founded the Academy of Code, and to see such exciting results in our first full term is incredibly heartening. Not that every student is equally as brilliant as each other - that simply wouldn't be a sensible yardstick - but that every one of them moves at the top end of whatever their own pace is, and that they are constantly being challenged, overcoming that challenge, and then being challenged again.

Over the past two weeks one of the major features being added by many students was collision detection, in most cases between circles. (Detecting collisions between rectangles involves a lot more steps, so most students were encouraged to stick to the circles. A few brave souls did implement the rectangle collision detecting though - and mostly with reasonably solid results!) 

The images above show how we go about detecting a collision. The distance from a circle to its edge is half its width (this is also called the "radius", for those of you who slept through maths class!). By getting the distance between the centre of the circles (basic geometry, which Processing takes care of for us with the "dist()" function) we can tell quite easily if the circles are touching. 

If the sum of the radiuses* is equal to the distance between the centres then the circles are just touching. If the distance between the centres is larger than the sum of radiuses then they aren't touching, while if that distance is smaller than the radiuses then there must be an overlap. Not trivial, but also far from rocket science. Lack of exposure to geometry is the real barrier we run into here, particularly with younger students, but with a bit of gentle coaxing most students managed it at some stage in the past two weeks. We also have the demo below to allow us to step through frame by frame and see what's happening. 

This is a very slightly altered version of the basic portion of the game students produce in their first term. We've added the line between circles, along with the text readouts, to allow us to watch the values of the important datapoints and analyse what's happening in the program. The line will turn red when the circles collide. The orange ball can be moved left and right using the 'a' and 's' keys, while the program can be paused by pressing '0', resumed at normal speed by pressing '9', or incremented a frame at a time by pressing 'c' while paused. (NOTE: You will probably have to click on the frame for any of those key presses to work!)

What you're seeing above, by the way, is one of the very neat features of processing - it can be embedded straight into a web page, almost without having to make any changes at all!

(Technical note: it's actually not quite that straightforward in reality, for a couple of reasons. Mostly it's that switching from Java (on the desktop) to javascript (in the browser) isn't ever going to be absolutely perfect. We've found that the background() function gives up on us in the javascript version (although this isn't a universal problem, and so merits a little more digging), as does some image resizing. In addition there are likely to be some issues with any complex object inheritance structures, as well as issues with overriding (since java is strongly typed and javascript is weakly typed). When the time comes (maybe 5 or 6 terms in!) this will provide us with a fascinating way of talking to students about the differences between strongly and weakly typed languages, and about how languages implement inheritance, and all sorts of other similar topics.
Another issue we've run into seems to be a Squarespace specific one, namely that embedding our canvas directly in the html on Squarespace just won't work. We have a couple of theories why, but for the moment we work around it by hosting them elsewhere and embedding them here using iframes.)

We have a number of mini-applications like this which we've either used this term, or will introduce next term, and many more ideas floating around. Look out for them here in the not too distant future!

In the meantime we're now facing into our final two weeks of term, and looking ahead already to next year. If you haven't already spotted the signs, we're taking signups for January already. If you're interested, don't wait until it's too late!




*Or radii, if you like to more classical in your plurals.