mercredi 17 février 2021

Which variable should I put on the modulator if statement in order for circles to move randomly?

var circleArray = [];
var MIN_RADIUS;
var MAX_RADIUS;
var NUM_CIRCLES;

function start(){
createCircles();
mouseClickMethod(changeCircles);
}

function createCircles(){


NUM_CIRCLES = readInt("How many circles do you want?");
MIN_RADIUS = readInt("What's the smallest radius you would like?");
MAX_RADIUS = readInt("What's the largest radius you would like?");

for(var i = 0; i < NUM_CIRCLES; i++){

    var circle = new Circle(Randomizer.nextInt(MIN_RADIUS, MAX_RADIUS));

    var x = Randomizer.nextInt(MIN_RADIUS, getWidth() - MAX_RADIUS);
    var y = Randomizer.nextInt(MIN_RADIUS, getHeight() - MAX_RADIUS);

    circle.setPosition(x, y);

    updateCircle(circle);
    add(circle);
    circleArray.push(circle);

}

}

function changeCircles(){

for(var i = 0; i < NUM_CIRCLES; i++){

     updateCircle(circleArray[i]);

}

}

function updateCircle(circle){

// If the current circle's radius is even
if(circle[circle] % 2 == 0){
    var x = Randomizer.nextInt(0, getWidth);
    var y = Randomizer.nextInt(0, getHeight);
   circle.setPosition(x, y);

  }

 if(circle[circle] % 2 == 1){

// Otherwise if the current circle's radius is odd
    var RADIUS = Randomizer.nextInt(MIN_RADIUS, MAX_RADIUS);
    circle.setRadius(RADIUS);
    }
    var color = Randomizer.nextColor();
    circle.setColor(color);
    }

This program makes you type in the number of circles you want, the minimum radius, and the maximum radius. Then, it runs the circles, and when you click on the program, the circles go at random. Everything works but it won't move when I click on it; it only changes the circle's color. I have deciphered the problem to be at the modulator if statements. I have tried every variable but to no avail. Any and all advice is appreciated. What variable should I use to make the circles go at random?

Aucun commentaire:

Enregistrer un commentaire