diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-07-15 19:56:39 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-07-15 19:56:39 -0400 |
| commit | 4bd53e69ea016d30147d6cb4c84ae264ab819b55 (patch) | |
| tree | 20478b3bb4606dd22d8313717867305c905ac25b | |
| parent | 31681feba8709707c1042e925399c1530be00c65 (diff) | |
renaming MircColor/color_code.js to photo.js
| -rw-r--r-- | grid5.html | 30 | ||||
| -rw-r--r-- | image.html | 24 | ||||
| -rw-r--r-- | js/clipboard.js | 10 | ||||
| -rw-r--r-- | js/photo.js (renamed from js/color_code.js) | 2 | ||||
| -rw-r--r-- | webcam.html | 12 |
5 files changed, 44 insertions, 34 deletions
@@ -38,8 +38,8 @@ var canvas = new Matrix ( grid_w * 16, grid_h * 16, function(x,y){ var opacity = (x % grid_w) / (grid_w-2) if ( (x % grid_w) != grid_w-gap && (y % grid_h) != grid_h-gap) { - var a = MircColor.colors[ all_hue(i) ] - var b = MircColor.colors[ all_hue(j) ] + var a = Photo.colors[ all_hue(i) ] + var b = Photo.colors[ all_hue(j) ] var a0 = a[0]/255 * opacity var a1 = a[1]/255 * opacity @@ -53,7 +53,7 @@ var canvas = new Matrix ( grid_w * 16, grid_h * 16, function(x,y){ pixel[1] = clamp( a1 + b1, 0, 1 ) * 255 pixel[2] = clamp( a2 + b2, 0, 1 ) * 255 - lex.fg = lex.bg = MircColor.closest_to(pixel) + lex.fg = lex.bg = Photo.closest_to(pixel) lex.char = " " } else if ((y % grid_h) == grid_h-gap) { @@ -82,12 +82,12 @@ var canvas = new Matrix ( grid_w * 16, grid_h * 16, function(x,y){ var j = floor(y / grid_h) if ( (x % grid_w) != grid_w-gap && (y % grid_h) != grid_h-gap) { - var a = MircColor.colors[ all_hue(i) ] - var b = MircColor.colors[ all_hue(j) ] + var a = Photo.colors[ all_hue(i) ] + var b = Photo.colors[ all_hue(j) ] pixel[0] = clamp( a[0]/255 * b[0]/255, 0, 1 ) * 255 pixel[1] = clamp( a[1]/255 * b[1]/255, 0, 1 ) * 255 pixel[2] = clamp( a[2]/255 * b[2]/255, 0, 1 ) * 255 - lex.fg = lex.bg = MircColor.closest_to(pixel) + lex.fg = lex.bg = Photo.closest_to(pixel) lex.char = " " } else if ((y % grid_h) == grid_h-gap) { @@ -113,12 +113,12 @@ var canvas = new Matrix ( grid_w * 16, grid_h * 16, function(x,y){ var j = floor(y / grid_h) if ( (x % grid_w) != grid_w-gap && (y % grid_h) != grid_h-gap) { - var a = MircColor.colors[ all_hue(i) ] - var b = MircColor.colors[ all_hue(j) ] + var a = Photo.colors[ all_hue(i) ] + var b = Photo.colors[ all_hue(j) ] pixel[0] = clamp( 1 - (1-a[0]/255) * (1-b[0]/255), 0, 1 ) * 255 pixel[1] = clamp( 1 - (1-a[1]/255) * (1-b[1]/255), 0, 1 ) * 255 pixel[2] = clamp( 1 - (1-a[2]/255) * (1-b[2]/255), 0, 1 ) * 255 - lex.fg = lex.bg = MircColor.closest_to(pixel) + lex.fg = lex.bg = Photo.closest_to(pixel) lex.char = " " } else if ((y % grid_h) == grid_h-gap) { @@ -146,8 +146,8 @@ var canvas = new Matrix ( grid_w * 16, grid_h * 16, function(x,y){ var j = floor(y / grid_h) if ( (x % grid_w) != grid_w-gap && (y % grid_h) != grid_h-gap) { - var a = MircColor.colors[ all_hue(i) ] - var b = MircColor.colors[ all_hue(j) ] + var a = Photo.colors[ all_hue(i) ] + var b = Photo.colors[ all_hue(j) ] var a0 = a[0]/255 var a1 = a[1]/255 @@ -168,7 +168,7 @@ var canvas = new Matrix ( grid_w * 16, grid_h * 16, function(x,y){ pixel[1] = clamp( 1 - 2 * (1-a1) * (1-b1), 0, 1 ) * 255 pixel[2] = clamp( 1 - 2 * (1-a2) * (1-b2), 0, 1 ) * 255 } - lex.fg = lex.bg = MircColor.closest_to(pixel) + lex.fg = lex.bg = Photo.closest_to(pixel) lex.char = " " } else if ((y % grid_h) == grid_h-gap) { @@ -197,8 +197,8 @@ var canvas = new Matrix ( grid_w * 16, grid_h * 16, function(x,y){ var j = floor(y / grid_h) if ( (x % grid_w) != grid_w-gap && (y % grid_h) != grid_h-gap) { - var a = MircColor.colors[ all_hue(i) ] - var b = MircColor.colors[ all_hue(j) ] + var a = Photo.colors[ all_hue(i) ] + var b = Photo.colors[ all_hue(j) ] var a0 = a[0]/255 var a1 = a[1]/255 @@ -229,7 +229,7 @@ var canvas = new Matrix ( grid_w * 16, grid_h * 16, function(x,y){ pixel[2] = clamp( 1 - 2 * (1-a2) * (1-b2), 0, 1 ) * 255 } - lex.fg = lex.bg = MircColor.closest_to(pixel) + lex.fg = lex.bg = Photo.closest_to(pixel) lex.char = " " } else if ((y % grid_h) == grid_h-gap) { @@ -47,7 +47,7 @@ var nn = $(nn_el).prop('checked') var invert = $(invert_el).prop('checked') var width_timeout -MircColor.set_recolor_fn(function(rgb){ +Photo.set_recolor_fn(function(rgb){ if (invert) { rgb[0] = 255 - rgb[0] rgb[1] = 255 - rgb[1] @@ -67,25 +67,25 @@ listen(lum_el, window, "lum") -MircColor.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) +Photo.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) url_el.addEventListener('change', function(){ ratio_el.value = ratio = 0 url = "/cgi-bin/proxy?" + url_el.value - MircColor.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) + Photo.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) }) nn_el.addEventListener('change', function(){ nn = $(nn_el).prop('checked') - MircColor.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) + Photo.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) }) invert_el.addEventListener('change', function(){ invert = $(invert_el).prop('checked') - MircColor.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) + Photo.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) }) palette_el.addEventListener('change', function(){ var palette = $(palette_el).val() - MircColor.set_colors( MircColor[palette] ) - MircColor.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) + Photo.set_colors( Photo[palette] ) + Photo.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) }) ratio_el.addEventListener("input", function(){ ratio = parseFloat( ratio_el.value ) @@ -94,7 +94,7 @@ ratio_el.addEventListener("input", function(){ height_span.innerHTML = "..." clearTimeout( width_timeout ) width_timeout = setTimeout(function(){ - MircColor.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) + Photo.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) }, 50) }) width_el.addEventListener("input", function(){ @@ -103,19 +103,19 @@ width_el.addEventListener("input", function(){ height_span.innerHTML = "..." clearTimeout( width_timeout ) width_timeout = setTimeout(function(){ - MircColor.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) + Photo.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) }, 50) }) function listen (el, obj, val) { el.addEventListener("input", function(){ obj[val] = parseFloat( el.value ) - MircColor.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) + Photo.fromUrl(url, toCanvas, { width: width, ratio: ratio, neighbor: nn }) }) } function toCanvas(rows){ var wpx = 6, hpx = 12 var canvas = document.createElement("canvas"), ctx = canvas.getContext('2d') - var rgb_colors = MircColor.colors.map(function(c){ return "rgb(" + c + ")" }) + var rgb_colors = Photo.colors.map(function(c){ return "rgb(" + c + ")" }) canvas.width = rows[0].length * wpx canvas.height = rows.length * hpx rows.forEach(function(row, j){ @@ -127,7 +127,7 @@ function toCanvas(rows){ height_span.innerHTML = rows.length image_style.innerHTML = "" image_style.appendChild(canvas) - text_style.value = MircColor.ascii(rows) + text_style.value = Photo.ascii(rows) } </script> diff --git a/js/clipboard.js b/js/clipboard.js index bcbfdff..b8b583e 100644 --- a/js/clipboard.js +++ b/js/clipboard.js @@ -205,6 +205,16 @@ var clipboard = (function () { clipboard.focus() return output }, + + export_png: function () { + var palette = 'mirc' + var font = 'fixedsys' + + var start = Date.now(); + colorcode.to_canvas(in_text.value, {canvas:canvas, palette:palette, font:font}) + var total = Date.now() - start; + console.log("took " + total) + } } diff --git a/js/color_code.js b/js/photo.js index 7811d82..e1b8079 100644 --- a/js/color_code.js +++ b/js/photo.js @@ -1,5 +1,5 @@ -var MircColor = (function(){ +var Photo = (function(){ var COLORS = [ [255,255,255], [0,0,0], diff --git a/webcam.html b/webcam.html index 5b40d6e..9d92931 100644 --- a/webcam.html +++ b/webcam.html @@ -77,10 +77,10 @@ getStream(function(video){ function animate () { requestAnimationFrame(animate) if (! camera.videoWidth) return - MircColor.fromCanvas(camera, toCanvas, { width: width, ratio: ratio, neighbor: nn }) + Photo.fromCanvas(camera, toCanvas, { width: width, ratio: ratio, neighbor: nn }) } -MircColor.set_recolor_fn(function(rgb){ +Photo.set_recolor_fn(function(rgb){ var hsl = rgb2hsl(rgb) hsl[0] = mod(hsl[0] + hue, 1.0) hsl[1] = clamp(hsl[1] + sat, 0.0, 1.0) @@ -107,9 +107,9 @@ listen(quant_el, window, "quant") save_el.addEventListener('click', save) function save (){ - MircColor.fromCanvas(camera, saveText, { width: width, ratio: ratio, neighbor: nn }) + Photo.fromCanvas(camera, saveText, { width: width, ratio: ratio, neighbor: nn }) function saveText(rows) { - text_style.value = MircColor.ascii(rows) + text_style.value = Photo.ascii(rows) if (window.self !== window.top) { window.parent.postMessage(text_style.value, "*"); } @@ -123,7 +123,7 @@ invert_el.addEventListener('change', function(){ }) palette_el.addEventListener('change', function(){ var palette = $(palette_el).val() - MircColor.set_colors( MircColor[palette] ) + Photo.set_colors( Photo[palette] ) }) ratio_el.addEventListener("input", function(){ ratio = parseFloat( ratio_el.value ) @@ -144,7 +144,7 @@ function listen (el, obj, val) { var canvas = document.createElement("canvas"), ctx = canvas.getContext('2d') function toCanvas(rows){ var wpx = 6, hpx = 12 - var rgb_colors = MircColor.colors.map(function(c){ return "rgb(" + c + ")" }) + var rgb_colors = Photo.colors.map(function(c){ return "rgb(" + c + ")" }) canvas.width = rows[0].length * wpx canvas.height = rows.length * hpx rows.forEach(function(row, j){ |
