@@ -5,16 +5,18 @@ module UnicodeGraphics
5
5
6
6
export blockize, brailize
7
7
8
- blockize (a, cutoff= 0 ) = blockize (a, cutoff, 1 : size (a, 1 ), 1 : size (a, 2 ))
9
- blockize (a, cutoff, yrange, xrange) = begin
8
+ blockize (a, cutoff= 0 ) = blockize (a, cutoff)
9
+ blockize (a, cutoff) = begin
10
+ yrange, xrange = axes (a)
10
11
out = Array {Char,2} (undef, length (xrange) + 1 , (length (yrange) - 1 ) ÷ 2 + 1 )
11
- blockize! (out, a, cutoff, yrange, xrange )
12
+ blockize! (out, a, cutoff)
12
13
end
13
14
14
- blockize! (out, a, cutoff, yrange, xrange ) = join (block_array! (out, a, cutoff, yrange, xrange ))
15
+ blockize! (out, a, cutoff) = join (block_array! (out, a, cutoff))
15
16
16
- function block_array! (out, a, cutoff, yrange, xrange)
17
- for y in yrange. start: 2 : yrange. stop
17
+ function block_array! (out, a, cutoff)
18
+ yrange, xrange = axes (a)
19
+ for y in first (yrange): 2 : last (yrange)
18
20
for x in xrange
19
21
top = checkval (a, y, x, yrange, xrange, cutoff)
20
22
bottom = checkval (a, y + 1 , x, yrange, xrange, cutoff)
@@ -23,10 +25,10 @@ function block_array!(out, a, cutoff, yrange, xrange)
23
25
else
24
26
ch = bottom ? ' ▄' : ' '
25
27
end
26
- out[x- xrange. start + 1 , (y- yrange. start ) ÷ 2 + 1 ] = Char (ch)
28
+ out[x- first ( xrange) + 1 , (y- first ( yrange) ) ÷ 2 + 1 ] = Char (ch)
27
29
end
28
30
# Return after every column
29
- out[end , (y- yrange. start ) ÷ 2 + 1 ] = Char (' \n ' )
31
+ out[end , (y- first ( yrange) ) ÷ 2 + 1 ] = Char (' \n ' )
30
32
end
31
33
# The last character is null
32
34
out[end , end ] = 0x00
35
37
36
38
const braile_hex = ((0x01 , 0x08 ), (0x02 , 0x10 ), (0x04 , 0x20 ), (0x40 , 0x80 ))
37
39
38
- brailize (a, cutoff= 0 ) = brailize (a, cutoff, 1 : size (a, 1 ), 1 : size (a, 2 ))
39
- brailize (a, cutoff, yrange, xrange) = begin
40
+ brailize (a) = brailize (a, 0 )
41
+ brailize (a, cutoff) = begin
42
+ yrange, xrange = axes (a)
40
43
out = Array {Char,2} (undef, (length (xrange) - 1 ) ÷ 2 + 2 , (length (yrange) - 1 ) ÷ 4 + 1 )
41
- brailize! (out, a, cutoff, yrange, xrange )
44
+ brailize! (out, a, cutoff)
42
45
end
43
46
44
- brailize! (out, a, cutoff, yrange, xrange ) = join (braile_array! (out, a, cutoff, yrange, xrange ))
47
+ brailize! (out, a, cutoff) = join (braile_array! (out, a, cutoff))
45
48
46
- function braile_array! (out, a, cutoff, yrange, xrange)
47
- for y = yrange. start: 4 : yrange. stop
48
- for x = xrange. start: 2 : xrange. stop
49
+ function braile_array! (out, a, cutoff)
50
+ yrange, xrange = axes (a)
51
+ for y in first (yrange): 4 : last (yrange)
52
+ for x in first (xrange): 2 : last (xrange)
49
53
ch = 0x2800
50
54
for j = 0 : 3 , i = 0 : 1
51
55
if checkval (a, y+ j, x+ i, yrange, xrange, cutoff)
52
56
ch += braile_hex[j % 4 + 1 ][i % 2 + 1 ]
53
57
end
54
58
end
55
- out[(x - xrange. start) ÷ 2 + 1 , (y- yrange. start ) ÷ 4 + 1 ] = ch
59
+ out[(x - first ( xrange)) ÷ 2 + 1 , (y- first ( yrange) ) ÷ 4 + 1 ] = ch
56
60
end
57
61
# Return after every column
58
- out[end , (y- yrange. start ) ÷ 4 + 1 ] = Char (' \n ' )
62
+ out[end , (y- first ( yrange) ) ÷ 4 + 1 ] = Char (' \n ' )
59
63
end
60
64
# The last character is null
61
65
out[end , end ] = 0x00
62
66
out
63
67
end
64
68
65
69
checkval (a, y, x, yrange, xrange, cutoff) = begin
66
- if x <= xrange. stop && y <= yrange. stop
70
+ if x <= last ( xrange) && y <= last ( yrange)
67
71
a[y, x] > cutoff
68
72
else
69
73
false
0 commit comments