TEACH RANDOM_WALK
2 Dec 2011
Using the RC_GRAPHIC (relative coordinates 2-D graphics) package in Pop11
and its Object Oriented extension rclib
Aaron Sloman, School of Computer Science
University of Birmingham, UK
http://www.cs.bham.ac.uk/~axs
Playing with some simple commands, and later exploring random walks.
See the video tutorial based on this file on youtube:
http://www.youtube.com/watch?v=jsCINKXK6ek
For more information about the 2-D graphical facilities in Pop11 see
http://www.cs.bham.ac.uk/research/projects/poplog/figs/rclib
For examples of 'thinky' programs see
http://www.cs.bham.ac.uk/research/projects/poplog/examples
To make the commands available:
uses rclib
Additional backgroun information in TEACH files:
TEACH RC_GRAPHIC
TEACH RC_GRAPHPLOT
TEACH FACES
Create a window:
vars win1 = rc_new_window_object(400, 0, 500, 500, false,'win1');
win1 -> rc_current_window_object;
vars win2 = rc_new_window_object(400, 0, 600, 600, false,'win1');
win2 -> rc_current_window_object;
rc_kill_window_object(win1);
rc_kill_window_object(win2);
rc_start();
'black' -> rc_foreground(rc_window);
'red' -> rc_foreground(rc_window);
'blue' -> rc_foreground(rc_window);
;;; Horizontal and vertical steps
1-> rc_linewidth;
2-> rc_linewidth;
rc_jumpto(0, 0);
rc_xposition, rc_yposition =>
rc_drawby(20, 0);
rc_xposition, rc_yposition =>
rc_drawby(0, 20);
rc_xposition, rc_yposition =>
rc_drawby(-20, 0);
rc_drawby(0, -20);
'black' -> rc_foreground(rc_window);
rc_drawby(explode(oneof([[20 0][0 20][-20 0][0 -20]])));
'blue' -> rc_foreground(rc_window);
;;; Horizontal and vertical steps
rc_drawby(explode(oneof([[20 20] [-20 20] [-20 -20] [20 -20]])));
'red' -> rc_foreground(rc_window);
rc_drawby(explode(oneof([[20 0][20 20][0 20][-20 20][-20 0][-20 -20][0 -20][20 -20]])));
rc_start();
;;; should be documented
define random_walk(options, steps, delay, clear, colour);
if clear then rc_start() endif;
if isstring(colour) then
colour -> rc_foreground(rc_window)
endif;
rc_jumpto(0,0);
0-> rc_heading;
repeat steps times
rc_drawby(explode(oneof(options)));
if delay then syssleep(delay) endif;
endrepeat;
enddefine;
random_walk([[20 0][0 20][-20 0][0 -20]], 100, 5, false, 'black');
random_walk([[20 0][0 20][-20 0][0 -20]], 100, 5, false, 'blue');
random_walk([[5 0][0 5][-5 0][0 -5]], 100, false, true, 'black');
random_walk([[5 5][-5 5][-5 -5][5 -5]], 100, 1, true, 'blue');
random_walk([[5 0][5 5][0 5][-5 5][-5 0][-5 -5][0 -5][5 -5]],
100, 1, true, 'red');
random_walk([[5 0][5 5][0 5][-5 5][-5 0][-5 -5][0 -5][18 -18]],
100, 20, true, 'red');
--- $usepop/pop/teach/random_walk.p
--- Copyright University of Birmingham 2011. All rights reserved.