javascript - Can't find error in JS code -
i have "bubble generator" working, not clearing bubbles , can't figure out why. been staring @ while now. specifically, of bubbles getting "cleared" float up, others aren't, , can't see why. argh!
http://jsfiddle.net/dud2q/7/ (slowed waaay down can watch single bubble)
logic flow (this describes code in fiddle):
create imagedata array (long list of pixels)
imgdata = ctx.getimagedata(0, 0, w, h);
push new random bubbles onto beginning of "bubbles array" draws bottom-up:
for(var i=0, l=generators.length; i<l; i++){ for(var j=0, m=0|math.random()*6; j<m; j++){ newbubbles.push( 0|generators[i] + j ); } generators[i] = math.max(0, math.min(w, generators[i] + math.random()*10 - 5)); } bubbles.unshift(newbubbles);
loop bubbles drawn and:
clear bubbles drawn in last loop setting alpha channel 0 (transparent):
if(i<(l-1)){ x = 0|bubbles[i+1][j]; offset = y * w * 4 + x * 4; pixels[offset+3] = 0; }
draw new bubbles (
offset+1
= g,offset+2
= b,offset+3
= alpha):x = 0|(bubbles[i][j] += math.random() * 6 - 3); offset = y * w * 4 + x * 4; pixels[offset+1] = 0x66; pixels[offset+2] = 0x99; pixels[offset+3] = 0xff;
increasing number of generators higher number seems make work.
eg. 50..times(createbubblegenerator);
works.
cheers!!!
Comments
Post a Comment