↓ ↑ ↑ ↙ ←
↙ ← ↓ ↓ ↙ ↓ ↓
↘ ↙ ↑ ↑ ↑ → ← → → ↘
↑ ↗ ↘ ↓ ← ↖ ↑ ↘ ↖ ↙ ↓
↘ ↑ ↙ ← ↘ ↖ ↗ ↘ ↑ ↓ ↘ ← ↓
↗ ↖ ↘ ↘ ↑ → ↓ ↖ ↓ ↗ ↙ ↖ ↗ ↗
↑ ↘ ↓ ↑ ↑ ← → → ↗ ↘ ↑ ↘ ↓ ↓
↑ ↑ ↘ ↗ ↗ ↗ ↓ ↑ ← ← ↑ ↘ ↓ → ↙ ↑
↓ ↖ ↗ ↖ ↓ ↙ ↗ ↑ ↖ ↗ → ↗ ↓ → ↘ ↖
→ ← ↙ ↖ ← ↘ ↑ ↓ ↙ ↑ ↑ ↘ ↗ ↘ ↓ ↑ ↖
↑ ← ↑ ↗ ↑ ↑ → ↖ → ← ↖ ↖ ↖ ↑ ← ← ↖ ↓
↙ ← → ↗ ↗ → ↘ ↗ ↑ ↗ ↑ ↘ ↑ ↙ ← ↓ ↑
← ↗ ↙ ↑ ↖ ↖ ↗ ↖ ↓ → ↙ ↓ ↓ ↗ ↘ → ↗ ↘ ↙
→ ↗ ← ↗ ↖ ← ← ↗ ↙ ↗ ↘ ↙ ↓ → ↗ ↓ ↙ ↙
← ↖ ← → ↘ ← ↗ ← ← ↘ ↗ ↙ ↘ ← ↓ ↗ ↖ ↓ ↖
↗ ← ↘ ↓ ← ↓ ↓ ↑ ↓ → → → ↖ → ↑ ↖ → ↓ ↘ ↑
← ← ↙ ← → ↗ ↗ ↓ ↑ ↘ ↗ → ↓ → → ↘ → ↙ ←
↘ ↙ ↙ → ↖ ↓ → ↓ ↑ ↓ ↙ ↗ ↘ ↙ ↗ ↗ ← ↖ ↙ ↗
↓ ← ↘ ← ↗ ↗ ← ↓ ↘ ↑ ↓ → ↙ ↘ ↓ ← ← → ↓
↙ ↘ ↗ ↗ ↖ ↑ ↗ ↙ ↘ ↘ ↘ ← ← ↘ ↙ ↑ ↘ ↗ ← ↓
↑ ↙ ↑ ↘ ← ↗ ↙ ↖ ← ↗ ← ↘ ← → ← ↗ ↑ ↖ ↓
↘ ↘ ↓ ↖ ↑ ↙ ↘ ↖ ← ↑ ↙ ↗ ↘ ↑ ↑ ↗ ↘ ↗ → ↗
↖ ↖ ↓ ↙ ← → ↙ ↙ ↙ → → ↖ → ↗ ↑ ← ← ↑ ↗
→ ↖ ↗ ↓ → ← → → → ↖ ↑ → → ← ↙ ↘ ← ↑ ↖ →
↖ ↙ → ↓ → → ↘ ↙ ↓ ← ↑ ↙ ↗ ↗ → ↗ ↗ ↓ ↑
← ← → ↖ ↓ ↓ ↖ ↑ → → ↘ ↑ ↖ ↖ ↗ ↗ ↓ ←
↓ ↘ ↖ ↑ ↘ ↙ ↗ ← ← → ↖ ← ↗ ↘ ↓ ↑ ↓ ↑ ↑
↘ ↗ ↑ ↖ ↘ ↘ → ↘ ↑ ↙ ↖ ↘ ← → ↗ ↘ ↘
↖ → ↓ ↙ ↓ ↗ ↙ ← → ↑ ↓ ↓ ↑ ↙ ← ↓ ← ↙
→ ↑ ↓ ← ↑ ↘ ↗ ↘ ↗ ↖ ↓ → ↘ → ↗ → ←
→ ↗ ← ↖ ↘ ↘ → ↖ ↗ ← → ← ↙ → ↙ ↗
→ ↗ → ← ← ↑ → ↓ ↖ ↘ ← ↖ ↙ ↑ ← ↗
↙ ↖ ↓ ↙ ← → ↗ ← ↘ ↓ ↘ ← ↖ ↙
↖ ↗ → ↑ ↘ ↙ ↑ ↓ ↑ ↖ ↙ ↗ ↑ ←
← ↙ ↗ ↙ ↑ ↙ ↖ ↖ → ← ↘ ↖ →
↘ ↓ ↓ ↙ ↙ ← ↘ ↑ ↗ ← ↖
↗ ↖ ↑ ↑ ↙ ↑ ↗ ↙ ↙ ↓
↑ ← ↗ ↓ ↖ ↘ ←
← ↗ ↑ ↓ ↖
// Inescapable Spiral by VES3L // written in Typescript for node
import process from "process";
abstract class Sym { abstract cell(): string; }
const Dirs = ["←", "↙", " ↓ ", "↘", →, "↗", ↑, "↖"];
class DirsSym extends Sym { dir: number;
constructor(dir: number) { super();
this.dir = dir;
}
cell() { if (this.dir <= 0) return " "; return Dirs[Math.floor(Math.random() * Dirs.length)]; } }
function twoDtoOneD(x: number, y: number, width: number) { return y * width + x; }
class Grid { _grid: Array<Sym>; w: number; h: number;
constructor(w: number, h: number) { this.w = w; this.h = h; this._grid = new Array<Sym>(this.w * this.h); this.init(); }
print() { for (let y = 0; y < this.w; y++) { for (let x = 0; x < this.h; x++) { process.stdout.write(this._grid[this.twoDtoOneD(x, y)].cell() + " "); } process.stdout.write("\n"); } }
twoDtoOneD(x: number, y: number) { return twoDtoOneD(x, y, this.w); }
init() { for (let y = 0; y < this.w; y++) { for (let x = 0; x < this.h; x++) { const normX = (x / this.h) * 2 - 1; const normY = (y / this.w) * 2 - 1;
const dNorm = Math.sqrt(Math.pow(normX, 2) + Math.pow(normY, 2));
if (dNorm < 0.98) {
let d = Math.sqrt(Math.pow(normX, 2) + Math.pow(normY, 2)) * 50;
const a = Math.atan2(normX, normX);
d = Math.atan2(Math.cos(d + a), Math.sin(d + a));
this._grid[this.twoDtoOneD(x, y)] = new DirsSym(
Math.floor(Math.abs(d / 3.14) * 2) % 2
);
} else {
this._grid[this.twoDtoOneD(x, y)] = new DirsSym(0);
}
}
}
} }
function draw() { const grid = new Grid(40, 40); grid.print(); }
draw();