Skip to content

Commit

Permalink
added checkbox to toggle fading of previous generations, for #2
Browse files Browse the repository at this point in the history
  • Loading branch information
rvosa committed Sep 1, 2016
1 parent 7af1cf2 commit a40bc71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ <h3>Evolution</h3-->
<br />
<div style="text-align: right">
<label for="drawTree">Update tree</label>
<div id="drawTree"></div>
<div id="drawTree"></div><br />
<label for="drawFade">Fade previous</label>
<div id="drawFade"></div>
</div>
<br /><br />
<svg id="svg"></svg>
Expand Down
17 changes: 12 additions & 5 deletions uilib.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var UI = function() {

// make checkbox
$('#drawTree').replaceWith('<input type="checkbox" id="drawTree" checked="checked" />');
$('#drawFade').replaceWith('<input type="checkbox" id="drawFade" checked="checked" />');

// collect all controls in an accordion
$("#controls").accordion({ collapsible: true, active: false });
Expand Down Expand Up @@ -278,12 +279,18 @@ UI.prototype.colorArea = function(ctx,startX,startY,rgb,imageData){
* Fades the previous generation of individuals on the canvas
*/
UI.prototype.fade = function() {
var imgData = this.evoCtx.getImageData(0,0,window.innerWidth,window.innerHeight);
var pix = imgData.data;
for ( var i = 0; i < pix.length; i += 4 ) {
pix[i+3] *= 0.9;
var fade = this.getBoolean('drawFade');
if ( fade ) {
var imgData = this.evoCtx.getImageData(0, 0, window.innerWidth, window.innerHeight);
var pix = imgData.data;
for (var i = 0; i < pix.length; i += 4) {
pix[i + 3] *= 0.9;
}
this.evoCtx.putImageData(imgData, 0, 0);
}
else {
this.evoCtx.clearRect(0,0, window.innerWidth, window.innerHeight);
}
this.evoCtx.putImageData(imgData,0,0);
};

/**
Expand Down

0 comments on commit a40bc71

Please sign in to comment.