-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcairographics.ml
38 lines (31 loc) · 1.56 KB
/
cairographics.ml
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
open Cairo
type turtlecontext = { mutable cr: Cairo.context; }
let stroke ctx = Cairo.stroke ctx.cr
let set_source_rgb ctx = Cairo.set_source_rgb ctx.cr
let move_to ctx = Cairo.move_to ctx.cr
let line_to ctx = Cairo.line_to ctx.cr
let set_line_width ctx = Cairo.set_line_width ctx.cr
let create_context w h = let surface = Cairo.Image.create Cairo.Image.ARGB32 w h in
let ctx = Cairo.create surface in
let wf = (float_of_int w) in
let hf = (float_of_int h) in
(* paint background white *)
Cairo.rectangle ctx 0.0 0.0 wf hf;
Cairo.set_source_rgb ctx 1.0 1.0 1.0;
Cairo.fill ctx;
(* setup turtle coordinates *)
Cairo.translate ctx (wf /. 2.0) (hf /. 2.0);
Cairo.scale ctx 2. 2.;
(* setup turtle line properties *)
Cairo.set_line_width ctx 1.0;
Cairo.set_source_rgb ctx 0. 0. 0.;
Cairo.set_line_join ctx JOIN_MITER;
Cairo.set_line_cap ctx SQUARE;
Cairo.move_to ctx 0. 0.;
{ cr = ctx; }
let write_out ctx filename = let surface = Cairo.get_target ctx.cr in
stroke ctx;
Cairo.PNG.write surface filename
(* These are nops for the cairographics backend *)
let remove_turtle c = ()
let draw_turtle c x y h = ()