From 8fac46008806a7ab4908d1738a28210e76b74f36 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 23 May 2016 02:43:49 -0400 Subject: choose a mode --- js/ui/evolver.js | 20 ++++++++++++++++++++ js/ui/nopaint.js | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/js/ui/evolver.js b/js/ui/evolver.js index 8e889f4..26ef05d 100644 --- a/js/ui/evolver.js +++ b/js/ui/evolver.js @@ -9,6 +9,7 @@ var evolver = (function(){ population: 10, strokes: 1, randomize: false, + mode: 'all', } var hash = window.location.search || window.location.hash if (hash) { @@ -35,6 +36,25 @@ var evolver = (function(){ }) } + var modes = {} + modes.gray = 'gray' + modes.color = 'solid hue erase random' + modes.letter = 'letter random-letter' + modes.brush = [modes.gray, modes.color, 'smear clone'].join(" ") + modes.magic = 'letter random-letter translate scale rotate cycle smear clone' + + if (opt.mode && opt.mode in modes){ + nopaint.disable_all_tools() + nopaint.enable_tools( modes[opt.mode].split(" ") ) + if (opt.mode == 'magic') { + nopaint.tools.translate.opt.weight *= 2 + nopaint.tools.cycle.opt.weight *= 3 + nopaint.tools.rotate.opt.weight *= 3 + nopaint.tools.scale.opt.weight *= 3 + } + nopaint.regenerate_weights() + } + console.log(opt) var step = 0 diff --git a/js/ui/nopaint.js b/js/ui/nopaint.js index d3741a9..da30e37 100644 --- a/js/ui/nopaint.js +++ b/js/ui/nopaint.js @@ -89,6 +89,16 @@ var nopaint = (function(){ nopaint.add_tool = function(fn){ nopaint.tools[fn.type] = fn } + nopaint.disable_all_tools = function(){ + Object.keys(nopaint.tools).forEach(function(key){ + nopaint.tools[key].disabled = true + }) + } + nopaint.enable_tools = function(keys){ + keys.forEach(function(key){ + if (nopaint.tools[key]) nopaint.tools[key].disabled = false + }) + } nopaint.get_random_tool = function( last_tool ){ var n = rand( nopaint.sum ) for (var i = 0, _len = nopaint.weights.length; i < _len; i++) { @@ -101,7 +111,11 @@ var nopaint = (function(){ nopaint.regenerate_weights = function(){ nopaint.sum = 0 nopaint.weights = [] - nopaint.keys = Object.keys( nopaint.tools ).sort(function(a,b){ return nopaint.tools[b].opt.weight-nopaint.tools[a].opt.weight }) + nopaint.keys = Object.keys( nopaint.tools ).sort(function(a,b){ + return nopaint.tools[b].opt.weight-nopaint.tools[a].opt.weight + }).filter(function(key){ + return ! nopaint.tools[key].disabled + }) nopaint.keys.forEach(function(key){ nopaint.sum += nopaint.tools[key].opt.weight nopaint.weights.push( nopaint.sum ) @@ -456,7 +470,7 @@ var nopaint = (function(){ }) var GrayBrush = SolidBrush.extend({ - type: "hue", + type: "gray", recolor: function(){ this.fg = this.bg = rand_gray() this.char = " " @@ -743,6 +757,7 @@ var nopaint = (function(){ start: function(){ this.__start() this.n = randsign() + if (random() < 0.2) this.n *= randint(15) }, shade: function(src, dest, lex, x, y){ lex.bg += this.n -- cgit v1.2.3-70-g09d2