module BBS::Art::Drawing
How an Art is drawn: as ANSI lines, on a BBS::FrameBuffer, on a BBS::Petscii::Canvas, as a whole PETSCII screen.
Public Instance Methods
Source
# File lib/bbs/art/drawing.rb, line 25 def ansi = ansi_lines.join(Ansi::CRLF)
The ansi_lines joined with CR LF, for writing at the start of a line.
Source
# File lib/bbs/art/drawing.rb, line 10 def ansi_lines @grid.map do |row| line = +'' sgr = nil row.each do |cell| s = Art.sgr(cell) line << s if s != sgr sgr = s line << cell.char end line << Ansi::RESET end end
The art as lines of 256-colour ANSI: each line starts with its own colours and ends with a reset, so a line can be written anywhere.
Source
# File lib/bbs/art/drawing.rb, line 64 def canvas = draw_canvas(Petscii::Canvas.new)
A new BBS::Petscii::Canvas with the art drawn at its top left.
# File lib/bbs/art/drawing.rb, line 32 def draw(frame, x: 1, y: 1, width: @cols, height: @rows) [height, @rows].min.times do |r| [width, @cols].min.times do |c| cell = @grid[r][c] plain = cell.fg.nil? && cell.bg.nil? && !cell.rvs frame.move(x + c, y + r) frame.write(cell.char, sgr: plain ? nil : Art.sgr(cell)) end end frame end
Draws the art on frame, a BBS::FrameBuffer, with its top left at x, y (1-based), cut to width × height cells (default the whole art) and to the buffer. A cell with no colours gets no style.
Returns frame.
# File lib/bbs/art/drawing.rb, line 50 def draw_canvas(canvas, row: 0, col: 0) raise ArgumentError, "#{@path}: a #{@charset} art does not go on a C64 canvas" unless petscii? @grid.each_with_index do |cells, r| cells.each_with_index do |cell, c| code, reversed = Petscii::Canvas.code(cell.char) color = cell.fg ? cell.fg.c64 : Petscii::Canvas::LIGHT_GREY canvas.put(row + r, col + c, code, color, rvs: cell.rvs ^ reversed) end end canvas end
Draws the art on canvas, a BBS::Petscii::Canvas, with its top left at row, col (0-based); cells off the screen are cut. A visible cell with no colour is light grey, the C64’s text colour. Raises ArgumentError for a cp437 art.
Returns canvas.
Source
# File lib/bbs/art/drawing.rb, line 68 def petscii = canvas.frame
The raw PETSCII of the whole screen with the art on it (the canvas’s frame), a binary String to send with session.write_raw.