diff options
| -rw-r--r-- | js/nopaint/index.js | 174 |
1 files changed, 144 insertions, 30 deletions
diff --git a/js/nopaint/index.js b/js/nopaint/index.js index 413306a..859c4cf 100644 --- a/js/nopaint/index.js +++ b/js/nopaint/index.js @@ -89,6 +89,7 @@ var nopaint = (function(){ }, start: function(){}, paint: function(t){}, + update: function(t){}, finish: function(){}, }) @@ -97,6 +98,7 @@ var nopaint = (function(){ is_brush: true, init: function(opt){ this.opt = opt || {} + this.opt.max_radius = this.opt.max_radius || 10 this.p = {x: randint(canvas.w), y: randint(canvas.h)} this.fg = 0 this.bg = 1 @@ -106,13 +108,12 @@ var nopaint = (function(){ start: function(last_brush){ this.reset( last_brush ) - brush.load( this ) - brush.generate() + this.regenerate() draw.down({}, null, [this.p.x, this.p.y]) }, paint: function(t){ - this.update( t ) + this.update(t) draw.move_toroidal({}, null, [this.p.x, this.p.y]) }, @@ -149,15 +150,7 @@ var nopaint = (function(){ }) this.tweens.push(tween) }, - - - }) - - var easings = "linear circ_out circ_in circ_in_out quad_in quad_out quad_in_out".split(" ") - var SolidBrush = NopaintBrush.extend({ - type: "solid", - get_next_point: function(){ var radius = randrange(2, this.opt.max_radius) var b = {} @@ -167,38 +160,91 @@ var nopaint = (function(){ b.y = this.p.y + randrange(-radius, radius) return b }, + + iterate: function( last_brush ){ + this.reorient( last_brush ) + }, + + regenerate: function(){ + brush.load( this ) + brush.generate() + }, + }) + + 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 + }, + }) + + var SolidBrush = NopaintBrush.extend({ + type: "solid", recolor: function(){ this.fg = this.bg = randint(16) this.char = " " - this.regenerate() }, - randomize: function(){ - this.opt.max_radius = randrange(3,10) - var bw = xrandrange(5, 1, 3) - brush.resize( round(bw * randrange(0.9, 1.8)), round(bw) ) + resize: function(m,n){ + m = m || 3 + n = n || 0 + var bw = xrandrange(5, 0, m) + n + brush.resize( round(bw * randrange(0.9, 1.8)) || 1, round(bw) || 1 ) }, reset: function( last_brush ){ - brush.resize(1,1) - this.randomize() + this.opt.max_radius = randrange(5,20) + this.resize() this.reorient( last_brush ) this.recolor( last_brush ) + this.regenerate() }, iterate: function( last_brush ){ - this.randomize() + this.resize() this.reorient( last_brush ) }, - - regenerate: function(){ - brush.load( this ) - brush.generate() + }) + + var EraseBrush = SolidBrush.extend({ + type: "random", + iterate: function( last_brush ){ + this.bg = 0 + this.char = " " + this.random() }, - - update: function(t){ - } }) var RandomBrush = SolidBrush.extend({ @@ -214,7 +260,6 @@ var nopaint = (function(){ recolor: function(){ this.fg = this.bg = rand_hue() this.char = " " - this.regenerate() }, }) @@ -225,14 +270,83 @@ var nopaint = (function(){ this.fg = rand_hue() this.bg = rand_hue() this.char = choice(this.chars) + }, + }) + + var RandomLetterBrush = LetterBrush.extend({ + type: "random-letter", + iterate: function(){ + if (Math.random() < 0.01) { + this.fg += 1 + } + if (Math.random() < 0.05) { + var n = this.fg + this.fg = this.bg + this.bg = n + } + if (Math.random() < 0.7) { + this.char = choice(this.chars) + } this.regenerate() + this.__iterate() + }, + update: function(){ + if (Math.random() < 0.3) { + this.char = choice(this.chars) + } + this.regenerate() + }, + }) + + var CloneBrush = SolidBrush.extend({ + type: "clone", + reset: function( last_brush ){ + this.opt.max_radius = randrange(5,20) + this.reorient( last_brush ) + this.__resize(3,2) + this.clone_region() + }, + + clone_region: function(){ + 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)) + brush.mask(brush) + }, + + regenerate: function(){}, + resize: function(){}, + }) + + var StarsTool = NopaintBrush.extend({ + type: "stars", + chars: "...,,''''*", + + start: function(last_brush){ + this.reorient( last_brush ) + }, + + paint: function(t){ + if (Math.random() < 0.5) { + var lex = canvas.get(this.p.x, this.p.y) + lex.fg = rand_hue() + lex.bg = colors.black + lex.char = choice(this.chars) + lex.build() + } }, }) - nopaint.add_tool( new SolidBrush({ weight: 1 }) ) - nopaint.add_tool( new RandomBrush({ weight: 2 }) ) - nopaint.add_tool( new HueBrush({ weight: 4 }) ) + 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 CloneBrush({ weight: 8 }) ) + nopaint.add_tool( new FillTool({ weight: 6 }) ) + nopaint.add_tool( new FillLetterTool({ weight: 6 }) ) + nopaint.add_tool( new StarsTool({ weight: 6 }) ) nopaint.regenerate_weights() return nopaint |
