Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ruby = "676B9C82275548C1B5737C2D9274E02F";
- const emerald = "9B0C8C7B4AB04DAA9786C65D9C7F479A";
- const sapphire = "893AC64565E64403B6BE62831F35CE70"
- const opal = "DA34226AED3B4111BC3BAD312231F633";
- const all = [
- ruby,
- emerald,
- sapphire,
- opal
- ];
- function splitEachN(s: string, n: number): string[] {
- const result = [];
- for (let i = 0; i < s.length; i += n) {
- result.push(s.slice(i, i + n));
- }
- return result;
- }
- function splitPairs(s: string): string[] {
- return splitEachN(s, 2);
- }
- function hexToInt(s: string): number {
- return parseInt(s, 16);
- }
- function intToBinary8(n: number): string {
- const b = (n).toString(2);
- return ("0" as any).repeat(8 - b.length) + b;
- }
- function binaryToInt(s: string): number {
- return parseInt(s, 2);
- }
- function splitNybbles(n: number): number[] {
- return [(n >> 4), n & 0x0f];
- }
- function add(n: number): (v: number) => number {
- return (x: number) => x + n;
- }
- function toAscii(n: number): string {
- return String.fromCharCode(n);
- }
- function compose<A, B, C>(f1: (v: A) => B, f2: (v: B) => C) {
- return (v: A) => {
- return f2(f1(v));
- };
- }
- function mapFunc<A, B>(f: (v: A) => B): ((vs: A[]) => B[]) {
- return (vs: A[]) => {
- return vs.map(f);
- };
- }
- function interleave(s1: string, s2: string, n?: number): string {
- if (s1.length !== s2.length) {
- throw new Error("lengths don't match");
- }
- n = n || 1;
- const chars: string[] = [];
- for (let i = 0; i < s1.length; i += n) {
- chars.push(s1.slice(i, i + n));
- chars.push(s2.slice(i, i + n));
- }
- return chars.join("");
- }
- function flatten<T>(vss: T[][]): T[] {
- const output: T[] = [];
- vss.forEach(vs => {
- vs.forEach(v => output.push(v));
- });
- return output;
- }
- function replace(olds: string, news: string): (v: string) => string {
- return (x => x.replace(olds, news));
- }
- // all.forEach(a => {
- // all.forEach(b => {
- // if (a !== b) {
- // const input = interleave(a, b);
- // // console.log(input);
- // const binary = splitPairs(input).map(hexToInt).map(intToBinary8).join("");
- // console.log(binary.replace(/0/g, " "));
- // // console.log(splitEachN(binary, 7).map(binaryToInt).map(add(32)).map(toAscii).join(""));
- // // console.log("");
- // }
- // });
- // });
- const s = sapphire;
- const o = opal;
- const r = ruby;
- const e = emerald;
- let img = [interleave(interleave(r,o),interleave(s, e), 16)].map(input => {
- return splitPairs(input).map(hexToInt).map(intToBinary8).join("");
- }).join("").replace(/0/g, " ").replace(/1/g, "\u2588");
- //img = ("0123456789abcdefghijklmnopqrstuvwxyz" as any).repeat(20).slice(0, 512);
- const width = 32;
- const height = 16;
- const output: string[][] = splitEachN(("." as any).repeat(width * height) as string, width).map(r => splitEachN(r, 1));
- splitEachN(img, 1).forEach((c, i) => {
- const group = Math.floor(i / 4);
- const offset = i % 4;
- const x = group % width;
- const y = Math.floor(group / width) * 4 + offset;
- output[y][x] = c;
- });
- const rows = output.map(row => row.join(""));
- for (let i = 0; i < rows.length; ++i) {
- const newI = (i * 4) % height + Math.floor(i / 4);
- // console.log(newI);
- const row = rows[newI];
- console.log(row);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement