fork download
  1.  
  2. let w1 (x, y) = (0.836 *. x +. 0.044 *. y, (-0.044) *. x +. 0.836 *. y +. 0.169);;
  3. let w2 (x, y) = ((-0.141) *. x +. 0.302 *. y, 0.302 *. x +. 0.141 *. y +. 0.127);;
  4. let w3 (x, y) = (0.141 *. x -. 0.302 *. y, 0.302 *. x +. 0.141 *. y +. 0.169);;
  5. let w4 (x, y) = (0.0, 0.175337 *. y);;
  6.  
  7. let image_width = 80;;
  8. let image_height = 80;;
  9.  
  10. let makeImageBuf p n m init =
  11. let result = Array.make p (Array.make n (Array.make m init)) in
  12. for j = 1 to p - 1 do
  13. result.(j) <- Array.make n (Array.make m init);
  14. for i = 1 to n - 1 do
  15. result.(j).(i) <- Array.make m init
  16. done;
  17. done;
  18. result;;
  19.  
  20. let imgBuf = makeImageBuf 3 image_width image_height 0.0;;
  21.  
  22. let rec cedar n (x, y) ib =
  23. if 0 < n then begin
  24. cedar (n - 1) (w1(x,y)) ib;
  25. if Random.float 1.0 < 0.3 then begin
  26. cedar (n - 1) (w2(x,y)) ib;
  27. end;
  28.  
  29. if Random.float 1.0 < 0.3 then begin
  30. cedar (n - 1) (w3(x,y)) ib;
  31. end;
  32.  
  33. if Random.float 1.0 < 0.3 then begin
  34. cedar (n - 1) (w4(x,y)) ib;
  35. end;
  36. end
  37. else begin
  38. let xx = int_of_float (x *. (float image_width) *. 0.9) + image_width/2 in
  39. let yy = image_height - int_of_float (y *. (float image_height) *. 0.9) in
  40. if xx >= image_width then () else
  41. if yy >= image_height then () else
  42. imgBuf.(1).(xx).(yy) <- 1.0;
  43. end;;
  44.  
  45. cedar 20 (0.0, 0.0) imgBuf;;
  46. for i = 0 to image_height -1 do
  47. for j = 0 to image_width -1 do
  48. print_int (int_of_float (imgBuf.(1).(j).(i)));
  49. done;
  50. done;;
  51.  
Success #stdin #stdout 1.19s 2736KB
stdin
Standard input is empty
stdout
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000011100000000000000000000000
00000000000000000000000000000000000000000000000000000111100000000000000000000000
00000000000000000000000000000000000000000000000000111111000000000000000000000000
00000000000000000000000000000000000000000000000001111110000000000000000000000000
00000000000000000000000000000000000000000000000011111110000000000000000000000000
00000000000000000000000000000000000000000000000011111110000000000000000000000000
00000000000000000000000000000000000000000000001011111110000000000000000000000000
00000000000000000000000000000000000000000000001111111100000000000000000000000000
00000000000000000000000000000000000000000000101111111100000000000000000000000000
00000000000000000000000000000000000000000000111111111000000000000000000000000000
00000000000000000000000000000000000000000110111111111100000000000000000000000000
00000000000000000000000000000000000000000111111111111000000000000000000000000000
00000000000000000000000000000000000000000111111111111100000000000000000000000000
00000000000000000000000000000000000000001011111111111000000000000000000000000000
00000000000000000000000000000000000000001011111111110000000000000000000000000000
00000000000000000000000000000000000000001101111111111100000000000000000000000000
00000000000000000000000000000000000001001111111111111000000000000000000000000000
00000000000000000000000000000000000001101111111111110000000000000000000000000000
00000000000000000000000000000000000001111111110111011100000000000000000000000000
00000000000000000000000000000000000001111111111111111100000000000000000000000000
00000000000000000000000000000000000000111111111111110000000000000000000000000000
00000000000000000000000000000000001000111111111111110000000000000000000000000000
00000000000000000000000000000000001100111111101111111100000000000000000000000000
00000000000000000000000000000000001110011111111111111100000000000000000000000000
00000000000000000000000000000000001111111111111111111000000000000000000000000000
00000000000000000000000000000000001111111101111111110000000000000000000000000000
00000000000000000000000000000010000111111101111111000100000000000000000000000000
00000000000000000000000000000011000111111101011111101100000000000000000000000000
00000000000000000000000000000011100011111111111111111100000000000000000000000000
00000000000000000000000000000001111011111111111111111000000000000000000000000000
00000000000000000000000000000011111111111111111111111000000000000000000000000000
00000000000000000000000000000001111111111011111111110001000000000000000000000000
00000000000000000000000000000000111111111011111111100110000000000000000000000000
00000000000000000000000000000000111111111010111111011110000000000000000000000000
00000000000000000000000000110000111111111110111111111110000000000000000000000000
00000000000000000000000000111000011111111101111111111100000000000000000000000000
00000000000000000000000000011110001111111111111111111100000000000000000000000000
00000000000000000000000000011111110111111111111111111000000000000000000000000000
00000000000000000000000000011111111111110111111111111001100000000000000000000000
00000000000000000000000000001111111111100111111111110011100000000000000000000000
00000000000000000000000000001111111111110110111111011111000000000000000000000000
00000000000000000000000000000111111111111100111111111111000000000000000000000000
00000000000000000000001000000111111111111101111111111110000000000000000000000000
00000000000000000000001100000111111111111011111111111110000000000000000000000000
00000000000000000000001111000010111111111111111111111110000000000000000000000000
00000000000000000000000111110001111111111111111111111000001000000000000000000000
00000000000000000000000111111110101111101111111111111100011000000000000000000000
00000000000000000000000111111110111111001111111111110001111000000000000000000000
00000000000000000000000111111111111111001111111111100111111000000000000000000000
00000000000000000000000011111111111111101001111111111111111000000000000000000000
00000000000000000000000011111111111111101001111111111111110000000000000000000000
00000000000000000000000000111111111111111001111111111111100000000000000000000000
00000000000000000000000001111111111111111011111111111111100000000000000000000000
00000000000000000000000000011111111111111011111111111111000000000000000000000000
00000000000000000000000000011111111111111111111111111110000000000000000000000000
00000000000000000000000000000111111111111111111111111111000000000000000000000000
00000000000000000000000000001111111111011111111111111100000000000000000000000000
00000000000000000000000000000000111111001111111111111100000000000000000000000000
00000000000000000000000000000011111110001111111111110000000000000000000000000000
00000000000000000000000000000000000000001101111111111000000000000000000000000000
00000000000000000000000000000000000000001001111110000000000000000000000000000000
00000000000000000000000000000000000000001000111111100000000000000000000000000000
00000000000000000000000000000000000000001000000101000000000000000000000000000000
00000000000000000000000000000000000000001000000000000000000000000000000000000000
00000000000000000000000000000000000000001000000000000000000000000000000000000000
00000000000000000000000000000000000000001000000000000000000000000000000000000000
00000000000000000000000000000000000000001000000000000000000000000000000000000000
00000000000000000000000000000000000000001000000000000000000000000000000000000000