Created
April 15, 2018 19:54
-
-
Save tobyweston/beadc82346a93549474d8024affd1c56 to your computer and use it in GitHub Desktop.
Rainbow text
This file contains 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
import Console._ | |
object Text { | |
private val colours = List(RED, YELLOW, GREEN, CYAN, BLUE, MAGENTA) | |
def bonza(string: String): String = GREEN + string + RESET | |
def alter(string: String): String = RED + string + RESET | |
def rainbow(string: String): String = { | |
val rainbow = Stream.continually(colours.toStream).flatten.take(string.length).toList | |
rainbow.zip(string).map { case (colour, character) => colour + character }.mkString("", "", RESET) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment