forked from dextercallender/blur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdlib.blr
119 lines (103 loc) · 2.41 KB
/
stdlib.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
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
/* stdlib.blr, authored by Tim Goodwin-tlg2132 and Dexter Callender-dec2148 */
void display(char[][] cv) {
int width = len(cv);
int height = len(cv[0]);
for(i = 0; i < width; i = i + 1){
for( j = 0; j < height; j = j + 1){
print( cv[i][j] );
}
println(" ");
}
}
int[][] edgeDetect(string x, int edgeDist){
int[][] image = readGrayscaleImage(x);
int width = len(image);
int height = len(image[0]);
int leftPixel = -1;
int rightPixel = -1;
int bottomPixel = -1;
int distance = -1;
int black = 0;
int row;
int col;
for(row=0; row<width; row=row+1){
for(col=0; col<height; col=col+1){
black = 0;
leftPixel = image[row][col];
if (col < height-1){
rightPixel = image[row][(col+1)];
distance = pixelDistance( leftPixel, rightPixel );
if(distance > edgeDist){
black = 1;
}
}
if(row < width-1){
bottomPixel = image[(row+1)][col];
distance = pixelDistance( leftPixel, bottomPixel );
if (distance > edgeDist){
black = 1;
}
}
if( black == 1 ){
image[row][col] = 1;
}else{
image[row][col] = 0;
}
}
}
for(row=0; row<width; row=row+1){
for(col=0; col<height; col=col+1){
print( image[row][col] );
}
println("");
}
return image;
}
int pixelDistance( int x, int y ){
int distance;
if( x > y ){
distance = x - y;
}else{
distance = y - x;
}
return distance;
}
char[][] dither(string imageFile) {
int[][] a = readGrayscaleImage(imageFile);
char[][] b = canvas(imageFile);
int width = len(a);
int height = len(a[0]);
char c = intensityToChar(255);
println(c);
println(width);
println(height);
int i;
int j;
char px;
for(i = 0; i < width; i = i + 1) {
for(j = 0; j < height; j = j + 1) {
px = intensityToChar(a[i][j]);
b[i][j] = px;
}
}
return b;
}
char[][] impose(char[][] asciiArt, int[][] edges, char edgeChar){
int width = len(asciiArt);
int height = len(asciiArt[0]);
int i;
int j;
for(i = 0; i < width; i = i + 1){
for( j = 0; j < height; j = j + 1){
if( edges[i][j] == 1 ){
asciiArt[i][j] = edgeChar;
print( edgeChar );
}
else{
print( asciiArt[i][j] );
}
}
println(" ");
}
return asciiArt;
}