| 97 | } |
| 98 | |
| 99 | function update_framebuffer(width, height, data, start_y, updated_height) { |
| 100 | for (let y=start_y; y < start_y + updated_height; y++) { |
| 101 | let row = Array(width); |
| 102 | let old_row = row.join(""); |
| 103 | for (let x=0; x < width; x++) { |
| 104 | let index = (y * width + x) * 4; |
| 105 | let r = data[index]; |
| 106 | let g = data[index+1]; |
| 107 | let b = data[index+2]; |
| 108 | let avg = (r + g + b) / 3; |
| 109 | //let avg = (x/width) * 255; // (uncomment for a gradient test) |
| 110 | |
| 111 | //note - these ascii characters were all picked because they have the same width in the sans-serif font that chrome decided to use for text fields |
| 112 | if (avg > 200) |
| 113 | row[x] = "_"; |
| 114 | else if (avg > 150) |
| 115 | row[x] = "::"; |
| 116 | else if (avg > 100) |
| 117 | row[x] = "?"; |
| 118 | else if (avg > 50) |
| 119 | row[x] = "//"; |
| 120 | else if (avg > 25) |
| 121 | row[x] = "b"; |
| 122 | else |
| 123 | row[x] = "#"; |
| 124 | } |
| 125 | let row_str = row.join(""); |
| 126 | if (row_str !== old_row) |
| 127 | globalThis.getField("field_"+(height-y-1)).value = row_str; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | var key_to_input_map = { |
| 132 | "Esc": 0x01, "1": 0x02, "2": 0x03, "3": 0x04, "4": 0x05, "5": 0x06, "6": 0x07, |