source: Deliverables/Dissemination/final-review/wp5/Pics/summul_cost_incr.ml @ 3282

Last change on this file since 3282 was 3282, checked in by regisgia, 7 years ago
  • WP5 slides for the final review.
File size: 3.0 KB
Line 
1
2open Mlpost;;
3open Box;;
4open Arrow;;
5open Path;;
6open Command;;
7open Num;;
8open Dash;;
9open Color;;
10open Pen;;
11open Point;;
12open Picture;;
13
14
15let box = Box.box ~stroke:None ~dx:zero ~dy:zero
16let path = Box.path ~stroke:None ~dx:zero ~dy:zero
17let pic = Box.pic ~stroke:None ~dx:zero ~dy:zero
18
19(* Helpers *)
20
21let string_of_list sep f =
22  let rec aux = function
23    | [] -> ""
24    | [e] -> f e
25    | e :: l -> (f e) ^ sep ^ (aux l)
26  in
27  aux
28
29
30(* Text *)
31
32let color_text color text = "\\textcolor{" ^ color ^ "}{" ^ text ^ "}"
33let color_bftext color text = "\\textcolor{" ^ color ^ "}{\\bf " ^ text ^ "}"
34let texttt text = "\\texttt{" ^ text ^ "}"
35
36let line lexs =
37  Box.tex (texttt (string_of_list " " (fun s -> s) lexs))
38
39let lines l =
40  let f (b_prev, b_res) (indent, lexs) =
41    let b_line = line lexs in
42    let b_line = Box.place `Southwest ~pos:`Northwest b_prev b_line in
43    let indent = float_of_int indent in
44    let shft = Point.pt (Num.multf indent (cm 0.4), zero) in
45    let b_line = Box.shift shft b_line in
46    (b_line, b_res @ [b_line])
47  in
48  let (_, b_res) = List.fold_left f (Box.empty (), []) l in
49  Box.group b_res
50
51let typ = color_bftext "black"
52let funct = color_text "blue"
53let keyword = color_bftext "black"
54let var = color_text "black"
55
56let label s = color_text "blue" s
57
58let kwhile = keyword "while"
59let kif = keyword "if"
60let kreturn = keyword "return"
61
62let typ_int = typ "int"
63
64let args l =
65  let f (t, x) = (typ t) ^ " " ^ (var x) in
66  "(" ^ (string_of_list ", " f l) ^ ")"
67
68let line_cost = [color_text "magenta" "int \\_cost;"]
69let line1 = [typ_int ; funct "summul" ; args [("int", "n")] ; "\\{"]
70let line2 = [typ_int ; (var "accu") ^ " = 1;"]
71let line3 = [typ_int ; (var "stop") ^ " = 1;"]
72let line4 = [typ_int ; (var "k") ^ " = n;"]
73let line41 = [color_text "red" "\\_cost += 2;"]
74let line42 = ["accu = 1;"]
75let line43 = ["stop = 1;"]
76let line44 = ["k = n;"]
77let line5 = [kwhile ; "(k >= stop)" ; "\\{"]
78let line51 = [color_text "darkgreen" "\\_cost += 9;"]
79let line6 = ["accu += accu * k;"]
80let line7 = ["k -= 1;" ; "\\}"]
81let line71 = [color_text "blue" "\\_cost += 1;"]
82let line8 = [kreturn ; "(accu);"]
83let line81 = [ "\\}" ]
84let line9 = [typ "void" ; funct "main" ; args [] ; "\\{"]
85let line10 = [typ_int ; (var "i") ^ ";"]
86let line100 = [color_text "magenta" "\\_cost = 0;"]
87let line11 = [color_text "orange" "\\_cost += 12;"]
88let line12 = ["i = summul(5);" ; "\\}"]
89
90let cost = lines [(0, line_cost)]
91
92let summul = lines [(0, line1) ; (1, line2) ; (0, line3) ; (0, line4) ;
93                    (0, line41) ; 
94                    (* (0, line42) ; (0, line43) ; (0, line44) ; *)
95                    (0, line5) ; (1, line51) ; (0, line6) ; (0, line7) ;
96                    (-1, line71) ; (0, line8); (-1, line81) ]
97
98let main = lines [(0, line9) ; (1, line10) ; (0, line100) ;
99                  (0, line11) ; (0, line12)]
100
101
102(* Place Text *)
103
104
105(* Strokes and arrows *)
106
107
108(* Main *)
109
110let summul_cost_incr = Box.hbox ~pos:`Top ~padding:(cm 1.)
111  [summul]
112
113let summul_cost_incr = Box.draw summul_cost_incr
114
115let _ = Metapost.emit "summul_cost_incr" summul_cost_incr
Note: See TracBrowser for help on using the repository browser.