Created
February 16, 2023 00:06
-
-
Save D0zee/43994c7ec85cdbd2f57f3b32c8f482cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun applyBordersFilter(picture: String): String { | |
| val lines = picture.lines() | |
| .map { it.trimIndent() } | |
| .filter { it.isNotEmpty() } | |
| val width = lines.maxOf { it.length } + 1 | |
| val pic = lines | |
| .map { SEPARATOR + it + SEPARATOR.toString().repeat(width - it.length) } | |
| .map { BORDER_SYMBOL + it + BORDER_SYMBOL } | |
| .joinToString(System.lineSeparator()) + System.lineSeparator() | |
| val newWidth = pic.lines().maxBy { it.length }.length | |
| val stringOfBorderSymbol = BORDER_SYMBOL.toString().repeat(newWidth) + System.lineSeparator() | |
| return "$stringOfBorderSymbol$pic$stringOfBorderSymbol" | |
| } | |
| fun applySquaredFilter(picture: String): String { | |
| var borderImageLines = applyBordersFilter(picture).lines() | |
| .filter { it.isNotEmpty() } | |
| .map { it + it } | |
| val newImage = borderImageLines.toMutableList() | |
| borderImageLines = borderImageLines.drop(1) | |
| return newImage.joinToString(System.lineSeparator()) + System.lineSeparator() + borderImageLines.joinToString( | |
| System.lineSeparator() | |
| ) + System.lineSeparator() | |
| } | |
| fun applyFilter(picture: String, filter: String): String { | |
| return if (filter == "borders") applyBordersFilter(picture) | |
| else applySquaredFilter(picture) | |
| } | |
| fun chooseFilter(): String { | |
| val filters = listOf("squared", "borders") | |
| println("Type filter from this list: $filters") | |
| var ask = readln() | |
| while (ask !in filters) { | |
| println("Type filter from this list: $filters") | |
| ask = readln() | |
| } | |
| return ask | |
| } | |
| fun choosePicture(): String { | |
| var image: String? = null | |
| while (image.isNullOrEmpty()) { | |
| println("Choose from this list: ${allImages.keys}") | |
| val namePic = readln() | |
| image = allImages[namePic] | |
| } | |
| return image | |
| } | |
| fun getPicture(): String { | |
| println("Do you want to choose picture from available pictures or print your picture?") | |
| var noOrYes = readln() | |
| while (noOrYes !in listOf("yes", "no")) { | |
| println("Please type yes or no!") | |
| noOrYes = readln() | |
| } | |
| return if (noOrYes == "yes") { | |
| choosePicture() | |
| } else { | |
| println("Input your picture:") | |
| readln() | |
| } | |
| } | |
| fun photoshop() { | |
| val pic = getPicture() | |
| val filter = chooseFilter() | |
| print(applyFilter(pic, filter)) | |
| } | |
| fun main() { | |
| photoshop() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment