Skip to content

Commit

Permalink
Autosave images
Browse files Browse the repository at this point in the history
  • Loading branch information
phl committed Jul 20, 2012
1 parent 00de4f1 commit b09db3b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pareidoloop.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var Pareidoloop = new function() {
var genCount;
var lastImprovedGen;
var faceA, faceB;
var canvasA, canvasB, canvasOut, scoreA, scoreB, output;
var canvasA, canvasB, canvasOut, scoreA, scoreB;
var outputCallback;

var settings = {
CANVAS_SIZE : 50,
Expand All @@ -30,6 +31,9 @@ var Pareidoloop = new function() {
if (args.outputSize) {
settings.OUTPUT_SIZE = args.outputSize;
}
if (args.outputCallback) {
outputCallback = args.outputCallback;
}
if (args.confidenceThreshold) {
settings.CONFIDENCE_THRESHOLD = args.confidenceThreshold;
}
Expand All @@ -42,7 +46,6 @@ var Pareidoloop = new function() {
scoreA = document.getElementById("scoreA");
canvasB = document.getElementById("canvasB");
scoreB = document.getElementById("scoreB");
output = document.getElementById("output");

canvasOut = document.createElement("canvas");

Expand Down Expand Up @@ -176,8 +179,11 @@ var Pareidoloop = new function() {
var dataUrl = canvasOut.toDataURL();

var outputImg = document.createElement("img");
output.appendChild(outputImg);
outputImg.src = dataUrl;
outputImg.src = dataUrl;

if (outputCallback) {
outputCallback(outputImg);
}

// go again
reset();
Expand Down Expand Up @@ -211,10 +217,10 @@ var Pareidoloop = new function() {
ctx.closePath();

if (alpha > 0) {
ctx.fillStyle = "#ffffff";
ctx.fillStyle = "#ffffff";
ctx.globalAlpha = alpha;
} else {
ctx.fillStyle = "#000000";
ctx.fillStyle = "#000000";
ctx.globalAlpha = -alpha;
}

Expand Down Expand Up @@ -304,4 +310,4 @@ var Pareidoloop = new function() {
return {numFaces : comp.length, bounds : this.bounds, confidence : this.fitness};
}
}
}
}

0 comments on commit b09db3b

Please sign in to comment.