1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| #open "graphics";;
let room = make_matrix 600 800 0;;
let dim room =
let n = vect_length room in
if n = 0 then (0, 0)
else (n, vect_length room.(0));;
let prob ng mh =
let t = make_vect (ng+mh+1) 0 in
for i = ng to (ng+mh) do
t.(i) <- 1
done;
for i = 1 to (ng-1) do
t.(i) <- 0
done;
t.(random__int (mh+ng));;
let proba ng mh =
let v = make_vect (ng+mh) 0 in
let rng = ref ng and rmh = ref mh in
for i = 0 to (ng+mh-1) do
if (prob (!rng) (!rmh)) = 1 then
(v.(i) <-1;
rmh:=(!rmh - 1))
else (v.(i) <-0;
rng:=(!rng - 1))
done;
v;;
let fix_outline room =
let (l,h) = dim room in
for j = 0 to (l-1) do
room.(j).(0) <- 2;
room.(j).(h-1) <- 2;
done;
for i = 0 to (h-1) do
room.(0).(i) <- 2;
room.(l-1).(i) <- 2;
done;
for j = 280 to 320 do
room.(j).(h-1) <- 0;
done;
for i = 28 to 45 do
room.(l-1).(i) <- 0;
done;
for j = 80 to 140 do
room.(j).(h-1) <- 0;
done;
for i = 700 to 750 do
room.(l-1).(i) <- 0;
done;
for i = 0 to (h-1) do
room.(200).(i) <- 2;
done;
room;;
let room1 = fix_outline room;;
let translate_into_graph room (x,y) (a,b) =
open_graph " ";
let mh = abs(y-b) in
let ng = abs(x-a) in
let xc = ref x in
let yc = ref y in
let t = proba ng mh in
let u = vect_length t in
let (n,p) = dim room in
for i = 0 to (n-1) do
for j = 0 to (p-1) do
if (room.(i).(j) = 2)
then begin
set_color red;
plot j (n-i);
end
else if (room.(i).(j) = 2)
then begin
set_color black;
plot j (n-i);
end
done;
done;
for i = 0 to (u-1) do
if t.(i)=1 then begin
if (y > b) then (decr yc)
else (incr yc);
set_color red;
plot (!xc) (n - !yc)
end
else if t.(i)=0
then begin
if (x > a) then (decr xc)
else (incr xc);
set_color black;
plot (!xc) (n - !yc);
end
done;
read_key();
close_graph();;
translate_into_graph room1 (50,550) (799,300);; |
Partager