File: test04.dats

package info (click to toggle)
ats2-lang 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,064 kB
  • sloc: ansic: 389,637; makefile: 7,123; lisp: 812; sh: 657; php: 573; python: 387; perl: 365
file content (67 lines) | stat: -rw-r--r-- 1,072 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
(*
** Author: Hongwei Xi
** Authoremail: gmhwxiATgmailDOTcom
** Start time: October, 2013
*)

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

#define PI 3.1415926535898

(* ****** ****** *)
//
extern
fun{}
draw_line (point, point, color): void
//
extern
fun{}
draw_dragon
(
  sgn: int, point, point, color, int(*level*)
) : void // end of [draw_dragon]
//
(* ****** ****** *)

implement{
} draw_line
(
  p1, p2, clr
) = let
//
val () = mydraw_new_path ()
//
val () = mydraw_move_to (p1)
val () = mydraw_line_to (p2)
val () = mydraw_stroke_set_rgb (clr.r(), clr.g(), clr.b())
val () = mydraw_stroke ()
//
val () = mydraw_close_path ()
//
in
  // nothing
end // end of [draw_line]

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

implement{
} draw_dragon
(
  sgn, p1, p2, clr, n
) = let
in
//
if n > 0 then let
  val v0 = $M.cos(PI/4) * (p2 - p1)
  val q1 = p1 + vector_rotate (v0, sgn*PI/4)
  val () = draw_dragon ( 1, p1, q1, clr, n-1)
  val () = draw_dragon (~1, q1, p2, clr, n-1)
in
  // nothing
end else draw_line (p1, p2, clr) // end of [if]
//
end // end of [draw_dragon]

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

(* end of [test04.dats] *)