-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drawille.dcl
146 lines (130 loc) · 3.32 KB
/
Drawille.dcl
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
definition module Drawille
/**
* Monochrome canvas for drawing with Braille characters on UTF-8 terminal.
*
* (0, 0) pixel is in the top-left corner.
* x coordinate grows right.
* y coordinate grows down.
*/
:: PixelValue :== Bool
setPixel :== True
unsetPixel :== False
/**
* Canvas for drawing with Braille characters.
* @var current X dimension of canvas
* @var current Y dimension of canvas
* @var current X dimension of internal bitmap
* @var current Y dimension of internal bitmap
* @var array, which contains the bitmap in rows
*/
:: Canvas = { size_x :: !Int, size_y :: !Int,
real_size_x :: !Int, real_size_y :: !Int, data :: !.{#PixelValue}}
/**
* Empty Canvas without any drawings. Also see {{`create`}}.
*/
empty :: .Canvas
/**
* Create Canvas with given dimensions. Also see {{`empty`}}.
* @param The number of columns
* @param The number of rows
* @result The blank canvas.
*/
create :: !Int !Int -> .Canvas
/**
* Create Canvas from list of pixel coordinates. These pixels
* will be set, canvas will be autoadjusted.
* @param The number of columns
* @param The number of rows
* @result The blank canvas.
*/
fromList :: ![(Int, Int)] -> .Canvas
/**
* Get the value of a pixel on canvas at given coordinates.
*
* @param The canvas
* @param x coordinate of the pixel (column)
* @param y coordinate of the pixel (row)
*
* @result The value of the pixel
*/
get :: !Canvas !Int !Int -> PixelValue
/**
* Get the value of a pixel on canvas at given coordinates.
* Unique version.
*
* @param The canvas
* @param x coordinate of the pixel (column)
* @param y coordinate of the pixel (row)
*
* @result The value of the pixel and unmodified canvas
*/
uget :: !u:Canvas !Int !Int -> *(PixelValue, v:Canvas), [u <= v]
/**
* Set pixel with coordinates on Canvas.
*
* @param The canvas
*
* @param x coordinate of the pixel (column)
* @param y coordinate of the pixel (row)
*
* @result Updated canvas
*/
set :: !*Canvas !Int !Int -> *Canvas
/**
* Unset pixel with coordinates on Canvas.
*
* @param The canvas
*
* @param x coordinate of the pixel (column)
* @param y coordinate of the pixel (row)
*
* @result Updated canvas
*/
unset :: !*Canvas !Int !Int -> *Canvas
/**
* Toggle pixel with coordinates on Canvas.
*
* @param The canvas
*
* @param x coordinate of the pixel (column)
* @param y coordinate of the pixel (row)
*
* @result Updated canvas
*/
toggle :: !*Canvas !Int !Int -> *Canvas
/**
* Render canvas contents as a list of monochrome Braille
* character strings (UTF-8 encoded).
*
* @param Canvas to render
*
* @result List of UTF-8 encoded strings
*/
frame :: !Canvas -> [String]
// Below are debug functions, used for testing.
/**
* Braille character code to the list of coordinates
*
* @param Braille character code
*
* @result List of coordinates of "set" pixels
*/
brailleToList :: !Int -> [(Int, Int)]
/**
* Recognise canvas contents as a bitmap of
* Braille characters. Simple bit encoding based on `pixmap`
* is used, character codes are in the range [0..255].
*
* @param Canvas to parse
*
* @result 2D array (first index - rows) of Braille chars
*/
toBrailleCodes :: !Canvas -> {*{#Int}}
/**
* Debug print canvas.
*
* @param canvas to print.
*
* @result string, where each character represents canvas pixel.
*/
toDebugString :: !.Canvas -> String