splice

I want to make the first image disappear when it reaches 10 images. I am thinking splice the array. However not sure where or how.

index.html

    <html>
    <head>

      <meta charset="UTF-8">
      <script language="javascript" type="text/javascript" src="libraries/p5.js"></script> 
      <script language="javascript" src="libraries/p5.dom.js"></script>
      <script language="javascript" src="libraries/p5.sound.js"></script>
      <script language="javascript" src="images.js"></script>
      <script language="javascript" src="images_2.js"></script>
    </head> 
      <!-- this line removes any default padding and style. you might only need one of these values set. -->
      <style> 
      </style>

    </head>

    <body>

    </body>
    </html>

============================================================================ images.js

    var bubbles = [];
    var flowers = [];

    function preload(){

        for(var i = 0; i< 6; i++){
            flowers[i] = loadImage("fet_pictures/" + i + ".jpg");
        }

    }

    function windowResized(){
        resizeCanvas(windowWidth, windowHeight);
    }

    function setup(){
        createCanvas(windowWidth, windowHeight);
    }

    function mousePressed(){
        var r = floor(random(0, flowers.length));
        var b = new Bubble(mouseX, mouseY, flowers[r]);
        bubbles.push(b);
    }

    function draw(){
        background(0);
        for(var i = bubbles.length -1; i >= 0; i--){
            bubbles[i].update();
            bubbles[i].display();
        }
    }

============================================================================ images_2.js

        function Bubble(x, y, img){
        this.x = x;
        this.y = y;
        this.img = img;
        this.lifespan = 255;

        this.display = function(){
            imageMode(CENTER);
            image(this.img, this.x, this.y);
            this.img.resize(100, 0);
            //ellipse(this.x, this.y, 48, 48);
        }

        this.update = function() {
            this.x = this.x + random(-1, 1);
            this.y = this.y + random(-1, 1);
           }
        }

Answers

Sign In or Register to comment.