diff options
| -rw-r--r-- | js/blit.js | 11 | ||||
| -rw-r--r-- | js/ui/controls.js | 10 | ||||
| -rw-r--r-- | js/ui/nopaint.js | 63 | ||||
| -rw-r--r-- | js/util.js | 1 |
4 files changed, 74 insertions, 11 deletions
@@ -78,6 +78,17 @@ var blit = (function(){ } }) } + blit.inverted_cross = function(A, lex){ + // 1x1 brush should still draw something + if (A.w == 1 && A.h == 1) { + return + } + A.forEach(function(lex,x,y) { + if (!((x+y)%2)) { + lex.clear() + } + }) + } blit.square = function(A, lex){ // i.e. no transparency } diff --git a/js/ui/controls.js b/js/ui/controls.js index a2b0c7b..8eddc4e 100644 --- a/js/ui/controls.js +++ b/js/ui/controls.js @@ -4,12 +4,20 @@ var controls = (function(){ controls.cross = new Tool (cross_el) controls.cross.use = function(){ - brush.mask = blit.cross + if (brush.mask == blit.cross) { + controls.cross.el.innerHTML = "ssoɹɔ" + brush.mask = blit.inverted_cross + } + else { + controls.cross.el.innerHTML = "cross" + brush.mask = blit.cross + } brush.generate() drawing = true brush.modified = false } controls.cross.done = function(){ + controls.cross.el.innerHTML = "cross" drawing = false } diff --git a/js/ui/nopaint.js b/js/ui/nopaint.js index fc2b5a3..da6a74b 100644 --- a/js/ui/nopaint.js +++ b/js/ui/nopaint.js @@ -126,6 +126,7 @@ var nopaint = (function(){ }, start: function(last_brush){ + this.set_brush_mask() this.toggle_channels() this.reset( last_brush ) this.regenerate() @@ -181,14 +182,30 @@ var nopaint = (function(){ return b }, + set_brush_mask: function(){ + var r = Math.random() + if (r < 0.2) { + brush.mask = blit.square + } + else if (r < 0.6) { + brush.mask = blit.circle + } + else if (r < 0.9) { + brush.mask = blit.cross + } + else{ + brush.mask = blit.inverted_cross + } + }, + toggle_channels: function(){ - if (Math.random() < 0.01) { controls.bg.use(false) } + if (Math.random() < 0.001) { controls.bg.use(false) } else if (! brush.draw_bg && Math.random() < 0.25) { controls.bg.use(true) } - if (Math.random() < 0.2) { controls.fg.use(false) } + if (Math.random() < 0.1) { controls.fg.use(false) } else if (! brush.draw_fg && Math.random() < 0.5) { controls.fg.use(true) } - if (Math.random() < 0.05) { controls.char.use(false) } + if (Math.random() < 0.02) { controls.char.use(false) } else if (! brush.draw_char && Math.random() < 0.2) { controls.char.use(true) } }, @@ -297,22 +314,47 @@ var nopaint = (function(){ var CloneBrush = SolidBrush.extend({ type: "clone", + reset: function( last_brush ){ - this.opt.max_radius = randrange(5,20) + this.opt.max_radius = randrange(5, 20) this.reorient( last_brush ) - this.__resize(4,2) - this.clone_region() + this.resize(4,2) + this.clone_random_region() }, - clone_region: function(){ + clone_random_region: function(x, y){ var x = randrange(0, canvas.w - brush.w) var y = randrange(0, canvas.h - brush.h) - blit.copy_from(canvas, brush, floor(x-brush.w/2), floor(y-brush.h/2)) + this.clone_region(x, y) + }, + + clone_region: function(x, y){ + blit.copy_from(canvas, brush, round(x-brush.w/2), round(y-brush.h/2)) brush.mask(brush) }, + iterate: function( last_brush ){ + this.reorient( last_brush ) + }, + regenerate: function(){}, - resize: function(){}, + }) + + var SmearBrush = CloneBrush.extend({ + type: "smear", + + update: function(){ + var r = random() + var jitter_x = randnullsign() * xrand(2, 2) + var jitter_y = randnullsign() * xrand(2, 2) + this.clone_region( this.p.x + jitter_x, this.p.y + jitter_y ) + }, + + iterate: function( last_brush ){ + this.resize(4, 2) + this.update() + this.reorient( last_brush ) + } }) var StarsTool = NopaintBrush.extend({ @@ -528,7 +570,8 @@ var nopaint = (function(){ nopaint.add_tool( new LetterBrush({ weight: 4 }) ) nopaint.add_tool( new RandomLetterBrush({ weight: 16 }) ) nopaint.add_tool( new CloneBrush({ weight: 10 }) ) - nopaint.add_tool( new FillTool({ weight: 4 }) ) + nopaint.add_tool( new SmearBrush({ weight: 16 }) ) + nopaint.add_tool( new FillTool({ weight: 3 }) ) nopaint.add_tool( new FillLetterTool({ weight: 6 }) ) nopaint.add_tool( new StarsTool({ weight: 3 }) ) nopaint.add_tool( new TranslateTool({ weight: 5 }) ) @@ -47,6 +47,7 @@ function rand(n){ return (Math.random()*n) } function randint(n){ return rand(n)|0 } function randrange(a,b){ return a + rand(b-a) } function randsign(){ return random() >= 0.5 ? -1 : 1 } +function randnullsign(){ var r = random(); return r < 0.333 ? -1 : r < 0.666 ? 0 : 1 } function xrandom(exp){ return Math.pow(Math.random(), exp) } function xrand(exp,n){ return (xrandom(exp)*n) } |
