summaryrefslogtreecommitdiff
path: root/util/cairo-script/examples/dragon.cs
blob: 1060ca6993dfb5cf8a97ea531a04460e22fd1eac (plain)
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
%!CairoScript
/pot { % n -- n
  1 sub
  dup  -1 bitshift or
  dup  -2 bitshift or
  dup  -4 bitshift or
  dup  -8 bitshift or
  dup -16 bitshift or
  1 add
} bind def

/direction { % i -- bool
  dup 2 lt { pop true } {
      dup 1 add dup pot dup 3 -1 roll eq { pop pop true } {
	  2 div 1 sub 2 mul exch sub direction not
      } ifelse
  } ifelse
} bind def

/path { % cr dx dy -- cr
  0 1 2048 {
    4 1 roll 3 copy L pop 4 -1 roll direction {
      exch neg
    } {
      neg exch
    } ifelse
  } for
  pop pop
} bind def

dict
  /width  512 set
  /height 512 set
  surface context

1 g set-source paint

//LINE_CAP_ROUND set-line-cap
//LINE_JOIN_ROUND set-line-join
4 set-line-width

256 256 m  12 0 path 0 0 0 rgb set-source stroke
256 256 m -12 0 path 1 0 0 rgb set-source stroke
256 256 m 0  12 path 0 1 0 rgb set-source stroke
256 256 m 0 -12 path 0 0 1 rgb set-source stroke

/target get (out.png) write-to-png pop
pop