Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to make the particles explode at 250,250 when b==250 but its not working

What I have tried:

var a=500;
var b=490;
var pA;


function setup() {
var canvas=createCanvas(500,500);
canvas.parent("easel");
textSize(50);
angleMode(DEGREES);

pA=new Array(500);
for(var i=0;i<500;i++){
pA[i]=new Particle(250,250,0,5,-5,5);

}


}


function draw() {
background(255,255,0);




stroke(255,0,0);
strokeWeight(3);
line(250,a,250,b);

if(a>250){
a--
};
if(b>250){
b--
};
if(b==250) {
stroke(255,0,0);
strokeWeight(2);
for(var i=0;i<500;i++){
point(pA[i].x, pA[i].y);
pA[i].x+=pA[i].vx;
pA[i].y+=pA[i].vy;
}
};

function Particle(x,y,vx1,vx2,vy1,vy2){
this.x=x;
this.y=y;
this.vx=random(vx1,vx2);
this.vy=random(vy1,vy2);
}

\
}
Posted
Updated 19-Aug-17 14:43pm

1 solution

Quote:
but its not working

This is not informative, use the debugger to see what the code is doing.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
JavaScript Debugging[^]
Chrome DevTools  |  Web  |  Google Developers[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900