kopia lustrzana https://github.com/ertdfgcvb/play.core
Change gray range from 0-255 to 0-1
rodzic
a16b243a4e
commit
59b1a31b7f
|
@ -15,15 +15,15 @@ C64 and CGA palettes are exported as arrays
|
||||||
|
|
||||||
Colors in exported palettes are augmented to:
|
Colors in exported palettes are augmented to:
|
||||||
{
|
{
|
||||||
name: 'red',
|
name : 'red',
|
||||||
r: 255,
|
r : 255, // 0-255 (as in CSS)
|
||||||
g: 0,
|
g : 0, // 0-255 (as in CSS)
|
||||||
b: 0,
|
b : 0, // 0-255 (as in CSS)
|
||||||
a: 1.0,
|
a : 1.0, // 0-1 (as in CSS)
|
||||||
gray: 54,
|
gray : 0.6, // 0-1 (custom)
|
||||||
hex: '#FF0000',
|
hex : '#FF0000',
|
||||||
css: 'rgb(255,0,0)'
|
css : 'rgb(255,0,0)'
|
||||||
int: 16711680,
|
int : 16711680
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -74,9 +74,9 @@ export function rgb2hex(rgb) {
|
||||||
return '#' + r + g + b + a
|
return '#' + r + g + b + a
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert {r,g,b} values to gray value [0-255]
|
// Convert {r,g,b} values to gray value [0-1]
|
||||||
export function rgb2gray(rgb) {
|
export function rgb2gray(rgb) {
|
||||||
return Math.round(rgb.r * 0.2126 + rgb.g * 0.7152 + rgb.b * 0.0722)
|
return Math.round(rgb.r * 0.2126 + rgb.g * 0.7152 + rgb.b * 0.0722) / 255.0
|
||||||
}
|
}
|
||||||
|
|
||||||
// hex is not a string but an int number
|
// hex is not a string but an int number
|
||||||
|
|
|
@ -53,7 +53,7 @@ const black = {
|
||||||
g : 0,
|
g : 0,
|
||||||
b : 0,
|
b : 0,
|
||||||
a : 1.0,
|
a : 1.0,
|
||||||
gray : 0
|
gray : 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ImageBuffer {
|
export class ImageBuffer {
|
||||||
|
@ -189,7 +189,6 @@ export class ImageBuffer {
|
||||||
return this.buffer[x + y * this.canvas.width]
|
return this.buffer[x + y * this.canvas.width]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Debug -------------------------------------------------------------------
|
// Debug -------------------------------------------------------------------
|
||||||
|
|
||||||
// Attaches the canvas to a target element for debug purposes
|
// Attaches the canvas to a target element for debug purposes
|
||||||
|
@ -274,8 +273,9 @@ function toBuffer(canvas, out){
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use this or import 'rgb2gray' from color.js
|
||||||
// https://en.wikipedia.org/wiki/Grayscale
|
// https://en.wikipedia.org/wiki/Grayscale
|
||||||
function toGray(r,g,b) {
|
function toGray(r, g, b) {
|
||||||
return Math.round(r * 0.2126 + g * 0.7152 + b * 0.0722) / 255.0
|
return Math.round(r * 0.2126 + g * 0.7152 + b * 0.0722) / 255.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,16 @@ pal.push(CSS3.lightblue)
|
||||||
|
|
||||||
export function pre(context, cursor, buffers){
|
export function pre(context, cursor, buffers){
|
||||||
// Double the height of the camera image
|
// Double the height of the camera image
|
||||||
const ctxSizes = {cols : context.cols, rows : context.rows * 2}
|
const newSize = {
|
||||||
cam.cover({...context, ...ctxSizes}, {x:1, y:2}).quantize(pal).mirrorX().write(buffers.data)
|
cols : context.cols,
|
||||||
|
rows : context.rows * 2
|
||||||
|
}
|
||||||
|
// Adjust the scale to compensate
|
||||||
|
const adjustedScale = {
|
||||||
|
x:1,
|
||||||
|
y:2
|
||||||
|
}
|
||||||
|
cam.cover({...context, ...newSize}, adjustedScale).quantize(pal).mirrorX().write(buffers.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function main(coord, context, cursor, buffers){
|
export function main(coord, context, cursor, buffers){
|
||||||
|
|
|
@ -21,7 +21,7 @@ export function pre(context, cursor, buffers){
|
||||||
export function main(coord, context, cursor, buffers){
|
export function main(coord, context, cursor, buffers){
|
||||||
// Coord also contains the index of each cell:
|
// Coord also contains the index of each cell:
|
||||||
const color = buffers.data[coord.index]
|
const color = buffers.data[coord.index]
|
||||||
const index = Math.floor(color.gray / 255.0 * (density.length-1))
|
const index = Math.floor(color.gray * (density.length-1))
|
||||||
return density[index]
|
return density[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ export function main(coord, context, cursor, buffers){
|
||||||
// Coord also contains the index of each cell
|
// Coord also contains the index of each cell
|
||||||
const color = buffers.data[coord.index]
|
const color = buffers.data[coord.index]
|
||||||
// Add some chars to the output
|
// Add some chars to the output
|
||||||
const index = Math.floor(color.gray / 255.0 * (density.length-1))
|
const index = Math.floor(color.gray * (density.length-1))
|
||||||
return {
|
return {
|
||||||
char : density[index],
|
char : density[index],
|
||||||
color : 'white',
|
color : 'white',
|
||||||
|
|
Ładowanie…
Reference in New Issue