% Sketcher %

old_x_y(0, 0).

sketcher :-
   newframe,
   repeat,
      cursor(Mouse, X, Y),
      action(Mouse, X, Y).

action(Buttons, X, Y) :-
   Buttons = 2,
   old_x_y(Old_X, Old_Y),
   retract(old_x_y(_, _)),
   move_abs(Old_X, Old_Y),
   line_abs(X, Y),
   Fact =.. [old_x_y, X, Y],
   asserta(Fact), 
   !, fail.

action(Buttons, X, Y) :-
   Buttons = 4,
   retract(old_x_y(_, _)),
   Now =.. [old_x_y, X, Y],
   asserta(Now), 
   !, fail.

action(Buttons, X, Y) :-
   Buttons = 1,
   display('Sketching ended'), nl, !.
