-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangleBuilder.kt
47 lines (40 loc) · 1.11 KB
/
RectangleBuilder.kt
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
package seamcarving
import utils.Prompt
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
class RectangleBuilder {
private var width: Int = 0
private var height: Int = 0
private lateinit var image: BufferedImage
fun getDetails() {
println(Prompt.ENTER_WIDTH.text)
width = readln().toInt()
println(Prompt.ENTER_HEIGHT.text)
height = readln().toInt()
}
fun createImage() {
image = BufferedImage(width, height, BufferedImage.TYPE_INT_BGR)
}
fun drawRectangles() {
image.createGraphics().apply {
color = Color.red
drawLine(0, 0, image.width - 1, image.height - 1)
drawLine(0, image.height - 1, image.width - 1, 0)
}
}
fun saveImage() {
println(Prompt.ENTER_NAME.text)
val name = readln()
val outputFile = File(name)
ImageIO.write(image, "png", outputFile)
}
}
fun main() {
val image = RectangleBuilder()
image.getDetails()
image.createImage()
image.drawRectangles()
image.saveImage()
}