Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6098687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:11:12+00:00 2026-05-23T13:11:12+00:00

I have a bubble generator that is mostly working, but is not properly clearing

  • 0

I have a “bubble generator” that is mostly working, but is not properly clearing the bubbles and I can’t figure out why. Been staring at this for a while now. Specifically, some of the bubbles are getting “cleared” as they float up, others aren’t, and I can’t see why. ARGH!

http://jsfiddle.net/Dud2q/7/ (slowed waaay down so that you can easily watch a single bubble)

Logic flow (this just describes the code in the fiddle):

  1. Create an imageData array (long list of pixels)

    imgData = ctx.getImageData(0, 0, w, h);
    
  2. push new random bubbles onto the beginning of the “bubbles array” which 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);
    
  3. loop all bubbles to be drawn and:

    1. clear the bubbles that were drawn in the last loop by setting alpha channel to 0 (transparent):

      if(i<(l-1)){
          x = 0|bubbles[i+1][j];
          offset = y * w * 4 + x * 4;
          pixels[offset+3] = 0;
      }
      
    2. 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;
      
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:11:13+00:00Added an answer on May 23, 2026 at 1:11 pm

    Increasing the number of generators to a higher number seems to make it work.

    Eg. 50..times(createBubbleGenerator); almost works.

    Cheers!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have a qTip2 bubble created but not displayed at load time.
I know bubble sort is probably not the fastest way to do this but
The Background: I have been creating a script that based on input csv's that
I'm creating a bubble generator as a background effect that will run on a
I can't figure out an elegant way to accomplish the following using CSS: I
Do bubble sorts have any real world use? Every time I see one mentioned,
I have multiple layers in an application and i find myself having to bubble
Have a n-tire web application and search often times out after 30 secs. How
Hola! I have an issue I thought I would throw out to the S.O.
On my local dev environment, when an App Engine task that had been added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.