import { IntegerPoint as Point, IntegerSize as Size, Rect, } from "./geometry.js"; export class Console { #screen: Cell[]; #size: Size; constructor(size: Size) { const length = size.width * size.height; this.#size = size this.#screen = new Array(length); for (let i = 0; i < length; i++) { this.#screen[i] = new Cell(' ') } } drawInRect(rect: Rect) { const cellSize = new Size( rect.size.width / this.#size.width, rect.size.height / this.#size.height ); for (let y = 0; y < this.#size.height; y++) { for (let x = 0; x < this.#size.width; x++) { const pt = new Point(x, y); const character = this.characterAt(pt); } } } characterAt(pt: Point) { return this.#cellAt(pt).character; } #cellAt(pt: Point): Cell { return this.#screen[this.#size.width * pt.y + pt.x]; } } export class Color { red: number; green: number; blue: number; constructor(r: number, g: number, b: number) { this.red = Math.min(1, Math.max(0, r)); this.green = Math.min(1, Math.max(0, g)); this.blue = Math.min(1, Math.max(0, b)); } } export class Cell { character: String; foregroundColor: Color; backgroundColor?: Color; constructor(character: String, foregroundColor?: Color, backgroundColor?: Color) { this.character = character ? character : " "; this.foregroundColor = foregroundColor ? foregroundColor : new Color(1, 1, 1); this.backgroundColor = backgroundColor; } }