#include "library.h" double distance_between(const double x1, const double y1, const double x2, const double y2) { return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); } void main() { print("Width of field: "); const double width = read_double(); print("Speed of boy: "); const double boyspeed = read_double(); print("Speed of bull: "); const double bullspeed = read_double(); print("Initial position of bull:\n x: "); const double bullx0 = read_double(); print(" y: "); const double bully0 = read_double(); print("Position of tree:\n x: "); const double treex = read_double(); print(" y: "); const double treey = read_double(); /* I found that these figures provide for an exciting contest... width = 700 boyspeed = 2 bullspeed = 2.8 bullx0 = 300 for one result, 500 for the other. bully0 = 0 treex = 500 treey = 500 P.S. This is a multi-line comment that I have never shown you before */ MakeWindow(1000, width); PenColor(0.0, 1.0, 0.0); // green PenWidth(10); DrawPointAt(treex, width-treey); PenColor(1.0, 1.0, 1.0); // white PenWidth(7); DrawPointAt(treex, width-treey); PenWidth(2); const double time_increment=0.002, close_enough=1; double time_now=0.0; double bullx=bullx0, bully=bully0, boyx=0, boyy=width; while (distance_between(bullx, bully, boyx, boyy)>close_enough && distance_between(boyx, boyy, treex, treey)>close_enough) { const double initbullx=bullx, initbully=bully, initboyx=boyx, initboyy=boyy; const double boy_tree_direction = atan2(treex-boyx, treey-boyy); boyx += boyspeed*sin(boy_tree_direction)*time_increment; boyy += boyspeed*cos(boy_tree_direction)*time_increment; const double bull_boy_direction = atan2(boyx-bullx, boyy-bully); bullx += bullspeed*sin(bull_boy_direction)*time_increment; bully += bullspeed*cos(bull_boy_direction)*time_increment; PenColor(0.0, 0.0, 1.0); // blue MoveTo(initboyx, width-initboyy); DrawLineTo(boyx, width-boyy); PenColor(1.0, 0.0, 0.0); // red MoveTo(initbullx, width-initbully); DrawLineTo(bullx, width-bully); time_now += time_increment; } MoveTo(treex+10, width-(treey-10)); SetFontSize(24); SetFontFace("Arial"); SetFontAttributes(FONT_BOLD); PenWidth(10); if (distance_between(boyx, boyy, treex, treey)<=close_enough) { PenColor(0.0, 0.0, 1.0); WriteText("The boy is safely in the tree"); DrawPointAt(treex, width-treey); } else { PenColor(1.0, 0.0, 0.0); WriteText("The bull ate the boy"); DrawPointAt(boyx, width-boyy); } }