diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-05-10 21:47:27 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-05-10 21:47:27 -0400 |
| commit | 13d700004227922fb99bbef3587ff1b546741ec0 (patch) | |
| tree | 1c3c644481353db4036fd535e2f51b21a360f5fa /js | |
| parent | a885f8dd16bfc3c1e04f0fffa68661bfe5301673 (diff) | |
moving nopaint stuff into main codebase
Diffstat (limited to 'js')
| -rw-r--r-- | js/tool.js | 15 | ||||
| -rw-r--r-- | js/ui/controls.js | 11 | ||||
| -rw-r--r-- | js/ui/nopaint.js (renamed from js/nopaint/index.js) | 92 | ||||
| -rw-r--r-- | js/ui/palette.js | 4 |
4 files changed, 71 insertions, 51 deletions
@@ -114,14 +114,11 @@ var RadioGroup = Tool.extend({ } }) - - - var Checkbox = Tool.extend({ init: function (el){ this.__init(el) var name = this.name.replace(/^[x_] /,"") - var state = localStorage.getItem("ascii." + name) || this.name[0] == "x" + var state = localStorage.getItem("ascii.tools." + name) == "true" || this.name[0] == "x" this.name = name this.update(state) }, @@ -153,14 +150,18 @@ var BlurredTool = Tool.extend({ }) var HiddenCheckbox = BlurredCheckbox.extend({ + on: "o", + off: ".", init: function (el){ this.el = el this.lex = new Lex (el) - this.name = el.innerHTML - var state = this.name[0] == "o" + this.name = this.el.id + var state = localStorage.getItem("ascii.tools." + name) == "true" || this.el.innerHTML[0] == this.on this.update(state) }, update: function(state){ - this.el.innerHTML = state ? "o" : "." + this.el.innerHTML = state ? this.on : this.off + if (this.memorable) { localStorage.setItem("ascii.tools." + this.name, !! state) } + console.trace() } }) diff --git a/js/ui/controls.js b/js/ui/controls.js index 9139989..00cb14c 100644 --- a/js/ui/controls.js +++ b/js/ui/controls.js @@ -176,8 +176,17 @@ var controls = (function(){ cs.selection.use = function(){ shader.canvas = selection.canvas } controls.experimental_palette = new HiddenCheckbox (experimental_palette_toggle) + controls.experimental_palette.memorable = true controls.experimental_palette.use = function(state){ - var state = palette.experimental() + var state = palette.experimental(state) + this.update(state) + } + + controls.nopaint = new HiddenCheckbox (nopaint_toggle) + controls.nopaint.memorable = true + controls.nopaint.on = "N" + controls.nopaint.use = function(state){ + var state = nopaint.toggle(state) this.update(state) } diff --git a/js/nopaint/index.js b/js/ui/nopaint.js index 859c4cf..d6b0004 100644 --- a/js/nopaint/index.js +++ b/js/ui/nopaint.js @@ -2,8 +2,6 @@ var nopaint = (function(){ var is_paint = false - controls.nopaint = {} - controls.no = new Tool (nopaint_no_el) controls.no.use = function(state){ undo.undo() @@ -32,6 +30,12 @@ var nopaint = (function(){ nopaint.step = 0 nopaint.time = 0 nopaint.timeout = false + nopaint.toggle = function(state){ + var state = typeof state == "boolean" ? state : nopaint_rapper.classList.contains("hidden") + nopaint_rapper.classList.toggle("hidden", ! state) + document.body.classList.toggle("nopaint", state) + return state + } nopaint.undo = function(){ undo.undo() } @@ -82,6 +86,8 @@ var nopaint = (function(){ }) } + /* Base models for brushes */ + var NopaintTool = Model({ type: "none", init: function(opt){ @@ -173,41 +179,7 @@ var nopaint = (function(){ var easings = "linear circ_out circ_in circ_in_out quad_in quad_out quad_in_out".split(" ") - var FillTool = NopaintTool.extend({ - type: "fill", - rate: 25, - start: function(){ - this.fill() - }, - paint: function(t){ - if ((t % this.rate) == this.rate-1) { - this.fill() - } - }, - recolor: function(){ - this.fg = this.bg = randint(16) - this.char = " " - this.opacity = 1 - }, - fill: function(){ - var x = randint(canvas.w) - var y = randint(canvas.h) - this.recolor() - draw.fill(this, x, y) - } - }) - - var FillLetterTool = FillTool.extend({ - type: "fill-letter", - rate: 25, - chars: unicode.block('Basic Latin', 32), - recolor: function(){ - this.fg = randint(16) - this.bg = randint(16) - this.char = choice(this.chars) - this.opacity = 1 - }, - }) + /* Standard brushes */ var SolidBrush = NopaintBrush.extend({ type: "solid", @@ -303,7 +275,7 @@ var nopaint = (function(){ reset: function( last_brush ){ this.opt.max_radius = randrange(5,20) this.reorient( last_brush ) - this.__resize(3,2) + this.__resize(4,2) this.clone_region() }, @@ -320,7 +292,7 @@ var nopaint = (function(){ var StarsTool = NopaintBrush.extend({ type: "stars", - chars: "...,,''''*", + chars: "....,,'''*", start: function(last_brush){ this.reorient( last_brush ) @@ -337,14 +309,52 @@ var nopaint = (function(){ }, }) + /* Fill tool */ + + var FillTool = NopaintTool.extend({ + type: "fill", + rate: 25, + start: function(){ + this.fill() + }, + paint: function(t){ + if ((t % this.rate) == this.rate-1) { + this.fill() + } + }, + recolor: function(){ + this.fg = this.bg = randint(16) + this.char = " " + this.opacity = 1 + }, + fill: function(){ + var x = randint(canvas.w) + var y = randint(canvas.h) + this.recolor() + draw.fill(this, x, y) + } + }) + + var FillLetterTool = FillTool.extend({ + type: "fill-letter", + rate: 25, + chars: unicode.block('Basic Latin', 32), + recolor: function(){ + this.fg = randint(16) + this.bg = randint(16) + this.char = choice(this.chars) + this.opacity = 1 + }, + }) + nopaint.add_tool( new SolidBrush({ weight: 3 }) ) nopaint.add_tool( new EraseBrush({ weight: 5 }) ) nopaint.add_tool( new RandomBrush({ weight: 4 }) ) nopaint.add_tool( new HueBrush({ weight: 6 }) ) nopaint.add_tool( new LetterBrush({ weight: 4 }) ) - nopaint.add_tool( new RandomLetterBrush({ weight: 11 }) ) + nopaint.add_tool( new RandomLetterBrush({ weight: 14 }) ) nopaint.add_tool( new CloneBrush({ weight: 8 }) ) - nopaint.add_tool( new FillTool({ weight: 6 }) ) + nopaint.add_tool( new FillTool({ weight: 4 }) ) nopaint.add_tool( new FillLetterTool({ weight: 6 }) ) nopaint.add_tool( new StarsTool({ weight: 6 }) ) nopaint.regenerate_weights() diff --git a/js/ui/palette.js b/js/ui/palette.js index 3b5cb24..5931543 100644 --- a/js/ui/palette.js +++ b/js/ui/palette.js @@ -37,8 +37,8 @@ var palette = (function(){ } palette.repaint() var use_experimental_palette = false - palette.experimental = function(){ - use_experimental_palette = ! use_experimental_palette + palette.experimental = function(state){ + use_experimental_palette = typeof state == "boolean" ? state : ! use_experimental_palette use_experimental_palette ? palette.resize(32, 5) : palette.resize(32, 2) palette.repaint() return use_experimental_palette |
