OFFSIDE DEMONSTRATION APPLET


Instructions

  1. Place the mouse pointer over a player (blue players are attacking the goal at the top of the screen, reds defending) and hold down the left mouse button
  2. Drag the player into any position on the pitch you fancy. Release the mouse button to drop the player in his current location.
  3. Repeat with as many players as you like
  4. Click the 'Check for Offside' button to see if play is offside (were the ball to be played forward at that point)
  5. The red line you will then see represents the 'offside threshold' i.e. the point beyond which attacking players must not stray if they are to stay onside
  6. The applet will either inform you of the (most) offside player, or describe the play as being onside, via a message on the yellow panel at the top end of the pitch
  7. You also have the facility to draw arbitray shapes over the scene, a la Andy Gray on Sky Sports. To do this, click and drag the mouse without selecting a player to move. You are the pundit!
  8. If you are technically minded (or just curious, in all senses of the word...) you can see the Java source code here.

I wrote this applet following a conversation with a non-football savvy friend, when I realised that the offside rule can seem complex when explained verbally, but very simple when illustrated graphically. According to the official rules of Association Football, the offside rule is thus:

  1. A player is in an offside position if he is nearer to his opponent's goal line than the ball is unless:
  2. A player will only be declared offside if, at the moment the ball touches or is played by one of his own team, in the opinion of the referee, that player is:
  3. A player will not be declared offside:
  4. If a player is declared offside, the referee gives an indirect free kick which is taken by the opposing team from the place where the offside occurred.Offside is judged from the moment the ball is played. A player who is level with the second last opponent or with the last two opponents is not in an offside position.

I thought this relatively simple set of rules would be good to express in code - not too involved for an afternoon of programming, but enough of a challenge to keep me interested for a few hours. If you want to see how it was done you can see the Java source code here.


Michael Fitzmaurice April, 2003