Team:TU Eindhoven/the game

From 2014.igem.org

(Difference between revisions)
Line 40: Line 40:
// The next line is needed if running in JavaScript Mode with Processing.js
// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="http://i.imgur.com/gDccyRX.png, http://i.imgur.com/V6756WQ.png, http://i.imgur.com/qmz6Tqx.png, http://i.imgur.com/kTG3cjw.png, http://i.imgur.com/rXLfh0n.png, http://i.imgur.com/DF3iOQN.png, http://i.imgur.com/HsgqFiR.png, http://i.imgur.com/yt3xRrC.png, http://i.imgur.com/oqpG7r6.png, http://i.imgur.com/tVs8PA3.png, http://i.imgur.com/8TgXchE.png, http://i.imgur.com/k2JxEjl.png, http://i.imgur.com/87sB8SH.png, http://i.imgur.com/vWEOnlj.png, http://i.imgur.com/sua0hIH.png, http://i.imgur.com/o2V20If.png, http://i.imgur.com/V2v8JpM.png, http://i.imgur.com/7VmOmW1.png, http://i.imgur.com/NW22Blc.png, http://i.imgur.com/9uJagVU.png, http://i.imgur.com/C7xi9eF.png, http://i.imgur.com/V8Tyv9D.png, http://i.imgur.com/14eMBR8.png, http://i.imgur.com/rKe6hVf.png, http://i.imgur.com/i9jxTsO.png, http://i.imgur.com/i9jxTsO.png, http://i.imgur.com/EY7xXur.png, http://i.imgur.com/qiWx2fF.png, http://i.imgur.com/2YUI7lW.png, http://i.imgur.com/KQ0ZyBA.png, http://i.imgur.com/ermi0iK.png, http://i.imgur.com/EKrOZM8.png, http://i.imgur.com/8VAJ6Bt.png, http://i.imgur.com/t2kTiPr.png, http://i.imgur.com/UmJRy3m.png, http://i.imgur.com/nkWwyFH.png, http://i.imgur.com/klMOhVr.png, http://i.imgur.com/CfREnca.png, http://i.imgur.com/1Sk2HSE.png, http://i.imgur.com/ymhoulY.png, http://i.imgur.com/G7MdUHm.png, http://i.imgur.com/P5kUXSf.png, http://i.imgur.com/oW2kyrW.png, http://i.imgur.com/wrpjZ1g.png, http://i.imgur.com/oi4cINP.png, http://i.imgur.com/wyzfNAg.jpg"; */
/* @pjs preload="http://i.imgur.com/gDccyRX.png, http://i.imgur.com/V6756WQ.png, http://i.imgur.com/qmz6Tqx.png, http://i.imgur.com/kTG3cjw.png, http://i.imgur.com/rXLfh0n.png, http://i.imgur.com/DF3iOQN.png, http://i.imgur.com/HsgqFiR.png, http://i.imgur.com/yt3xRrC.png, http://i.imgur.com/oqpG7r6.png, http://i.imgur.com/tVs8PA3.png, http://i.imgur.com/8TgXchE.png, http://i.imgur.com/k2JxEjl.png, http://i.imgur.com/87sB8SH.png, http://i.imgur.com/vWEOnlj.png, http://i.imgur.com/sua0hIH.png, http://i.imgur.com/o2V20If.png, http://i.imgur.com/V2v8JpM.png, http://i.imgur.com/7VmOmW1.png, http://i.imgur.com/NW22Blc.png, http://i.imgur.com/9uJagVU.png, http://i.imgur.com/C7xi9eF.png, http://i.imgur.com/V8Tyv9D.png, http://i.imgur.com/14eMBR8.png, http://i.imgur.com/rKe6hVf.png, http://i.imgur.com/i9jxTsO.png, http://i.imgur.com/i9jxTsO.png, http://i.imgur.com/EY7xXur.png, http://i.imgur.com/qiWx2fF.png, http://i.imgur.com/2YUI7lW.png, http://i.imgur.com/KQ0ZyBA.png, http://i.imgur.com/ermi0iK.png, http://i.imgur.com/EKrOZM8.png, http://i.imgur.com/8VAJ6Bt.png, http://i.imgur.com/t2kTiPr.png, http://i.imgur.com/UmJRy3m.png, http://i.imgur.com/nkWwyFH.png, http://i.imgur.com/klMOhVr.png, http://i.imgur.com/CfREnca.png, http://i.imgur.com/1Sk2HSE.png, http://i.imgur.com/ymhoulY.png, http://i.imgur.com/G7MdUHm.png, http://i.imgur.com/P5kUXSf.png, http://i.imgur.com/oW2kyrW.png, http://i.imgur.com/wrpjZ1g.png, http://i.imgur.com/oi4cINP.png, http://i.imgur.com/wyzfNAg.jpg"; */
-
 
int numberOfDNA;
int numberOfDNA;
DNAPiece[] dna;
DNAPiece[] dna;
Line 172: Line 171:
boolean thereIsInfoToShow = true;
boolean thereIsInfoToShow = true;
 +
PImage img;  // Declare variable "a" of type PImage
-
void setup(){
+
void setup() {
-
   size(1000, 800);
+
   size(640, 360);
-
  textAlign(CENTER);
+
   // The image file must be in the data folder of the current sketch
-
   //image's
+
   // to load successfully
-
 
+
   img = loadImage("http://i.imgur.com/wyzfNAg.jpg");  // Load the image into the program  
-
   level1_1  = loadImage("http://i.imgur.com/V6756WQ.png");
+
-
   level1_2  = loadImage("http://i.imgur.com/qmz6Tqx.png");
+
-
  level1_3 = loadImage("http://i.imgur.com/kTG3cjw.png");
+
-
  level2_1 = loadImage("http://i.imgur.com/rXLfh0n.png");
+
-
  level2_2  = loadImage("http://i.imgur.com/DF3iOQN.png");
+
-
  wellDone  = loadImage("http://i.imgur.com/P5kUXSf.png");
+
-
  toBad  = loadImage("http://i.imgur.com/G7MdUHm.png");
+
-
  logo1_1  = loadImage("http://i.imgur.com/qiWx2fF.png");
+
-
  logo1_2  = loadImage("http://i.imgur.com/2YUI7lW.png");
+
-
  logo1_3  = loadImage("http://i.imgur.com/KQ0ZyBA.png");
+
-
  logo2_1  = loadImage("http://i.imgur.com/EKrOZM8.png");
+
-
  logo2_2  = loadImage("http://i.imgur.com/8VAJ6Bt.png");
+
-
  logo1_max  = loadImage("http://i.imgur.com/ermi0iK.png");
+
-
  logo2_max  = loadImage("http://i.imgur.com/t2kTiPr.png");
+
-
 
+
-
  helpOn = loadImage("http://i.imgur.com/oqpG7r6.png");
+
-
  helpOff = loadImage("http://i.imgur.com/yt3xRrC.png");
+
-
 
+
-
  handInDNA = loadImage("http://i.imgur.com/HsgqFiR.png");
+
-
  info = loadImage("http://i.imgur.com/87sB8SH.png");
+
-
  background = loadImage("http://i.imgur.com/wrpjZ1g.png");
+
-
 
+
-
  img_gfp = loadImage("http://i.imgur.com/klMOhVr.png");
+
-
  img_t7 = loadImage("http://i.imgur.com/CfREnca.png");
+
-
  img_terminator = loadImage("http://i.imgur.com/1Sk2HSE.png");
+
-
  img_antibiores = loadImage("http://i.imgur.com/wyzfNAg.jpg");
+
-
  img_tntP = loadImage("http://i.imgur.com/ymhoulY.png");
+
-
  img_o2 = loadImage("http://i.imgur.com/oW2kyrW.png");
+
-
  img_display = loadImage("http://i.imgur.com/DF3iOQN.png");
+
-
  img_linker = loadImage("http://i.imgur.com/UmJRy3m.png");
+
-
  img_mri = loadImage("http://i.imgur.com/nkWwyFH.png");
+
-
  img_keke = loadImage("http://i.imgur.com/EY7xXur.png");
+
-
  img_inhi = loadImage("http://i.imgur.com/i9jxTsO.png");
+
-
  binOn = loadImage("http://i.imgur.com/gDccyRX.png");
+
-
  binOff = loadImage("http://i.imgur.com/oi4cINP.png");
+
-
 
+
-
  numberOfDNA = 11;
+
-
  infoBoard = new PImage[numberOfDNA + 1];
+
-
  infoBoard[1] = loadImage("http://i.imgur.com/vWEOnlj.png");
+
-
  infoBoard[2] = loadImage("http://i.imgur.com/sua0hIH.png");
+
-
  infoBoard[3] = loadImage("http://i.imgur.com/o2V20If.png");
+
-
  infoBoard[4] = loadImage("http://i.imgur.com/V2v8JpM.png");
+
-
  infoBoard[5] = loadImage("http://i.imgur.com/7VmOmW1.png");
+
-
  infoBoard[6] = loadImage("http://i.imgur.com/NW22Blc.png");
+
-
  infoBoard[7] = loadImage("http://i.imgur.com/9uJagVU.png");
+
-
  infoBoard[8] = loadImage("http://i.imgur.com/C7xi9eF.png");
+
-
  infoBoard[9] = loadImage("http://i.imgur.com/V8Tyv9D.png");
+
-
  infoBoard[10] = loadImage("http://i.imgur.com/14eMBR8.png");
+
-
  infoBoard[11] = loadImage("http://i.imgur.com/rKe6hVf.png");
+
-
 
+
-
  helpScreen = new PImage[maxNumberOfHelpScreens];
+
-
  helpScreen[0] = loadImage("http://i.imgur.com/tVs8PA3.png");
+
-
  helpScreen[1] = loadImage("http://i.imgur.com/8TgXchE.png");
+
-
  helpScreen[2] = loadImage("http://i.imgur.com/k2JxEjl.png");
+
-
 
+
-
  //grapping items
+
-
 
+
-
 
+
-
  dna = new DNAPiece[numberOfDNA + 1];
+
-
  dna[0] = new DNAPiece(10, 10, img_gfp, name_gfp, 1, color(0, 255, 0));
+
-
  dna[1] = new DNAPiece(10, 80, img_terminator, name_terminator, 2, color(200,200,200));
+
-
  dna[2] = new DNAPiece(10, 150, img_t7, name_t7, 3, color(255,0,100));
+
-
  dna[3] = new DNAPiece(10, 220, img_antibiores, name_antibiores, 4, color(255,255,255));
+
-
  dna[4] = new DNAPiece(10, 290, img_tntP, name_tntP, 5, color(255,100,0));
+
-
  dna[5] = new DNAPiece(10, 360, img_o2, name_o2, 6, color(255, 0, 0));
+
-
  dna[6] = new DNAPiece(10, 430, img_display, name_display, 7, color(100,51,102));
+
-
  dna[7] = new DNAPiece(10, 500, img_linker, name_linker, 8, color(0,105,106));
+
-
  dna[8] = new DNAPiece(10, 570, img_mri, name_mri, 9, color(255,125,255));
+
-
  dna[9] = new DNAPiece(10, 640, img_keke, name_keke, 10, color(255,0,255));
+
-
  dna[10] = new DNAPiece(10, 710, img_inhi, name_inhi, 11, color(100,100,255));
+
-
  plasmide1 = new Plasmide(250, 100, 500, 450, 2);
+
-
  plasmide2 = new Plasmide(350, 425, 350, 300, 2);
+
-
 
+
-
  //buttons right
+
-
  bin = new Button((width-stripRight)+10, 20, binOn, binOff);
+
-
  helpButton = new Button((width-stripRight)+10, 700, helpOn, helpOff);
+
-
  helpButton.isItOn = true;
+
-
 
+
-
  //levels
+
-
 
+
-
  level1 = new SubLevel[3];
+
-
  level2 = new SubLevel[1];
+
-
  level1[0] = new SubLevel(eis1_1,empty, logo1_1, level1_1, wellDone, 1, 1);
+
-
  level1[1] = new SubLevel(eis1_2,empty, logo1_2, level1_2, wellDone, 1, 2);
+
-
  level1[2] = new SubLevel(eis1_3,empty, logo1_3, level1_3, wellDone, 1, 2);
+
-
  level2[0] = new SubLevel(eis2_1,empty, logo2_1, level2_1, wellDone, 2, 1);
+
-
  //level2[1] = new SubLevel(eis2_2,empty, logo2_2, level2_2, wellDone, 2, 2);
+
-
 
+
-
 
+
-
  theRealLevels = new MasterLevel[2];
+
-
  theRealLevels[0] = new MasterLevel(level1, toBad, logo1_max, (width-stripRight)+10, 100);
+
-
  theRealLevels[1] = new MasterLevel(level2, toBad, logo2_max, (width-stripRight)+10, 180);
+
-
 
+
-
 
+
-
 
+
}
}
-
void draw(){
+
void draw() {
-
  image(background, 0,0, width, height);
+
   // Displays the image at its actual size at point (0,0)
-
   //background(0);
+
   image(img, mouseX, mouseY);
-
  fill(200, 50, 50, 200);
+
   // Displays the image at point (0, height/2) at half of its size
-
  rect(0,0, stripLeft, height);
+
   image(img, 0, height/2, img.width/2, img.height/2);
-
  rect(width-stripRight,0, stripRight, height);
+
-
 
+
-
  if(infoNumber != 0){
+
-
    showInfoBoard(infoNumber);
+
-
  } else if(currentHelpScreen != 0){
+
-
    image(helpScreen[currentHelpScreen-1], 0,0, 920, 800);
+
-
    helpButton.drawing();
+
-
    bin.drawing();
+
-
    for(int i = 0; i < theRealLevels.length; i++){
+
-
      theRealLevels[i].drawing();
+
-
    }
+
-
  } else {
+
-
    plasmide1.drawing();
+
-
    if(secondPlas) plasmide2.drawing();
+
-
    bin.drawing();
+
-
    helpButton.drawing();
+
-
    for(int i = 0; i < pieceOfDNAForUse; i++){
+
-
      dna[i].drawing();
+
-
    }
+
-
 
+
-
 
+
-
    for(int i = 0; i < theRealLevels.length; i++){
+
-
      theRealLevels[i].drawing();
+
-
    }
+
-
  }
+
-
 
+
-
}
+
-
 
+
-
void mouseClicked(){
+
-
 
+
-
  if(thereIsInfoToShow == false){
+
-
    for(int i = 0; i < theRealLevels.length; i++){
+
-
      theRealLevels[i].allFalse();
+
-
    }
+
-
   
+
-
    if((mouseX > (width - stripRight)) || (mouseX < stripLeft)){
+
-
      pickingUp();
+
-
    } else {
+
-
      dropIt();
+
-
      handItInBitch();
+
-
    }
+
-
  }else{
+
-
    thereIsInfoToShow = false;
+
-
    infoNumber = 0;
+
-
    helpDrawing();
+
-
    for(int i = 0; i < theRealLevels.length; i++){
+
-
      theRealLevels[i].allFalse();
+
-
    }
+
-
  }
+
-
}
+
-
void helpDrawing(){
+
-
  if(helpButton.checkIfClicked()){
+
-
    currentHelpScreen=(currentHelpScreen + 1)%(maxNumberOfHelpScreens+1);
+
-
    thereIsInfoToShow = true;
+
-
    if(currentHelpScreen == 0){
+
-
      helpButton.isItOn = false;
+
-
    }else{
+
-
      helpButton.isItOn = true;
+
-
    }
+
-
  }
+
-
}
+
-
 
+
-
void pickingUp(){
+
-
  somethingOnMouse = false;
+
-
  bin.check(false);
+
-
 
+
-
  for(int i = 0; i < theRealLevels.length; i++){
+
-
    if(mouseX >(width - stripRight)) theRealLevels[i].checkButton();
+
-
  }
+
-
  for(int i = 0; i < pieceOfDNAForUse; i++){
+
-
    if(dna[i].check(mouseX, mouseY)){
+
-
      itemOnMouse = i;
+
-
      somethingOnMouse = true;
+
-
    }
+
-
  }
+
-
}
+
-
 
+
-
void dropIt(){
+
-
  if(somethingOnMouse){
+
-
    plasmide1.check(dna[itemOnMouse].name, dna[itemOnMouse].colour);
+
-
    if(secondPlas)  plasmide2.check(dna[itemOnMouse].name, dna[itemOnMouse].colour);
+
-
  }else if(bin.isItOn){
+
-
    plasmide1.removePiece();
+
-
    if(secondPlas) plasmide2.removePiece();
+
-
  }
+
-
}
+
-
 
+
-
void showInfoBoard(int i){
+
-
   image(infoBoard[i], 0,0);
+
-
}
+
-
 
+
-
void handItInBitch(){
+
-
  for(int i = 0; i < theRealLevels.length; i++){
+
-
    theRealLevels[i].checkHandIn();
+
-
  }
+
-
}
+
-
 
+
-
class DNAPiece{
+
-
  int posX;
+
-
  int posY;
+
-
  int sizeX = 60;
+
-
  int sizeY = 60;
+
-
  int sizeXinfo = 60;
+
-
  int sizeYinfo = 60;
+
-
  int posXinfo = 72;
+
-
  int posYinfo = posY;
+
-
  int infonumber;
+
-
  String name;
+
-
  boolean mouseHold = false;
+
-
  PImage img;
+
-
  color colour;
+
-
 
+
-
  DNAPiece(int posXQ,int posYQ, PImage imgQ, String nameQ, int infonumberQ, color colourQ){
+
-
    posX = posXQ;
+
-
    posY = posYQ;
+
-
    posYinfo = posY;
+
-
    posXinfo = int(posX+sizeX*1.2);
+
-
    img = imgQ;
+
-
    name = nameQ;
+
-
    infonumber = infonumberQ;
+
-
    colour = colourQ;
+
-
  }
+
-
 
+
-
  void drawing(){
+
-
    fill(colour);
+
-
    if(mouseHold){
+
-
      image(img, mouseX-sizeX/2, mouseY-sizeY/2, sizeX, sizeY);
+
-
      text(name, width/2, height/20);
+
-
    }else{
+
-
      image(img, posX, posY, sizeX, sizeY);
+
-
    }
+
-
    image(info, posXinfo, posY, sizeX, sizeY);
+
-
   }
+
-
 
+
-
  boolean check(int XQ, int YQ){
+
-
    if((XQ <= (posX + sizeX)) && (XQ > posX) && (YQ <= (posY + sizeY)) && (YQ > posY) && (mouseHold == false)){
+
-
        mouseHold = true;
+
-
        return true;
+
-
    } else {
+
-
      if((XQ <= (posXinfo + sizeXinfo)) && (XQ > posXinfo) && (YQ <= (posYinfo + sizeYinfo)) && (YQ > posYinfo) && (infoNumber == 0)) infoNumber = infonumber; thereIsInfoToShow = true;//do you click the infobutton?
+
-
      mouseHold = false;
+
-
      return false;
+
-
    }
+
-
  }
+
-
}
+
-
 
+
-
class Button{
+
-
  PImage buttonOn;
+
-
  PImage buttonOff;
+
-
  boolean isItOn = false;
+
-
  int posX;
+
-
  int posY;
+
-
  int sizeX = 60;
+
-
  int sizeY = 60;
+
-
 
+
-
  Button(int posXQ, int posYQ, PImage buttonOnQ, PImage buttonOffQ){
+
-
    posX = posXQ;
+
-
    posY = posYQ;
+
-
    buttonOn = buttonOnQ;
+
-
    buttonOff = buttonOffQ;
+
-
  }
+
-
 
+
-
  Button(int posXQ, int posYQ, int sizeXQ, int sizeYQ, PImage buttonOnQ, PImage buttonOffQ){
+
-
    posX = posXQ;
+
-
    posY = posYQ;
+
-
    sizeX=sizeXQ;
+
-
    sizeY=sizeYQ;
+
-
    buttonOn = buttonOnQ;
+
-
    buttonOff = buttonOffQ;
+
-
  }
+
-
 
+
-
  void drawing(){
+
-
    if(isItOn){
+
-
      image(buttonOn, posX, posY, sizeX, sizeY);
+
-
    }else{
+
-
      image(buttonOff, posX, posY, sizeX, sizeY);
+
-
    }
+
-
  }
+
-
 
+
-
  void check(boolean infoQ){
+
-
   
+
-
    if((mouseX <= (posX + sizeX)) && (mouseX > posX) && (mouseY <= (posY + sizeY)) && (mouseY > posY) && (isItOn == false)){
+
-
      isItOn = true;
+
-
    } else {
+
-
      isItOn = false;
+
-
    }
+
-
    if(infoQ) thereIsInfoToShow = true;
+
-
  }
+
-
 
+
-
  boolean checkIfClicked(){
+
-
    if((mouseX <= (posX + sizeX)) && (mouseX > posX) && (mouseY <= (posY + sizeY)) && (mouseY > posY)){
+
-
      return true;
+
-
    } else {
+
-
      return false;
+
-
    }
+
-
  }
+
-
}
+
-
 
+
-
class MasterLevel{
+
-
  SubLevel theLevels[];
+
-
  int currentLevel = 0;
+
-
  int reward;
+
-
  PImage toBad;
+
-
  PImage maxLevel;
+
-
  boolean showInfo = false;
+
-
  boolean endLevel = false;
+
-
  boolean doneWell;
+
-
  Button handingIn;
+
-
  //drawing the image's
+
-
  int posX;
+
-
  int posY;
+
-
 
+
-
  int sizeX = 60;
+
-
  int sizeY = 60;
+
-
  int sizeXd = 920;
+
-
  int sizeYd = 800;
+
-
 
+
-
  MasterLevel(SubLevel[] theLevelsQ, PImage toBadQ, PImage maxLevelQ, int posXQ, int posYQ){
+
-
    theLevels = theLevelsQ;
+
-
    maxLevel = maxLevelQ;
+
-
    toBad = toBadQ;
+
-
    posX = posXQ;
+
-
    posY = posYQ;
+
-
    handingIn = new Button(600, 650, 240, 60, handInDNA, handInDNA);
+
-
   }
+
-
 
+
-
  void drawing(){
+
-
    if(currentLevel < theLevels.length){
+
-
      fill(255,255,0);
+
-
      if(showInfo) rect(posX-5,posY-5,sizeX+10,sizeY+10);
+
-
      image(theLevels[currentLevel].logo, posX, posY, sizeX, sizeY);
+
-
    } else{
+
-
      image(maxLevel, posX, posY, sizeX, sizeY);
+
-
    }
+
-
    if(showInfo){
+
-
      if(endLevel){
+
-
        if(doneWell){
+
-
          image(theLevels[currentLevel-1].wellDone, 0,0, sizeXd, sizeYd);
+
-
        }else{
+
-
          image(toBad, 0,0, sizeXd, sizeYd);
+
-
        }
+
-
      }else{
+
-
        image(theLevels[currentLevel].description, 0,0, sizeXd, sizeYd);
+
-
        handingIn.drawing();
+
-
      }
+
-
     
+
-
    }
+
-
  }
+
-
 
+
-
  void checkButton(){
+
-
    if((mouseX <= (posX + sizeX)) && (mouseX > posX) && (mouseY <= (posY + sizeY)) && (mouseY > posY) && (showInfo == false) && (currentLevel < theLevels.length)){
+
-
      showInfo = true;
+
-
      thereIsInfoToShow = true;
+
-
    } else {
+
-
      showInfo = false;
+
-
      endLevel = false;
+
-
    }
+
-
  }
+
-
  void checkHandIn(){
+
-
    if((showInfo) && (handingIn.checkIfClicked()) && (endLevel == false)){
+
-
      if((theLevels[currentLevel].check(plasmide1.hold) && theLevels[currentLevel].check2(plasmide2.hold))||(theLevels[currentLevel].check2(plasmide1.hold) && theLevels[currentLevel].check(plasmide2.hold))){
+
-
        endLevel = true;
+
-
        doneWell = true;
+
-
        theLevels[currentLevel].rewardThatShit();
+
-
        currentLevel++;
+
-
      }else{
+
-
        endLevel = true;
+
-
        doneWell = false;
+
-
      }
+
-
    }
+
-
  }
+
-
 
+
-
  void allFalse(){
+
-
    if(!handingIn.checkIfClicked()){
+
-
      showInfo = false;
+
-
      endLevel = false;
+
-
    }
+
-
  }
+
-
}
+
-
 
+
-
class Plasmide{
+
-
  String hold[];
+
-
  color colour[];
+
-
  color emptyColour = color(125, 125, 125);
+
-
  int posX;
+
-
  int posY;
+
-
  int sizeR;
+
-
  int sizeR2;
+
-
  int sizeR3;
+
-
  int maxLength;
+
-
  float sizeRone;
+
-
  long lastRemove;
+
-
 
+
-
  Plasmide(int posXQ,int posYQ,int sizeRQ, int sizeR2Q, int maxLengthQ){
+
-
    posX = posXQ;
+
-
    posY = posYQ;
+
-
    sizeR = sizeRQ;
+
-
    sizeR2 = sizeR2Q;
+
-
    sizeR3 = sizeR + 50;
+
-
    maxLength = maxLengthQ;
+
-
    sizeRone = (sizeR/maxLength);
+
-
    hold = new String[0];
+
-
    colour = new color[0];
+
-
  }
+
-
 
+
-
  void drawing(){
+
-
    fill(255, 100);
+
-
    rect(posX, posY, sizeR, sizeR);
+
-
    pushMatrix();
+
-
      float step = 0.1;
+
-
      int lengthOfHold = hold.length;
+
-
      translate(posX+sizeR/2, posY+sizeR/2);
+
-
      fill(0);
+
-
      text(maxLength,0,0);
+
-
      noStroke();
+
-
 
+
-
        for(int i = 0; i < lengthOfHold; i++){
+
-
          beginShape();
+
-
          fill(colour[i]);
+
-
          for(float u = i*TWO_PI/maxLength; u <= (i+1)*TWO_PI/maxLength; u += step){
+
-
            vertex(cos(u)*sizeR/2, sin(u)*sizeR/2);
+
-
          }
+
-
          vertex(cos((i+1)*TWO_PI/maxLength)*sizeR/2, sizeR/2*sin((i+1)*TWO_PI/maxLength));
+
-
          for(float u = (i+1)*TWO_PI/maxLength; u >= (i)*TWO_PI/maxLength; u -= step){
+
-
            vertex(cos(u)*sizeR2/2, sizeR2/2*sin(u));
+
-
          }
+
-
          vertex(cos((i)*TWO_PI/maxLength)*sizeR2/2, sizeR2/2*sin((i)*TWO_PI/maxLength));
+
-
          endShape();
+
-
          fill(0);
+
-
          text(hold[i], cos((i+0.5)*TWO_PI/maxLength)*sizeR2/2, sizeR2/2*sin((i+0.5)*TWO_PI/maxLength));
+
-
        }
+
-
       
+
-
      fill(emptyColour);
+
-
      noStroke();
+
-
      beginShape();
+
-
        for(float u = 0; u >= -(maxLength-lengthOfHold)*TWO_PI/maxLength; u -= step){
+
-
          vertex(cos(u)*sizeR/2, sin(u)*sizeR/2);
+
-
        }
+
-
        vertex(cos(-(maxLength-lengthOfHold)*TWO_PI/maxLength)*sizeR/2, sizeR/2*sin(-(maxLength-lengthOfHold)*TWO_PI/maxLength));
+
-
        for(float u = -(maxLength-lengthOfHold)*TWO_PI/maxLength; u <= 0; u += step){
+
-
          vertex(cos(u)*sizeR2/2, sin(u)*sizeR2/2);
+
-
        }
+
-
        vertex(sizeR2/2, 0);
+
-
      endShape();
+
-
    popMatrix();
+
-
  }
+
-
 
+
-
  void check(String holdQ, color colourQ){
+
-
    float angle = atan2((mouseY-posY-sizeR/2),( mouseX-posX-sizeR/2));
+
-
      if(angle < 0){
+
-
        angle = TWO_PI + angle;
+
-
      }
+
-
    int clickPiece = floor(angle/TWO_PI * maxLength);
+
-
    if((mouseX <= (posX + sizeR)) && (mouseX > posX) && (mouseY <= (posY + sizeR)) && (mouseY > posY) && (hold.length < maxLength)){
+
-
      if((hold.length < maxLength) && (hold.length < clickPiece)){
+
-
        hold=append(hold, holdQ);
+
-
        colour=append(colour, colourQ);
+
-
      } else {
+
-
       
+
-
        if((hold.length >= clickPiece) && (millis()-lastRemove > 100)){
+
-
          String[] holdQQ = subset(hold, clickPiece);
+
-
          color[] colourQQ = subset(colour, clickPiece);
+
-
          hold = append(subset(hold, 0, clickPiece), holdQ);
+
-
          colour = append(subset(colour, 0, clickPiece), colourQ);
+
-
         
+
-
          for(int i = 0; i < holdQQ.length; i++){
+
-
            hold=append(hold, holdQQ[i]);
+
-
            colour=append(colour, colourQQ[i]);
+
-
          }
+
-
          lastRemove = millis();
+
-
        }
+
-
      }
+
-
    }
+
-
  }
+
-
  boolean removePiece(){
+
-
    float angle = atan2((mouseY-posY-sizeR/2),( mouseX-posX-sizeR/2));
+
-
    if(angle < 0){
+
-
      angle = TWO_PI + angle;
+
-
    }
+
-
    int clickPiece = floor(angle/TWO_PI * maxLength);
+
-
    if((mouseX <= (posX + sizeR)) && (mouseX > posX) && (mouseY <= (posY + sizeR)) && (mouseY > posY) && (hold.length >= clickPiece) && (millis()-lastRemove > 100)){
+
-
      String[] holdQ = subset(hold, clickPiece);
+
-
      color[] colourQ = subset(colour, clickPiece);
+
-
      hold = subset(hold, 0, clickPiece);
+
-
      colour = subset(colour, 0, clickPiece);
+
-
      for(int i = 1; i < holdQ.length; i++){
+
-
        hold=append(hold, holdQ[i]);
+
-
        colour=append(colour, colourQ[i]);
+
-
      }
+
-
      lastRemove = millis();
+
-
      return true;
+
-
    } else{
+
-
      return false;
+
-
    }
+
-
  }
+
-
}
+
-
 
+
-
class SubLevel{
+
-
  String demands[];
+
-
  String demands2[];
+
-
  PImage logo;
+
-
  PImage description;
+
-
  PImage wellDone;
+
-
  boolean past = false;
+
-
  boolean locked = true;
+
-
  int masterPos;
+
-
  int subPose;
+
-
 
+
-
  SubLevel(String[] demandsQ, String[] demands2Q, PImage logoQ, PImage descQ, PImage wellDoneQ, int masterPosQ, int subPoseQ){
+
-
    demands = demandsQ;
+
-
    demands2 = demands2Q;
+
-
    logo = logoQ;
+
-
    description = descQ;
+
-
    wellDone = wellDoneQ;
+
-
    masterPos = masterPosQ;
+
-
    subPose = subPoseQ;
+
-
  }
+
-
 
+
-
 
+
-
 
+
-
  boolean check(String[] currentPlasQ){
+
-
//    past = true;
+
-
//   
+
-
//    if(currentPlasQ.length==demands.length){
+
-
//      for(int i = 0; i < demands.length; i++){
+
-
//        if(currentPlasQ[i] != demands[i]){
+
-
//          past = false;
+
-
//          break;
+
-
//        }
+
-
//      }
+
-
//    }else{
+
-
//      past = false;
+
-
//    }
+
-
//   
+
-
//    return past;
+
-
    past = true;
+
-
    boolean firstCorrect = false;
+
-
    int firstDNAPiece = 0;
+
-
    String[] stringLine1;
+
-
    String[] stringLine2;
+
-
    if(demands.length!=0){
+
-
    for(int i = 0; i < currentPlasQ.length; i++){
+
-
      if(currentPlasQ[i] == demands[0]){
+
-
        firstCorrect = true;
+
-
        firstDNAPiece = i;
+
-
        break;
+
-
      }
+
-
    }
+
-
   
+
-
    stringLine1 = subset(currentPlasQ, firstDNAPiece, currentPlasQ.length-firstDNAPiece);
+
-
    stringLine2 = subset(currentPlasQ, 0, firstDNAPiece);
+
-
 
+
-
    for(int u = 0; u < stringLine2.length; u++){
+
-
      stringLine1 = append(stringLine1, stringLine2[u]);
+
-
    }
+
-
   
+
-
    currentPlasQ = stringLine1;
+
-
   
+
-
   
+
-
    if((currentPlasQ.length==demands.length) && (firstCorrect)){
+
-
      for(int i = 0; i < demands.length; i++){
+
-
        if(currentPlasQ[i] != demands[i]){
+
-
          past = false;
+
-
          break;
+
-
        }
+
-
      }
+
-
    }else{
+
-
      past = false;
+
-
    }
+
-
    }else{
+
-
      if(currentPlasQ.length==0){ past = true; }else{ past = false; }
+
-
    }
+
-
    return past;
+
-
  }
+
-
 
+
-
  boolean check2(String[] currentPlasQ){
+
-
    past = true;
+
-
    boolean firstCorrect = false;
+
-
    int firstDNAPiece = 0;
+
-
    String[] stringLine1;
+
-
    String[] stringLine2;
+
-
    if(demands2.length!=0){
+
-
      for(int i = 0; i < currentPlasQ.length; i++){
+
-
        if(currentPlasQ[i] == demands2[0]){
+
-
          firstCorrect = true;
+
-
          firstDNAPiece = i;
+
-
          break;
+
-
        }
+
-
      }
+
-
   
+
-
    stringLine1 = subset(currentPlasQ, firstDNAPiece, currentPlasQ.length-firstDNAPiece);
+
-
    stringLine2 = subset(currentPlasQ, 0, firstDNAPiece);
+
-
 
+
-
    for(int u = 0; u < stringLine2.length; u++){
+
-
      stringLine1 = append(stringLine1, stringLine2[u]);
+
-
    }
+
-
   
+
-
    currentPlasQ = stringLine1;
+
-
   
+
-
   
+
-
    if((currentPlasQ.length==demands2.length) && (firstCorrect)){
+
-
      for(int i = 0; i < demands2.length; i++){
+
-
        if(currentPlasQ[i] != demands2[i]){
+
-
          past = false;
+
-
          break;
+
-
        }
+
-
      }
+
-
    }else{
+
-
      past = false;
+
-
    }
+
-
    }else{
+
-
      if(currentPlasQ.length==0){ past = true; }else{ past = false; }
+
-
    }
+
-
    return past;
+
-
  }
+
-
 
+
-
  void rewardThatShit(){
+
-
    reward(masterPos, subPose);
+
-
  }
+
-
}
+
-
 
+
-
void reward(int master, int sub){
+
-
  switch(master){
+
-
   
+
-
    case 1:
+
-
      rewardSub1(sub);
+
-
      break;
+
-
    case 2:
+
-
      rewardSub2(sub);
+
-
      break;
+
-
    case 3:
+
-
      rewardSub3(sub);
+
-
      break;
+
-
    case 4:
+
-
      rewardSub4(sub);
+
-
      break;
+
-
  }
+
-
}
+
-
//pieceOfDNAForUse
+
-
//plasmide1.maxLength
+
-
 
+
-
 
+
-
 
+
-
 
+
-
void rewardSub1(int sub){
+
-
 
+
-
  switch(sub){
+
-
    case 1:
+
-
      pieceOfDNAForUse += 1;
+
-
      plasmide1.maxLength++;
+
-
      break;
+
-
    case 2:
+
-
      pieceOfDNAForUse++;
+
-
      plasmide1.maxLength++;
+
-
      break;
+
-
    case 3:
+
-
      pieceOfDNAForUse++;
+
-
      plasmide1.maxLength+=2;
+
-
      break;
+
-
    case 4:
+
-
 
+
-
      break;
+
-
  }
+
-
}
+
-
 
+
-
void rewardSub2(int sub){
+
-
  switch(sub){
+
-
    case 1:
+
-
   
+
-
      break;
+
-
     
+
-
    case 2:
+
-
   
+
-
      break;
+
-
    case 3:
+
-
   
+
-
      break;
+
-
    case 4:
+
-
 
+
-
      break;
+
-
  }
+
-
}
+
-
 
+
-
void rewardSub3(int sub){
+
-
  switch(sub){
+
-
    case 1:
+
-
   
+
-
      break;
+
-
     
+
-
    case 2:
+
-
   
+
-
      break;
+
-
    case 3:
+
-
   
+
-
      break;
+
-
    case 4:
+
-
 
+
-
      break;
+
-
  }
+
-
}
+
-
 
+
-
void rewardSub4(int sub){
+
-
  switch(sub){
+
-
    case 1:
+
-
   
+
-
      break;
+
-
     
+
-
    case 2:
+
-
   
+
-
      break;
+
-
    case 3:
+
-
   
+
-
      break;
+
-
    case 4:
+
-
 
+
-
      break;
+
-
  }
+
}
}
</script><canvas width="640" height="360" tabindex="0" id="__processing0" style="image-rendering: -webkit-optimize-contrast !important;"></canvas>
</script><canvas width="640" height="360" tabindex="0" id="__processing0" style="image-rendering: -webkit-optimize-contrast !important;"></canvas>

Revision as of 14:17, 17 July 2014

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Clock \ Examples \ Processing.org

 

AAAAAAAA