Skip to content
Oeiuwq Faith Blog OpenSource Porfolio

wi101/embroidery

null

wi101/embroidery.json
{
"createdAt": "2018-01-31T22:12:24Z",
"defaultBranch": "master",
"description": null,
"fullName": "wi101/embroidery",
"homepage": null,
"language": "Scala",
"name": "embroidery",
"pushedAt": "2023-03-11T08:55:12Z",
"stargazersCount": 61,
"topics": [],
"updatedAt": "2024-11-29T13:57:10Z",
"url": "https://github.com/wi101/embroidery"
}

You can add an artistic touch to your console.

To use embroidery, add the following line in your build.sbt file:

libraryDependencies += "com.github.wi101" %% "embroidery" % "0.1.1"
  1. Convert your text to ASCII Art: title.asciiArt returns a String that you can display or use in your project. Or you can use the syntax title.toAsciiArt.
import embroidery.title
title.asciiArt("Hello world")

Or:

import embroidery._
"Hello".toAsciiArt

Output:

# # # # # # # # #
# # # # # # # # # #
# # ### # # ### # # # # ### # # # ## #
# # # # # # # # # # # # # # ## # # ##
####### # # # # # # # # # # # # # # # #
# # ##### # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # ##
# # ### # # ### # # ### # # ## #

You can specify the spaces between the character. For example, if you would like to display S c a l a, you can call:

import embroidery.title
title.asciiArt("Scala", art = 'S', spaces = 1)

Or

import embroidery._
"Scala".toAsciiArt(art = 'S', spaces = 1)

Output:

SS
SS
SSSS SSSSS SSSSS SS SSSSS
SSSSS SSSSSS SSSSS SS SSSSS
SSS SSS SS SS SS
SSSS SSS SSSSS SS SSSSS
SSSS SSS SSS SS SS SSS SS
SS SSS SSSSSS SSSSSS SS SSSSSS
SSSSS SSSSS SSSSSSS SS SSSSSSS
SS SS S S S S

WARNNG: The title should be short to be able to display it in your screen (maximum 20 characters including spaces).

  1. Convert your LOGO to ASCII Art:

You can get the Ascii Art of your icons using logo.asciiArt method. Or you can use the syntax logoPath.toAsciiArt.

import embroidery.logo
logo.asciiArt("src/test/scala/embroidery/asciiArt/logos/images/pikachu.png")

OR

import embroidery._
ImagePath("src/test/scala/embroidery/asciiArt/logos/images/pikachu.png").toAsciiArt
pikachu.pngresult with ASCII Art
pikachupikachu
import embroidery.logo
logo.asciiArt("src/test/scala/embroidery/asciiArt/logos/images/zio.png")

OR

import embroidery._
ImagePath("src/test/scala/embroidery/asciiArt/logos/images/zio.png").toAsciiArt
zio.pngresult with ASCII Art
ziozio
import embroidery.logo
logo.asciiArt("src/test/scala/embroidery/asciiArt/logos/images/scala.jpg")

OR

import embroidery._
ImagePath("src/test/scala/embroidery/asciiArt/logos/images/scala.jpg").toAsciiArt
scala.jpgresult with ASCII Art
scalascala

You can also decide which characters to use on each brightness level:

import embroidery._
val pixelsWithArt: List[PixelAsciiArt] = List(
PixelAsciiArt(Pixel(255), Art(' ')),
PixelAsciiArt(Pixel(0), Art('#'))
)
val img: String = ImagePath("src/test/scala/embroidery/asciiArt/images/zio.png").toAsciiArt(pixelsWithArt)
val s = img.flatMap(
c =>
if (c != ' ' && c != '\n')
Console.RED + c.toString + Console.RESET
else c.toString
)
println(s)

Output:

Screen Shot 2020-07-25 at 3 52 02 PM

You can also control the size of your logo:

import embroidery._
val pixelsWithArt: List[PixelAsciiArt] = List(
PixelAsciiArt(Pixel(255), Art(' ')),
PixelAsciiArt(Pixel(230), Art('.')),
PixelAsciiArt(Pixel(220), Art(',')),
PixelAsciiArt(Pixel(210), Art('°')),
PixelAsciiArt(Pixel(200), Art('²')),
PixelAsciiArt(Pixel(190), Art('*')),
PixelAsciiArt(Pixel(180), Art('^')),
PixelAsciiArt(Pixel(170), Art('~')),
PixelAsciiArt(Pixel(150), Art('/')),
PixelAsciiArt(Pixel(140), Art('|')),
PixelAsciiArt(Pixel(130), Art('s')),
PixelAsciiArt(Pixel(120), Art('q')),
PixelAsciiArt(Pixel(90), Art('µ')),
PixelAsciiArt(Pixel(70), Art('@')),
PixelAsciiArt(Pixel(0), Art('#'))
)
val img = logo.asciiArt(
"src/test/scala/embroidery/asciiArt/images/scala.jpg",
pixelsWithArt,
100,
50
)
// The same as: ImagePath("...").toAsciiArt(pixelsWithArt, 100, 50)
val scala = img.flatMap(
c =>
if (c != ' ' && c != '\n')
Console.RED + c.toString + Console.RESET
else c.toString
)
println(scala)

Output:

Screen Shot 2020-07-25 at 4 29 18 PM

Note: The valid format of the pictures are: jpg, jpeg, png, bmp