mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-02-16 09:29:13 +01:00
🐃 finishing BrailleBuffer!
This commit is contained in:
parent
719b099cdc
commit
a3fb7149f2
@ -20,6 +20,9 @@ module.exports = class BrailleBuffer
|
|||||||
charBuffer: null
|
charBuffer: null
|
||||||
colorBuffer: null
|
colorBuffer: null
|
||||||
|
|
||||||
|
termReset: "\x1B[39m"
|
||||||
|
termColor: (color) -> "\x1B[38;5;#{color}m"
|
||||||
|
|
||||||
constructor: (@width, @height) ->
|
constructor: (@width, @height) ->
|
||||||
@pixelBuffer = new Buffer @width*@height/8
|
@pixelBuffer = new Buffer @width*@height/8
|
||||||
@clear()
|
@clear()
|
||||||
@ -32,47 +35,55 @@ module.exports = class BrailleBuffer
|
|||||||
setPixel: (x, y, color) ->
|
setPixel: (x, y, color) ->
|
||||||
@_locate x, y, (idx, mask) =>
|
@_locate x, y, (idx, mask) =>
|
||||||
@pixelBuffer[idx] |= mask
|
@pixelBuffer[idx] |= mask
|
||||||
@colorBuffer[(x>>1)+(y*@height<<2)] = @termColor color
|
@colorBuffer[idx] = @termColor color
|
||||||
|
|
||||||
unsetPixel: (x, y) ->
|
unsetPixel: (x, y) ->
|
||||||
@_locate x, y, (idx, mask) =>
|
@_locate x, y, (idx, mask) =>
|
||||||
@pixelBuffer[idx] &= ~mask
|
@pixelBuffer[idx] &= ~mask
|
||||||
|
|
||||||
|
_project: (x, y) ->
|
||||||
|
(x>>1) + (@width>>1)*(y>>2)
|
||||||
|
|
||||||
_locate: (x, y, cb) ->
|
_locate: (x, y, cb) ->
|
||||||
return unless 0 <= x < @width and 0 <= y < @height
|
return unless 0 <= x < @width and 0 <= y < @height
|
||||||
idx = (x>>1) + (@width>>1)*(y>>2)
|
idx = @_project x, y
|
||||||
mask = @characterMap[y&3][x&1]
|
mask = @characterMap[y&3][x&1]
|
||||||
cb idx, mask
|
cb idx, mask
|
||||||
|
|
||||||
frame: ->
|
frame: ->
|
||||||
output = []
|
output = []
|
||||||
|
currentColor = null
|
||||||
delimeter = "\n"
|
delimeter = "\n"
|
||||||
color = null
|
|
||||||
|
|
||||||
for idx in [0...@pixelBuffer.length]
|
for idx in [0...@pixelBuffer.length]
|
||||||
output.push delimeter unless idx % (@width/2)
|
output.push delimeter unless idx % (@width/2)
|
||||||
|
|
||||||
if @charBuffer[idx]
|
if currentColor isnt colorCode = @colorBuffer[idx] or @termReset
|
||||||
output.push @charBuffer[idx]
|
output.push currentColor = colorCode
|
||||||
else if @pixelBuffer[idx] is 0
|
|
||||||
output.push ' '
|
|
||||||
else
|
|
||||||
output.push color = colorCode if color isnt colorCode = @colorBuffer[idx] or "\x1B[39m"
|
|
||||||
output.push String.fromCharCode 0x2800+@pixelBuffer[idx]
|
|
||||||
|
|
||||||
output.push "\x1B[39m"+delimeter
|
output.push if @charBuffer[idx]
|
||||||
|
@charBuffer[idx]
|
||||||
|
else if @pixelBuffer[idx] is 0
|
||||||
|
' '
|
||||||
|
else
|
||||||
|
String.fromCharCode 0x2800+@pixelBuffer[idx]
|
||||||
|
|
||||||
|
output.push @termReset+delimeter
|
||||||
output.join ''
|
output.join ''
|
||||||
|
|
||||||
termColor: (color) ->
|
setChar: (char, x, y, color) ->
|
||||||
"\x1B[38;5;#{color}m"
|
|
||||||
|
|
||||||
setChar: (char, color, x, y) ->
|
|
||||||
return unless 0 <= x < @width/2 and 0 <= y < @height/4
|
return unless 0 <= x < @width/2 and 0 <= y < @height/4
|
||||||
idx = x+y*@width/2
|
idx = @_project x, y
|
||||||
@charBuffer[idx] = char
|
@charBuffer[idx] = char
|
||||||
@colorBuffer[idx] = color
|
@colorBuffer[idx] = @termColor color
|
||||||
|
|
||||||
buffer = new BrailleBuffer 100, 16
|
writeText: (text, x, y, color, center = true) ->
|
||||||
for i in [0...100]
|
x -= text.length/2 if center
|
||||||
buffer.setPixel i, 8+8*Math.cos(i/10*Math.PI/2), i>>2
|
@setChar text.charAt(i), x+i*2, y, color for i in [0...text.length]
|
||||||
console.log buffer.frame()
|
|
||||||
|
# buffer = new BrailleBuffer 100, 16
|
||||||
|
# for i in [0...255]
|
||||||
|
# buffer.setPixel i, 8+8*Math.cos(i/10*Math.PI/2), i
|
||||||
|
#
|
||||||
|
# buffer.writeText "ruth", 10, 0, 111
|
||||||
|
# console.log buffer.frame()
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
VectorTile = require('vector-tile').VectorTile
|
VectorTile = require('vector-tile').VectorTile
|
||||||
Protobuf = require 'pbf'
|
Protobuf = require 'pbf'
|
||||||
zlib = require 'zlib'
|
zlib = require 'zlib'
|
||||||
Rbush = require('rbush')
|
Rbush = require 'rbush'
|
||||||
|
|
||||||
module.exports = class Tile
|
module.exports = class Tile
|
||||||
tree: null
|
tree: null
|
||||||
|
Loading…
Reference in New Issue
Block a user