forked from dextercallender/blur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtin.blr
59 lines (47 loc) · 1.9 KB
/
builtin.blr
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
/* builtin.blr, authored by Tim Goodwin-tlg2132 and Dexter Callender-dec2148 */
char intensityToChar(int i){
char[] map = ['$','@','B','%','8','&','W','M','#','*','o','a','h','k','b','d','p','q','w','m','Z','0','O','Q','L','C','J','U','Y','X','z','c','v','u','n','x','r','j','f','t','/','|','(',')','1','{','}','[',']','?','-','_','+','~','<','>','i','!','l','I',';',':',',','^','.',' '];
int intensity = i;
int maplen = len(map);
int factor = intensity * maplen; /* scale factor to map intensity (0-255) to char (0-len(map) */
int index = factor / 255;
char ret;
if(index > maplen) {
ret = map[0];
}
if(index == 0) {
ret = map[maplen - 1];
}
else {
ret = map[maplen - index];
}
return ret;
}
int charToIntensity(char c){
char[] map = ['$','@','B','%','8','&','W','M','#','*','o','a','h','k','b','d','p','q','w','m','Z','0','O','Q','L','C','J','U','Y','X','z','c','v','u','n','x','r','j','f','t','/','|','(',')','1','{','}','[',']','?','-','_','+','~','<','>','i','!','l','I',';',':',',','^','.',' '];
int maplen = len(map);
int idx = 0;
int i;
int intensity;
for(i = 0; i < maplen; i = i + 1) {
if(map[i] == c) {
idx = i;
}
}
intensity = (255 * idx) / maplen;
return 255 - intensity;
}
/* offset = 0 for darken, offset = 1 for lighten */
char adjustPX(char c, int offset) {
char[] map = ['$','@','B','%','8','&','W','M','#','*','o','a','h','k','b','d','p','q','w','m','Z','0','O','Q','L','C','J','U','Y','X','z','c','v','u','n','x','r','j','f','t','/','|','(',')','1','{','}','[',']','?','-','_','+','~','<','>','i','!','l','I',';',':',',','^','.',' '];
int maplen = len(map);
int idx = 0;
int i;
for(i = 0; i < maplen; i = i + 1) {
if(map[i] == c) {
idx = i;
}
}
offset = offset - 1;
return map[idx + offset];
}