File: tutprog_linejoin.dats

package info (click to toggle)
ats2-lang 0.3.11-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 40,116 kB
  • sloc: ansic: 389,606; makefile: 7,069; lisp: 770; sh: 657; php: 573; python: 387; perl: 365
file content (97 lines) | stat: -rw-r--r-- 2,196 bytes parent folder | download | duplicates (4)
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
//
// Author: Hongwei Xi
// Time: April 29, 2010
//
(* ****** ****** *)

(*
** Ported to ATS2 by Hongwei Xi, September, 2013
*)

(* ****** ****** *)
//
// How to compile:
//   patscc -I${PATSHOME}/contrib -o tutprog_linejoin tutprog_linejoin.dats `pkg-config cairo --cflags --libs`
//
// How to test: ./tutprog_linejoin
//
(* ****** ****** *)
//
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
//
#define
LIBCAIRO_targetloc
"\
$PATSHOME/\
npm-utils/contrib\
/atscntrb/atscntrb-hx-libcairo"
//
(* ****** ****** *)
//
#include
"{$LIBCAIRO}/mylibies.hats"
#staload $CAIRO // opening it!
//
(* ****** ****** *)

fun
draw_triangle{l:agz}
(
  cr: !cairo_ref l
, x0: double, y0: double
, x1: double, y1: double
, x2: double, y2: double
) : void = () where {
  val () = cairo_move_to (cr, x0, y0)
  val () = cairo_line_to (cr, x1, y1)
  val () = cairo_line_to (cr, x2, y2)
  val () = cairo_close_path (cr)
} (* end of [draw_triangle] *)

(* ****** ****** *)

implement
main0 () = () where {
//
val W = 300 and H = 300
val sf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, W, H)
val cr = cairo_create (sf)
//
macdef c0set () = cairo_set_source_rgb (cr, 0.0, 0.0, 0.0)
//
val () = cairo_set_line_width (cr, 15.0)
//
val () = c0set ()
val () = draw_triangle (cr, 50.0, 50.0, 20.0, 250.0, 80.0, 250.0)
val () = cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER)
val () = cairo_stroke (cr)
//
val () = c0set ()
val () = draw_triangle (cr, 150.0, 50.0, 120.0, 250.0, 180.0, 250.0)
val () = cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND)
val () = cairo_stroke (cr)
//
val () = c0set ()
val () = draw_triangle (cr, 250.0, 50.0, 220.0, 250.0, 280.0, 250.0)
val () = cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL)
val () = cairo_stroke (cr)
//
val status =
  cairo_surface_write_to_png (sf, "tutprog_linejoin.png")
val () = cairo_surface_destroy (sf); val () = cairo_destroy (cr)
//
val () =
if status = CAIRO_STATUS_SUCCESS then begin
  print "The image is written to the file [tutprog_linejoin.png].\n"
end else begin
  print "exit(ATS): [cairo_surface_write_to_png] failed"; print_newline ()
end // end of [if]
//
} (* end of [main0] *)

(* ****** ****** *)

(* end of [tutprog_linejoin.dats] *)