int w=400; // width int h=300; // height int lp=100; // number of allele A int lq=100; // number of allele a float dp=1; // frequency of mutation A->a float dq=1; // frequency of mutation a->A float mdp=0.1; // multiplicator of mutation A->a float mdq=0.1; // multiplicator of mutation a->A float p=lp/200f; // frequency of allel A float q=lq/200f; // frequency of allel a Allel [] [] mp = new Allel [10] [20]; Allel [] [] mq = new Allel [10] [20]; String state="stop"; //state: start/stop int counter=0; PFont f; int colStart=color(0,255,0); int colStop=color(150,0,0); PImage allel1; PImage allel2; int n=0; // generations number void setup() { size(w,h); background(0); smooth(); allel1= loadImage("redball.png"); allel2=loadImage("blueball.png"); displayAlleles(); frameRate(10); f=loadFont("DejaVuSans-12.vlw"); } void draw() { background(0); textFont(f,12); pushMatrix(); freq(40,dp); popMatrix(); pushMatrix(); freq(340,dq); popMatrix(); for (int i=0; i<20; i++) { for (int j=0; j<10; j++) { Allel allelp= mp[j][i]; Allel allelq= mq[j][i]; } } fill(colStart); rect(10,10,20,20); fill(colStop); rect(40,10,20,20); fill(0); triangle(15,15,15,25,25,20); rect(45,15,10,10); if (state=="start") { mutations(); } displayAlleles(); fill(255); text("A->a: "+dp*mdp/100,50,70); text("a->A: "+dq*mdq/100,270,70); fill(255,0,0); text("A: "+lp,130,50); p=lp/200f; //counting of allel A frequency text("p: "+p,130,30); fill(200,200,255); q=lq/200f; //counting of allel a frequency text("a: "+lq,225,50); text("q: "+q,225,30); fill (200,230,200); text("n: "+n,170,295); if (state=="start") { n++; } } void freq(int x, float val) { noStroke(); translate(x,280); fill(100,150,100); rect(0,0,20,-200); fill(0,255,0); rect(0,0,20,-val*2); } void mutations(){ counter=0; for (int i=0; i<200; i++) { if (countera if (mouseX>40 && mouseX<60 && mouseY<281 && mouseY>79) { dp=mouseY*-0.5+140; } // regulation of mutations frequency a->A if (mouseX>340 && mouseX<360 && mouseY<281 && mouseY>79) { dq=mouseY*-0.5+140; } // regulation of initial nr of allele A if (mouseX>70 && mouseX<170 && mouseY<281 && mouseY>79) { lp=abs(190-round((mouseY-80)/10)*10) + abs(round((mouseX+140)/10)-20); lq=200-lp; } // regulation of initial nr of allele a if (mouseX>230 && mouseX<330 && mouseY<281 && mouseY>79) { lq=abs(190-round((mouseY-80)/10)*10) + abs(round((mouseX+140)/10)-36); lp=200-lq; } // if start if (mouseX>10 && mouseX<30 && mouseY<30 && mouseY>10) { state="start"; colStart=color(0,155,0); colStop=color(250,0,0); } // if stop if (mouseX>40 && mouseX<60 && mouseY<30 && mouseY>10) { state="stop"; colStart=color(0,255,0); colStop=color(150,0,0); } displayAlleles(); } void keyPressed() { if(key == CODED) { if(keyCode == UP) { mdp*=10; } else if (keyCode == DOWN) { mdp/=10; } else if (keyCode == RIGHT) { mdq*=10; } else if (keyCode == LEFT) { mdq/=10; } } else { if (key == 'r') { lp=100; // reset number of allele A lq=100; // reset number of allele a dp=1; // reset frequency of mutation A->a dq=1; // reset frequency of mutation a->A mdp=0.1; // reset multiplicator of mutation A->a mdq=0.1; // reset multiplicator of mutation a->A p=lp/200f; // reset frequency of allel A q=lq/200f; // reset frequency of allel a n=0; // reset generations number } } }