7 people like it.

ASCII Art

Blow up words to ASCII art with this 5x5 font

 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: 
let chars = [|
    [|0b01110;0b11110;0b01111;0b11110;0b11111;0b11111;0b01111;0b10001;0b01110;0b11111;0b10001;0b10000;0b10001;0b10001;0b01110;0b11110;0b01110;0b11110;0b01111;0b11111;0b10001;0b10001;0b10001;0b10001;0b10001;0b11111|]
    [|0b10001;0b10001;0b10000;0b10001;0b10000;0b10000;0b10000;0b10001;0b00100;0b00001;0b10010;0b10000;0b11011;0b11001;0b10001;0b10001;0b10001;0b10001;0b10000;0b00100;0b10001;0b10001;0b10001;0b01010;0b01010;0b00010|]
    [|0b11111;0b11110;0b10000;0b10001;0b11110;0b11110;0b10011;0b11111;0b00100;0b00001;0b11100;0b10000;0b10101;0b10101;0b10001;0b11110;0b10001;0b11110;0b01110;0b00100;0b10001;0b10001;0b10101;0b00100;0b00100;0b00100|]
    [|0b10001;0b10001;0b10000;0b10001;0b10000;0b10000;0b10001;0b10001;0b00100;0b10001;0b10010;0b10000;0b10001;0b10011;0b10001;0b10000;0b10010;0b10001;0b00001;0b00100;0b10001;0b01010;0b10101;0b01010;0b00100;0b01000|]
    [|0b10001;0b11110;0b01111;0b11110;0b11111;0b10000;0b01110;0b10001;0b01110;0b01110;0b10001;0b11111;0b10001;0b10001;0b01110;0b10000;0b01101;0b10001;0b11110;0b00100;0b01110;0b00100;0b01010;0b10001;0b00100;0b11111|]
    |]

let toAsciiArt (s:string) =
    let sb = System.Text.StringBuilder()
    let unpack c bits =
        for x = 0 to 4 do               
            if bits &&& (1 <<< (4-x)) <> 0 then c else ' '
            |> sb.Append |> ignore                            
    sb.AppendLine() |> ignore
    for line in chars do
        for i = 0 to s.Length-1 do
            let c = s.[i]
            if c >= 'A' && c <= 'Z' 
            then line.[int c - int 'A'] |> unpack c
            else sb.Append("    ") |> ignore
            sb.Append(' ') |> ignore
        sb.AppendLine() |> ignore
    sb.ToString()

System.String([|'A'..'Z'|]) |> toAsciiArt

"HELLO WORLD" |> toAsciiArt
(*
H   H EEEEE L     L      OOO       W   W  OOO  RRRR  L     DDDD  
H   H E     L     L     O   O      W   W O   O R   R L     D   D 
HHHHH EEEE  L     L     O   O      W W W O   O RRRR  L     D   D 
H   H E     L     L     O   O      W W W O   O R   R L     D   D 
H   H EEEEE LLLLL LLLLL  OOO        W W   OOO  R   R LLLLL DDDD 
*)
val chars : int [] []

Full name: Script.chars
val toAsciiArt : s:string -> string

Full name: Script.toAsciiArt
val s : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val sb : System.Text.StringBuilder
namespace System
namespace System.Text
Multiple items
type StringBuilder =
  new : unit -> StringBuilder + 5 overloads
  member Append : value:string -> StringBuilder + 18 overloads
  member AppendFormat : format:string * arg0:obj -> StringBuilder + 4 overloads
  member AppendLine : unit -> StringBuilder + 1 overload
  member Capacity : int with get, set
  member Chars : int -> char with get, set
  member Clear : unit -> StringBuilder
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EnsureCapacity : capacity:int -> int
  member Equals : sb:StringBuilder -> bool
  ...

Full name: System.Text.StringBuilder

--------------------
System.Text.StringBuilder() : unit
System.Text.StringBuilder(capacity: int) : unit
System.Text.StringBuilder(value: string) : unit
System.Text.StringBuilder(value: string, capacity: int) : unit
System.Text.StringBuilder(capacity: int, maxCapacity: int) : unit
System.Text.StringBuilder(value: string, startIndex: int, length: int, capacity: int) : unit
val unpack : (char -> int -> unit)
val c : char
val bits : int
val x : int
System.Text.StringBuilder.Append(value: char []) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Append(value: obj) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Append(value: uint64) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Append(value: uint32) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Append(value: uint16) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Append(value: decimal) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Append(value: float) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Append(value: float32) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Append(value: int64) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Append(value: int) : System.Text.StringBuilder
   (+0 other overloads)
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
System.Text.StringBuilder.AppendLine() : System.Text.StringBuilder
System.Text.StringBuilder.AppendLine(value: string) : System.Text.StringBuilder
val line : int []
val i : int
property System.String.Length: int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
System.Text.StringBuilder.ToString() : string
System.Text.StringBuilder.ToString(startIndex: int, length: int) : string
Multiple items
type String =
  new : value:char -> string + 7 overloads
  member Chars : int -> char
  member Clone : unit -> obj
  member CompareTo : value:obj -> int + 1 overload
  member Contains : value:string -> bool
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EndsWith : value:string -> bool + 2 overloads
  member Equals : obj:obj -> bool + 2 overloads
  member GetEnumerator : unit -> CharEnumerator
  member GetHashCode : unit -> int
  ...

Full name: System.String

--------------------
System.String(value: nativeptr<char>) : unit
System.String(value: nativeptr<sbyte>) : unit
System.String(value: char []) : unit
System.String(c: char, count: int) : unit
System.String(value: nativeptr<char>, startIndex: int, length: int) : unit
System.String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
System.String(value: char [], startIndex: int, length: int) : unit
System.String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: System.Text.Encoding) : unit
Raw view Test code New version

More information

Link:http://fssnip.net/jS
Posted:10 years ago
Author:Phillip Trelford
Tags: ascii