#Need Help

4 messages · Page 1 of 1 (latest)

frozen bobcat
#

I wanted the code below to change the squares into circles, change the background color, adding an horizontal movement to simulate wind and simulate that the circles don't get past the floor like they get stuck

var step = 50;
var w = c.canvas.width;
var h = c.canvas.height;
var cmTID;

var px = [];
var py = []; 
var velx = [];
var vely = [];
var mida = [];


var i = 0;
var nquad = 350;

do {
  
  px[i] = Math.floor(Math.random() * w);   
  py[i] = -Math.floor(Math.random() * h);
  velx[i] = 0;
  vely[i] = Math.random() * 2 + 3;
  
  mida[i] = Math.floor(Math.random() * 5);
  vely[i] = mida[i]/2 + Math.random() * 1.5;

    i = i + 1;
} while (i < nquad);


drawStep();

function drawStep() {
  
  c.clearRect(0, 0, w, h);
  
    
  
    i = 0;
  do {
    
    c.fillStyle = "red";
    c.fillRect(px[i], py[i], mida[i], mida[i]);
    
    py[i] = py[i] + vely[i];
    
    
    if (py[i]>350) 
    { 
      py[i] = 0;
    }
    
        i = i + 1;
    } while (i < nquad);
  
    
  clearTimeout(cmTID);
  
  cmTID = setTimeout(drawStep, step);

}
wild haloBOT
#

This post has been reserved for your question.

Hey @frozen bobcat! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.