-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageMethods.kt
More file actions
68 lines (59 loc) · 1.76 KB
/
Copy pathimageMethods.kt
File metadata and controls
68 lines (59 loc) · 1.76 KB
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
package termImage
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
class imageMethods(){
private val dir = System.getProperty("user.home") + "/Desktop/"
private var char:String? = null
var image: BufferedImage
init {
println("Enter image name:")
val name = readln()
image = ImageIO.read(File("${dir}${name}"))
}
fun charImage(chr: String){
char = chr
for (h in 0 until image.height){
for (w in 0 until image.width){
val col = Color(image.getRGB(w,h))
printImage(col)
}
println()
}
}
fun negativeImage(){
for (h in 0 until image.height){
for (w in 0 until image.width){
val col = Color(image.getRGB(w,h))
val negative = Color(255 - col.red, 255 - col.green, 255 - col.blue)
printImage(negative)
}
println()
}
}
fun greyScaleImage(){
for (h in 0 until image.height){
for (w in 0 until image.width){
val col = Color(image.getRGB(w,h))
val average = (col.red + col.green + col.blue) / 3
val greyscale = Color(average, average, average)
printImage(greyscale)
}
println()
}
}
fun normalImage() {
for (h in 0 until image.height){
for (w in 0 until image.width){
val col = Color(image.getRGB(w, h))
printImage(col)
}
println()
}
}
fun printImage(rgb: Color){
char = char ?:"██"
print("\u001b[38;2;${rgb.red};${rgb.green};${rgb.blue}m${char}")
}
}