array question
in
Programming Questions
•
2 years ago
I've been picking apart this code and don't quite understand how the arrays work in terms of connecting the lines. Can someone explain? How does processing understand that e[k][0] is a neighboring circle.
- //settings
- int count=40;
- int minDomain=30;
- int maxDomain=60;
- int sel = 0;
- float[][] e = new float[count][5];
- void setup(){
- frameRate(15);
- size(400,400);
- for(int j=0;j< count;j++){
- e[j][0]=random(width); // X
- e[j][1]=random(height); // Y
- e[j][2]=random(minDomain,maxDomain); // Radius
- e[j][3]=random(-.5,.5); // X Speed
- e[j][4]=random(-.5,.5); // Y Speed
- }
- }
- void draw(){
- background(0);
- for(int j=0; j<count;j++){
- float radius=e[j][2];
- ellipse(e[j][0],e[j][1],radius,radius);
- e[j][0]+=e[j][3];
- e[j][1]+=e[j][4];
- fill(80,255,187,100);
- stroke(128,255,0,100);
- for(int k=0;k< count;k++){
- if( dist(e[j][0],e[j][1],e[k][0],e[k][1]) < radius){
- line(e[j][0],e[j][1],e[k][0],e[k][1]);
- }
- }
- }
- }
1