#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
ofLog(OF_LOG_NOTICE, "setup() nmnt");
ofSetFrameRate (20);
ofSetWindowTitle("lotka volterre teacher student model");
cout << "lotka volterre teacher student model.." << endl;
//uni.loadImage("uni.png"); // loads image
//uni.setAnchorPercent(0.5,0.5); // sets picture in middle of screen
//uni.draw(mouseX, mouseY); // uni
helpMe=true;
startLearning = false;
onOff=0;
blocks=0;
showBlocks = false;
oldNumPrey = 80;
oldNumPredator = 5;
caryingCapacityPrey = 300;
caryingCapacityPredator = 2000;
birthRatePrey = 0.4; //0.4
deathRatePredator = 0.2; //0.2
predationRate = 0.0050; //0.005
predationEfficiency = 0.2; //0.2
inflowPrey=0;
inflowPreyOnce=0;
inflowPredator=0;
inflowPredatorOnce=0;
leidenImage.loadImage("uni.jpg");
}
//--------------------------------------------------------------
void testApp::update(){
if (onOff%2==0) {
onOff=0;
startLearning = false;
}
if (blocks%2==0) {
blocks=0;
showBlocks = false;
}
counter = counter + 0.033f;
if (startLearning == true){
deltaPrey = birthRatePrey* (1-(oldNumPrey/caryingCapacityPrey))* oldNumPrey - predationRate * oldNumPredator * oldNumPrey + inflowPrey + inflowPreyOnce;
deltaPredator = predationEfficiency*predationRate*oldNumPrey*oldNumPredator * (1-(oldNumPredator/caryingCapacityPredator)) - deathRatePredator * oldNumPredator + inflowPredator+inflowPredatorOnce;
inflowPredatorOnce = 0;
inflowPreyOnce = 0;
newNumPrey = oldNumPrey + deltaPrey;
newNumPredator = oldNumPredator + deltaPredator;
if (newNumPrey < 0 ){
newNumPrey=0;
newNumPredator--;
}
if (newNumPrey > 500 ){
newNumPrey=500;
}
if (newNumPredator > 500 ){
newNumPredator=500;
}
if (newNumPredator < 0 ){
newNumPredator=0;
}
oldNumPrey = newNumPrey;
oldNumPredator = newNumPredator;
}
}
//--------------------------------------------------------------
void testApp::draw(){
ofBackground(152,201,212);
//uni.draw(400, 400); // uni
//leidenImage.draw(0,0);
if (startLearning == false){
ofSetColor(100,255,134); //set circle white
ofCircle(341, 300, oldNumPrey); // prey X
ofSetColor(255,0,0);
ofCircle(682, 300, oldNumPredator); // predator Y
}
if (blocks == 0){
ofSetColor(0,255,0); //set circle white
ofCircle(341, 300, newNumPrey); // prey X
}
if (blocks == 1 ){
for (int i = 0; i < newNumPrey; i++){
ofSetColor((int)ofRandom(0,255),(int)ofRandom(0,255),(int)ofRandom(0,255));
ofRect(ofRandom(100,500),ofRandom(100,500),ofRandom(10,20),ofRandom(10,20));
}
}
ofSetColor(255,0,0);
ofCircle(682, 300, newNumPredator); // predator Y
ofSetHexColor(0x000000);
ofDrawBitmapString( "lotka volterre teacher student model..", 20,20);
ofSetHexColor(0x000000);
ofDrawBitmapString(" Teachers ", 670,210);
ofSetHexColor(0x000000);
ofDrawBitmapString(" Students ", 20,410);
if(helpMe==false){
ofSetHexColor(0x000000);
ofDrawBitmapString(" Press h for help ", 20,50);
ofSetHexColor(0x000000);
ofDrawBitmapString(" deltaStudent = admissionRateStudent * (1-(oldNumStudents/tables for students))* oldNumStudent", 20,580);
ofSetHexColor(0x000000);
ofDrawBitmapString(" - predationRate * oldNumPredator * oldNumPrey + inflowPrey + inflowPreyOnce;", 20,600);
ofSetHexColor(0x000000);
ofDrawBitmapString(" deltaTeacher = vakationefficeny*graduationrate*oldNumTeachers*oldNumStudents * (1-(oldNumTeachers/rooms for teachers)) ", 20,660);
ofSetHexColor(0x000000);
ofDrawBitmapString(" - fireRateTeacher * oldNumTeacher + inflowTeachers + inflowTeachersOnce;", 20,680);
ofSetHexColor(0x000000);
ofDrawBitmapString("lowercast for up - Uppercast for down ( +/- .... )", 900, 20);
ofSetHexColor(0x000000);
ofDrawBitmapString(" => admission-rate", 900, 60);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (birthRatePrey), 800, 60);
ofSetHexColor(0x000000);
ofDrawBitmapString(" => graduation-rate", 900, 80);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (predationRate), 800, 80);
ofSetHexColor(0x000000);
ofDrawBitmapString(" => fire-rate", 900, 100);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (deathRatePredator), 800, 100);
ofSetHexColor(0x000000);
ofDrawBitmapString(" => vacation", 900, 120);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (predationEfficiency), 800, 120);
ofSetHexColor(0x000000);
ofDrawBitmapString(" => rooms ", 900, 160);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (caryingCapacityPredator), 800, 160);
ofSetHexColor(0x000000);
ofDrawBitmapString(" => tables", 900, 140);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (caryingCapacityPrey), 800, 140);
}
if(helpMe==true){
ofSetHexColor(0x000000);
ofDrawBitmapString(" Press shift h to hide help ", 20,50);
//----text teachers---
ofSetHexColor(0x000000);
ofDrawBitmapString("a => plus one teachers every new frame (initial value is 0)", 700, 580);
ofSetHexColor(0x000000);
ofDrawBitmapString("A => plus one teachers once", 700, 600);
ofSetHexColor(0x000000);
ofDrawBitmapString("z => minus one teacher every new frame (initial value is 0)", 700, 620);
ofSetHexColor(0x000000);
ofDrawBitmapString("Z => minus one teachers once", 700, 640);
ofSetHexColor(0x000000);
ofDrawBitmapString("q => random value beween 10 and -10 every new frame (initial value is 0)", 700, 660);
ofSetHexColor(0x000000);
ofDrawBitmapString("Q => adds a random value beween 10 and -10 once", 700, 680);
ofSetHexColor(0x000000);
ofDrawBitmapString("1 => reset the addition of teachers to 0", 700, 700);
//--- text Students----
ofSetHexColor(0x000000);
ofDrawBitmapString("s => chuck +1 freshman in there every new frame (initial value is 0)", 20, 580);
ofSetHexColor(0x000000);
ofDrawBitmapString("S => lets have these rotten few have a go + 10 once", 20, 600);
ofSetHexColor(0x000000);
ofDrawBitmapString("x => flunk +1 student every new frame (initial value is 0)", 20, 620);
ofSetHexColor(0x000000);
ofDrawBitmapString("X => oohh, you let 10 student flunks..", 20, 640);
ofSetHexColor(0x000000);
ofDrawBitmapString("w => adds beween 10 and -10 students every frame(initial value is 0)", 20, 660);
ofSetHexColor(0x000000);
ofDrawBitmapString("W => adds beween 10 and -10 students once (initial value is 0)", 20, 680);
ofSetHexColor(0x000000);
ofDrawBitmapString("2 => reset the addition of students to 0", 20, 700);
//-- parameters
ofSetHexColor(0x000000);
ofDrawBitmapString("lowercast for up - Uppercast for down ( +/- .... )", 900, 20);
ofSetHexColor(0x000000);
ofDrawBitmapString("b => admission-rate (+/- .... )", 900, 60);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (birthRatePrey), 800, 60);
ofSetHexColor(0x000000);
ofDrawBitmapString("g => graduation-rate (+/- .... )", 900, 80);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (predationRate), 800, 80);
ofSetHexColor(0x000000);
ofDrawBitmapString("f => sorry, we have to let you go..-rate (+/- .... )", 900, 100);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (deathRatePredator), 800, 100);
ofSetHexColor(0x000000);
ofDrawBitmapString("v => vacation (+/- .... )", 900, 120);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (predationEfficiency), 800, 120);
ofSetHexColor(0x000000);
ofDrawBitmapString("n => normal... ", 900, 180);
ofSetHexColor(0x000000);
ofDrawBitmapString("r => rooms (+/- .... ) ", 900, 160);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (caryingCapacityPredator), 800, 160);
ofSetHexColor(0x000000);
ofDrawBitmapString("t => tables (+/- .... )", 900, 140);
ofSetHexColor(0x000000);
ofDrawBitmapString(ofToString (caryingCapacityPrey), 800, 140);
}
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
cout << key << endl;
cout << caryingCapacityPrey << endl;
if (key==104) helpMe=true; //1 reset
if (key==72) helpMe=false; //1 reset
//start and stop time
if (key==32) {
onOff++;
startLearning = true;
}
// -- show blocks with enter
if (key==13) {
blocks++;
showBlocks = true;
}
// --- teacher inflow --
if (key==49) inflowPredator=0; //1 reset
if (key==97) inflowPredator++; //a
if (key==65) inflowPredatorOnce++; //shift A
if (key==122) inflowPredator--; //z
if (key==90) inflowPredatorOnce--; //Z
if (key==113) inflowPredator = inflowPredator + rand () %11 - rand () %11; //q
if (key==81) inflowPredatorOnce = inflowPredator + rand () %11 - rand () %11; //Q
// --- Student inflow --
if (key==50) inflowPrey=0; //2
if (key==115) inflowPrey++; //s
if (key==83) inflowPreyOnce++; //shift s
if (key==120) inflowPrey--; //x
if (key==88) inflowPreyOnce--; //shift x
if (key==119) inflowPrey = inflowPrey + rand () %21 - rand () %21; //w
if (key==87) inflowPreyOnce = inflowPrey + rand () %21 - rand () %21; //W
// --- parameter tweeking --
if (key==116) caryingCapacityPrey = caryingCapacityPrey + 10; //tables t
if (key==84) caryingCapacityPrey = caryingCapacityPrey - 10; //tables T
if (key==114) caryingCapacityPredator = caryingCapacityPredator + 10; //rooms r
if (key==82) caryingCapacityPredator = caryingCapacityPredator - 10; //rooms R
if (key==98) birthRatePrey = birthRatePrey + 0.05; //b
if (key==66) birthRatePrey = birthRatePrey - 0.05; //B
if (key==102) deathRatePredator = deathRatePredator + 0.05; //f
if (key==70) deathRatePredator = deathRatePredator - 0.05; //F
if (key==103) predationRate = predationRate + 0.00050; //graduation g
if (key==71) predationRate = predationRate - 0.00050; //graduation G
if (key==118) predationEfficiency = predationEfficiency + 0.05; //vacation v
if (key==86) predationEfficiency = predationEfficiency - 0.05; //vacation V
//---normal parameters (key n)--
if (key==110){
caryingCapacityPrey = 300;
caryingCapacityPredator = 2000;
birthRatePrey = 0.4; //0.4
deathRatePredator = 0.2; //0.2
predationRate = 0.0050; //0.005
predationEfficiency = 0.2; //0.2
}
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){
}