> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.7SzUVxiV9Lc/rev.3312
 * 
 * authors: 
 *   Nathan Breitsch

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// Pressing Control-R will render this sketch.


int xCenter = 500;
int yCenter = 500;
int radius = 300;
double timestep = 0.015;

int r = .8;
int s = .2;

randomSeed(0);
double[] cells = new double[20];
for (int i = 0; i < cells.length; i++){
    cells[i] = random(1);    
}

//do a sentinal count of cells in signaling region
int count = 0;
for (int cell : cells){
    if (cell <= s){
        ++count;    
    }    
}




void compute(){
    //count cells in S
    
    for (int i = 0; i < cells.length; i++){
        if (cells[i] > r){
        cells[i]+=timestep*(1- count/cells.length);  
        }
        else if (cells[i] <= s){
            cells[i] += timestep;
            if (cells[i] > s){
                --count;
            }
        }
        else{
        cells[i]+= timestep;    
        }
        if (cells[i] >= 1){
            cells[i] -= 1;  
            ++count;
            }
        }    
        
}

void drawParamTriangle(){
    stroke(#000000)
    strokeWeight(4);
    triangle(350, 650,
            350, 350,
            650, 350);
            
    //put a dot on the triangle indicating parameter values
    ellipse(350 + 300 * s, 650 - 300 * r, 3, 3);
    
}

void drawTimeStepBar(){
    stroke(#000000);
    strokeWeight(4);
    //left triangle
    triangle(50, 50, 350, 75, 350, 25); 
   // text("slower", 200, 50);
    
    //right triangle
    triangle(950, 50, 650, 75, 650, 25);
     //   text("faster", 730, 50);
    strokeWeight(12);
}

void drawBigCircle(){
    stroke(#0000aa);
    strokeWeight(12);
    ellipse(xCenter, yCenter, 2 * radius, 2 * radius);
}

void drawRegions(){
    strokeWeight(21);
    stroke(#33aaff);
    //draw signaling region
    arc(xCenter, yCenter, 2 * radius, 2 * radius,  - PI/2, 2 * PI * s -          PI/2);
    
    stroke(#ffaa33);
    //draw response region
    arc(xCenter, yCenter, 2*radius, 2*radius, 2 * PI * r - PI/2, 2 * PI - PI/2);
}

void drawCells(){
    stroke(#0000aa);
    strokeWeight(4);
    //print cells
    for (int cell : cells){
        ellipse(xCenter + radius * Math.cos(2 * PI * (cell) - PI/2),
                yCenter + radius * Math.sin(2 * PI * (cell) - PI/2),
                21, 21);
    }
}

void setup() {  // this is run once.   
    
    // set the background color
    background(255);
    
    // canvas size (Variable aren't evaluated. Integers only, please.)
    size(1000, 1000); 
      
    // smooth edges
    smooth();
    
    // limit the number of frames per second
    frameRate(30);
    
    // set the width of the line. 
    strokeWeight(12);
} 

//for change in parameters
void refactor(){
    //get the count
    //do a sentinal count of cells in signaling region
    count = 0;
    for (int cell : cells){
    if (cell <= s){
        ++count;    
    }    
}
}

void draw() {  // this is run repeatedly.  

    //compute new positions
    compute();
    
    background(255);

    //draw the big circle
    drawBigCircle();
    
    //time step bar
    drawTimeStepBar();
         
    //draw S and R
    drawRegions();
    
    //parameter triangle
    drawParamTriangle();
    
    //draw the cells
    drawCells();

    
    //triangle
    


}

void mousePressed(){
 //test if in the left triangle
    if (abs(mouseY - 50) <= 25/300*(mouseX - 50) && mouseX <= 350){
      timestep -=.005;
    }
 //test if in right triangle
    if (abs(mouseY - 50) <= 25/300*(950 - mouseX) && mouseX >= 650){
        timestep += .005;
    }
 //test if in parameter triangle
     if (mouseX > 350 && mouseY > 350 && mouseY < (650 - (mouseX - 350))){
         r = (650 - mouseY)/300;
         s = (mouseX - 350)/300;
         refactor();
    }
}