Skip to content

Instantly share code, notes, and snippets.

@tobyweston
Created April 15, 2018 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyweston/beadc82346a93549474d8024affd1c56 to your computer and use it in GitHub Desktop.
Save tobyweston/beadc82346a93549474d8024affd1c56 to your computer and use it in GitHub Desktop.
Rainbow text
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