Advertisement
Guest User

geneHack

a guest
Feb 2nd, 2011
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 21.65 KB | None | 0 0
  1.  
  2. // "geneHack" by James Mulholland
  3. // a family tree viewer (prototype)
  4. // compatible with GEDCOM files (.ged)
  5. /// for Interactive Art & Computational Design, Spring 2011
  6. /// Carnegie Mellon University
  7.  
  8. // used some code as a very basic starting point - http://forum.processing.org/topic/simple-file-manipulation
  9.  
  10. import java.util.*;
  11. import processing.pdf.*;
  12.  
  13. String[] records;
  14.  
  15. ArrayList<Person> people = new ArrayList<Person>(); //create people array
  16. ArrayList<Family> families = new ArrayList<Family>(); //create family array
  17. int count = 0;
  18. int totalPeople = 0;
  19. int totalFamilies = 0;
  20.  
  21. int rectHeight = 12;
  22. int rectWidth = 12;
  23.  
  24. Map familyHash = new HashMap();
  25. ArrayList myList;
  26.  
  27. void setup()
  28. {
  29.   frameRate(10);
  30.   //  size(2200, 1000, PDF, "filename.pdf");
  31.   size(2200, 1000);
  32.  
  33.   smooth();
  34.   background(100);
  35.  
  36.   ///////////////////////////////////////////// reads a .ged file and prints
  37.   records = loadStrings("/my.ged");
  38.  
  39.   //scans through lines and finds the start of a record, prints location of record
  40.   createFamilies();
  41.   createIndividuals();
  42.  
  43.   //display people
  44.  
  45.   println("The eldest member of the tree is " + earliestPerson().NAME + " " + earliestPerson().FAMS);
  46.  
  47.   //start drawing family ... with ME!
  48.   Family sFamily = (Family) familyHash.get("F1992");
  49.   drawNodes(sFamily.children.get(0), 50, 0);
  50. //  
  51. //  Family sFamily = (Family) familyHash.get("F1098");
  52. //  drawNodes(sFamily.children.get(0), width/2, 0);  
  53.  
  54. //  ////////CLEAN UP non-drawn pieces if relationships weren't 100% in-tact
  55. //  for (int i = 0; i < people.size() ; i++)
  56. //  {
  57. //    Person current = people.get(i);
  58. //    if (current.isDrawn == false) {
  59. //      drawNodes(current, 100, 0);
  60. //    }
  61. //  }
  62. //  println(sFamily.children.get(0).x + "," + sFamily.children.get(0).y);
  63. }
  64.  
  65. void draw() {
  66.   //display time periods rectangles
  67.   rectMode(CORNER);
  68.   stroke(100);
  69.   fill(255);
  70.   rect(0,0,width,height); //pre-modern Britain
  71.   fill(255);
  72.   rect(0,500,width,height-500); //Early Modern Britain
  73.   fill(255);
  74.   rect(0,850,width,height-850); //Early 20th century
  75.   fill(255);
  76.   rect(0,922,width,height-922); //
  77.  
  78.   for (int i = 0; i < people.size() ; i++) {
  79.     people.get(i).isDrawn = false;
  80.     people.get(i).display();
  81.   }
  82.  
  83.   highlight();
  84.  
  85.   //  println("Finished.");
  86.   //  exit();
  87. }
  88.  
  89.  
  90. void highlight() {
  91.   Person p = null;
  92.   for (int i = 0; i < people.size() ; i++)
  93.   {
  94.     p = people.get(i);
  95.     if (mouseX > (p.x - rectWidth/2) && mouseX < (p.x + rectWidth/2) && mouseY > (p.y - rectHeight/2) && mouseY < (p.y+rectHeight/2))
  96.     {
  97.       //if mouseX is greater
  98.  
  99.       println(p.NAME + " is now 'Selected'");
  100.       p.showDetail();
  101.     }
  102.     //    if (mouseY > (p.y - rectHeight/2) && mouseY < (p.y+rectHeight/2))
  103.     //    {
  104.     //      //if mouseX is greater
  105.     ////      p.selected = true;
  106.     //      println(p.NAME + " is now 'Selected'");
  107.     //      p.showDetail();
  108.     //    }
  109.   }
  110. }
  111.  
  112.  
  113. //void keyPressed() {
  114. // Person p = null;
  115. //  for (int i = 0; i < people.size() ; i++)
  116. //  {
  117. //    p = people.get(i);
  118. //    p.NAME = people.get(i).NAME;  
  119. //    if (p.NAME.charAt(0) == key) {
  120. //      p.showDetail();
  121. //      
  122. //    }
  123. //  }
  124. //}
  125.  
  126.  
  127. ////////////////////////////////////////////////////////////////////////////////////////////////////
  128. ////PARSING/////////////////////////////////////////////////////////////////////////////////////////
  129. ////////////////////////////////////////////////////////////////////////////////////////////////////
  130. void createIndividuals()
  131. {
  132.   count = 0;
  133.   for(int i = 0; i < records.length; i++) // scan through lines of data file
  134.   {
  135.     //////////////
  136.     /////CREATE A NEW RECORD
  137.     //////////////
  138.     if (records[i].charAt(0) == ('0') && records[i].charAt(2) == '@') // if a new record is found (indicated by "0 @")
  139.     {
  140.       String newID; //newID variable starts with value of char after first @
  141.       String newName;
  142.       String newSurname;
  143.       String newGiven;
  144.       char newSex;
  145.       String newDOB;
  146.       String newPOB;
  147.       String newDOD;
  148.       String newPOD;
  149.       String newUID;
  150.       String newFAMS;
  151.       String newFAMC;
  152.  
  153.       //////INDIVIDUALS//////
  154.       if (records[i].charAt(records[i].length()-1) == 'I') // if the record is for an individual "the line ends in I"
  155.       {
  156.         println("new person record at " + i); //print note of new records location
  157.         //Record the ID
  158.         newID = records[i].substring(3);
  159.         newID = newID.replace("@ INDI","");
  160.         Person newPerson = new Person(newID);
  161.         people.add(newPerson);
  162.  
  163.  
  164.         // people.get(people.size()-1);
  165.  
  166.         //Get information to create new individual
  167.         for (int x = 1 ; x < 16 ; x++)
  168.         {
  169.           int rowNum = x+i; // row number relative to the start of new record
  170.  
  171.           if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == 'N' && records[rowNum].charAt(3) == 'A') // if a NAME record is found (indicated by "1 N", short for 1 NAME)
  172.           {
  173.             newName = records[rowNum].substring(7); //Parse Full Name
  174.             newName = newName.replace("/",""); //remove "/" separators
  175.             newPerson.NAME = newName;
  176.           }
  177.           else if (records[rowNum].charAt(0) == ('2') && records[rowNum].charAt(2) == 'S') // if a surname is found (indicated by "2 S", short for 2 SURN)
  178.           {
  179.             newSurname = records[rowNum].substring(7); //Parse Surname
  180.             newPerson.SURN = newSurname;
  181.           }
  182.           else if (records[rowNum].charAt(0) == ('2') && records[rowNum].charAt(2) == 'G') // if a given name is found (indicated by "2 G", short for 2 GIVN)
  183.           {
  184.             newGiven = records[rowNum].substring(7); //Parse Given Name
  185.             newPerson.GIVN = newGiven;
  186.           }
  187.           else if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == 'S') // if a gender is found (indicated by "1 S", short for 1 SEX)
  188.           {
  189.             newSex = records[rowNum].charAt(6); //Parse Sex
  190.             newPerson.SEX = newSex;
  191.           }
  192.           else if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == 'B') // if birth info is found (indicated by "1 B", short for 1 BIRT)
  193.           {
  194.             for (int y = 1 ; y < 3 ; y++ )
  195.             {
  196.               rowNum += y;
  197.               if (records[rowNum].charAt(0) == ('2') && records[rowNum].charAt(2) == 'D') //if birthdate info is found (indicated by "2 D", short for 2 DATE)
  198.               {
  199.                 newDOB = records[rowNum].substring(records[rowNum].length() - 4); //Parse DOB
  200.  
  201.                 // thanks to the following site for this bit of try/catch code - http://www.devdaily.com/java/edu/qanda/pjqa00010.shtml
  202.                 try
  203.                 {
  204.                   // the String to int conversion happens here
  205.                   newPerson.DOB = Integer.parseInt(newDOB.trim());
  206.  
  207.                   // print out the value after the conversion
  208.                   println("int newPerson.DOB = " + newPerson.DOB);
  209.                 }
  210.                 catch (NumberFormatException nfe)
  211.                 {
  212.                   println("NumberFormatException: " + nfe.getMessage());
  213.                 }
  214.               }
  215.               else if (records[rowNum].charAt(0) == ('2') && records[rowNum].charAt(2) == 'P') //if birthplace info is found (indicated by "2 P", short for 2 PLAC)
  216.               {
  217.                 newPOB = records[rowNum].substring(7); //Parse POB
  218.                 newPerson.POB = newPOB;
  219.               }
  220.             }
  221.           }
  222.           else if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == 'D') // if death info is found (indicated by "1 B", short for 1 DEAT)
  223.           {
  224.             for (int y = 1 ; y < 3 ; y++ )
  225.             {
  226.               rowNum += y;
  227.               if (records[rowNum].charAt(0) == ('2') && records[rowNum].charAt(2) == 'D') //if deathdate info is found (indicated by "2 D", short for 2 DATE)
  228.               {
  229.                 newDOD = records[rowNum].substring(records[rowNum].length() - 4); //Parse DOD
  230.  
  231.                 // thanks to the following site for this bit of try/catch code - http://www.devdaily.com/java/edu/qanda/pjqa00010.shtml
  232.                 try
  233.                 {
  234.                   // the String to int conversion happens here
  235.                   newPerson.DOD = Integer.parseInt(newDOD.trim());
  236.  
  237.                   // print out the value after the conversion
  238.                   println("int newPerson.DOD = " + newPerson.DOD);
  239.                 }
  240.                 catch (NumberFormatException nfe)
  241.                 {
  242.                   println("NumberFormatException: " + nfe.getMessage());
  243.                 }
  244.               }
  245.               else if (records[rowNum].charAt(0) == ('2') && records[rowNum].charAt(2) == 'P') //if deathplace info is found (indicated by "2 P", short for 2 PLAC)
  246.               {
  247.                 newPOD = records[rowNum].substring(7); //Parse POB
  248.               }
  249.             }
  250.           } //end else if death info is found
  251.           else if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == '_') // if UID is found (indicated by "1 _", short for 1 _UID)
  252.           {
  253.             newUID = records[rowNum].substring(7); //Parse UID
  254.           }
  255.           else if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == 'F' && records[rowNum].charAt(5) == 'S') // if FAMS# is found (indicated by "1 F--S", short for 1 FAMS)
  256.           {
  257.             newFAMS = records[rowNum].substring(8); //Parse FAMS
  258.             newFAMS = newFAMS.replace("@",""); //remove "@"
  259.             if (newPerson.FAMS == null) {
  260.               newPerson.FAMS = newFAMS;
  261.             }
  262.             //check if family exists in map
  263.             //if yes, get family
  264.             //add to F...
  265.             //if no, create family
  266.             //add to family
  267.  
  268.             ////////////
  269.  
  270.             Family sFamily = (Family) familyHash.get(newFAMS);
  271.             //            println(newFAMS + ": is null " + (sFamily == null)); //COmment in to debug if Family exists
  272.  
  273.             if (familyHash.containsKey(newFAMS) == false)
  274.             {
  275.               familyHash.put(newFAMS, sFamily);
  276.             }
  277.  
  278.             if (newFAMS != null && newPerson.SEX == 'M') //Determine if male sire
  279.             {
  280.               sFamily.father = newPerson;
  281.             }
  282.             else if (newFAMS != null && newPerson.SEX == 'F') //Determine if female sire
  283.             {
  284.               sFamily.mother = newPerson;
  285.             }  
  286.  
  287.             if (sFamily.children.isEmpty() == false)
  288.             {
  289.               println(newPerson.NAME + " (born " + newPerson.DOB + ") is the parent of " +  sFamily.children.get(0).NAME ) ;
  290.             }  
  291.             ////////////
  292.           }
  293.           else if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == 'F' && records[rowNum].charAt(5) == 'C') // if FAMC# is found (indicated by "1 F--S", short for 1 FAMC)
  294.           {
  295.             newFAMC = records[rowNum].substring(8); //Parse FAMC
  296.             newFAMC = newFAMC.replace("@",""); //remove "@"
  297.             newPerson.FAMC = newFAMC;
  298.  
  299.             ////////////
  300.             if (newFAMC != null) //Determine if child
  301.             {
  302.               if (familyHash.containsKey(newFAMC) == false)
  303.               {
  304.                 familyHash.put(newFAMC, new Family());
  305.               }
  306.  
  307.               Family cFamily = (Family) familyHash.get(newFAMC);
  308.               cFamily.children.add(newPerson); //add children to array list
  309.  
  310.               //              if (cFamily.father.isEmpty() == false)
  311.               //              {
  312.               //                println(newPerson.NAME + " is the child of " +  sFamily.father.get(0).NAME ) ;
  313.               //              }
  314.             }
  315.             ////////////
  316.           }
  317.  
  318.           //if new record found, STOP and CONTINUE ON
  319.  
  320.  
  321.           if (records[rowNum].charAt(0) == ('0'))
  322.           {
  323.             break;
  324.           }
  325.         }
  326.         totalPeople += 1;
  327.       }
  328.       count += 1; //advance record
  329.     }
  330.   }
  331.   println(records.length + " lines of data");
  332.   println(totalPeople + " total people records");
  333. }
  334.  
  335.  
  336.  
  337. ///////////////Method to get data from Family data and create f=Family objects in the 'families' array
  338. void createFamilies()
  339. {
  340.   count = 0;
  341.   for(int i = 0; i < records.length; i++) // scan through lines of data file
  342.   {
  343.     if (records[i].charAt(0) == ('0') && records[i].charAt(2) == '@') // if a new record is found (indicated by "0 @")
  344.     {
  345.       //////FAMILIES//////
  346.       if (records[i].charAt(records[i].length()-1) == 'M') // if the record is for an family, the line ends in FAM
  347.       {
  348.         String newID = "_";
  349.         String newUID = "_";
  350.         String newHUSB = "_";
  351.         String newWIFE = "_";
  352.         String newDOM = "_";
  353.         String newPOM = "_";
  354.  
  355.         println("new family record at " + i); //print note of new records location
  356.         //Record the ID
  357.         newID = records[i].substring(3);
  358.         newID = newID.replace("@ FAM","");
  359.         Family newFamily = new Family();
  360.         families.add(newFamily);
  361.         println("(" + newID + ")");
  362.         newFamily.ID = newID;
  363.  
  364.         //check for hash.
  365.         if (familyHash.containsKey(newID) == false)
  366.         {
  367.           familyHash.put(newID, newFamily);
  368.         }
  369.         //        families.add(new Family(newID, newUID, newHUSB, newWIFE, newDOM, newPOM)); //create new person with properties defined by above parsing
  370.  
  371.         if (familyHash.containsKey(newID) == true)
  372.         {
  373.  
  374.  
  375.           //Get information to create new family
  376.           for (int x = 1 ; x < 7; x++)
  377.           {
  378.             int rowNum = x+i;
  379.  
  380.             if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == '_') // if UID is found (indicated by "1 _", short for 1 _UID)
  381.             {
  382.               newUID = records[rowNum].substring(7); //Parse UID
  383.             }
  384.             else if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == 'H') // if husband info is found (indicated by "1 H", short for 1 HUSB)
  385.             {
  386.               newHUSB = records[rowNum].substring(7); //Parse HUSB
  387.               newHUSB = newHUSB.replace("@",""); //remove "@"
  388.             }
  389.             else if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == 'W') // if wife info is found (indicated by "1 W", short for 1 WIFE)
  390.             {
  391.               newWIFE = records[rowNum].substring(7); //Parse WIFE
  392.               newWIFE = newWIFE.replace("@",""); //remove "@"
  393.             }
  394.             else if (records[rowNum].charAt(0) == ('1') && records[rowNum].charAt(2) == 'M') // if marriage info is found (indicated by "1 M", short for 1 MARR)
  395.             {
  396.               for (int y = 1 ; y < 3 ; y++ )
  397.               {
  398.                 rowNum += y;
  399.                 if (records[rowNum].charAt(0) == ('2') && records[rowNum].charAt(2) == 'D') // if date of marriage info is found (indicated by "2 D", short for 2 DATE)
  400.                 {
  401.                   newDOM = records[rowNum].substring(7); //Parse DOM
  402.                 }
  403.                 else if (records[rowNum].charAt(0) == ('2') && records[rowNum].charAt(2) == 'P') // if place of marriage info is found (indicated by "2 P", short for 2 PLACE)
  404.                 {
  405.                   newPOM = records[rowNum].substring(7); //Parse POM
  406.                 }
  407.               }
  408.             }
  409.             //if new record found, STOP and CONTINUE ON
  410.             else if (records[rowNum].charAt(0) == ('0'))
  411.             {
  412.               break;
  413.             }
  414.           }
  415.         }
  416.         println(newID + " " + newUID + " (" + newHUSB + ", " + newWIFE + ") " + newDOM + ", " + newPOM); //print out new record
  417.         totalFamilies += 1;
  418.       }
  419.       count += 1; //advance record
  420.     }
  421.   }
  422.   println(records.length + " lines of data");
  423.   println(totalFamilies + " total family records");
  424. }
  425.  
  426. //////SOURCES//////
  427. //////NOTES////////
  428.  
  429. class Family //new Person(newID, newUID, newHUSB, newWIFE, newDOM, newPOM);
  430. {
  431.   String ID; // unique ID for entry
  432.   String UID;
  433.   String HUSB;
  434.   String WIFE;
  435.   String DOM;
  436.   String POM;
  437.   Person father;
  438.   Person mother;
  439.   ArrayList<Person> children = new ArrayList<Person>();
  440.  
  441.   Family (
  442. //  String iID,
  443. //  String iUID,
  444. //  String iHUSB,
  445. //  String iWIFE,
  446. //  String iDOM,
  447. //  String iPOM
  448.     )
  449.  
  450.   {
  451. //    ID = iID;
  452. //    UID = iUID;
  453. //    HUSB = iHUSB;
  454. //    WIFE = iWIFE;
  455. //    DOM = iDOM;
  456. //    POM = iPOM;
  457.   }
  458. }
  459.  
  460. void drawNodes(Person main, float ix, int gen) {
  461.   float DOBmult = 1;
  462.   int DOBadd = -1000;
  463.   int yearBuffer = 40;
  464.  
  465.  
  466.   int genS = gen;
  467.   int genC = gen;
  468.   int genM = gen;
  469.   int genF = gen; //set gens to be modified separately for each new person form this one.
  470.   int xmodS = (int) (rectWidth/1.5); //sibling spacing
  471.   int xmodP = rectHeight; //parent spacing
  472.  
  473.   String FAMSID = main.FAMS;
  474.   String FAMCID = main.FAMC;
  475.   Family cFamily = (Family) familyHash.get(FAMCID); //get family for child-of
  476.   Family sFamily = (Family) familyHash.get(FAMSID); //get family for sire-of
  477.  
  478.  
  479.  
  480.  
  481.   //////DISPLAY PERSON
  482.   if (main.isDrawn == false) {
  483.     main.x = ix; //draw using modifier passed from parameter
  484.  
  485.     main.GEN = gen; //set generation of Person to passed value
  486.  
  487.  
  488.     if (main.DOB == 0) //if no DOB data
  489.     {
  490.       println("Trying to find DOB");
  491.      
  492.      
  493.       if (cFamily != null && cFamily.children.size() > 0) //if cFamily is OK -&- there ARE children
  494.       {
  495.         for (int i = 0 ; i < cFamily.children.size() ; i++) //go through siblings
  496.         {
  497.           if (cFamily.children.get(i).DOB > 0) //if a sibling has DOB not 0,  copy it
  498.           {
  499.             main.DOB = cFamily.children.get(i).DOB;
  500.             break;
  501.           }
  502.         }
  503.       }
  504.       if (main.DOB == 0 && sFamily != null) //if STILL 0 -&- is parent
  505.       {
  506.         println(sFamily.ID);
  507.         if (sFamily.children.size() > 0) // if person has children
  508.         {  
  509.           for (int c = 0 ; c < sFamily.children.size() ; c++) //go through children
  510.           {
  511.             if (sFamily.children.get(c).DOB > 0) //if child's age is OK
  512.             {
  513.               main.DOB = sFamily.children.get(c).DOB - 30; //take child's DOB and subtract 30 to get est. year
  514.               break;
  515.             }
  516.           }
  517.         }
  518.       }
  519.     }
  520.  
  521.   if (main.DOB != 0)
  522.   {
  523.     //main.y = (main.DOB*DOBmult)+DOBadd; //manipulate DOB to get y-coord
  524.     main.y = main.DOB+DOBadd;
  525.   }
  526.   else {
  527.     main.y = 500;
  528.   }
  529.   main.display();
  530.  
  531.   ///////IF PERSON IS A CHILD (has FAMC) - find siblings, find parents
  532.   if (cFamily != null && cFamily.children.size() > 0)
  533.   {
  534.     println("FAMC = " + cFamily.ID);
  535.  
  536.     ////draw siblings
  537.     for( int s = 0 ; s < cFamily.children.size() ; s++ )
  538.     {
  539.       Person child = cFamily.children.get(s); //get all siblings
  540.       if (child.isDrawn == false)
  541.       {
  542.         //no gen modifier, sibling is same gen
  543.         int sib = s;
  544.  
  545.         //          if (s % 2 > 0) {
  546.         //            sib = s*-1;
  547.         //          }
  548.  
  549.         drawNodes(child, main.x+xmodS*sib, genS); //xmodifier
  550.       }
  551.     }
  552.  
  553.     ////draw parents
  554.     if (cFamily.father != null) //if person has father
  555.     {
  556.       genF += 1;
  557.       drawNodes(cFamily.father, main.x-xmodP, genF);//draw father
  558.     }
  559.  
  560.     if (cFamily.mother != null) //if person has mother
  561.     {
  562.       genM += 1;
  563.       drawNodes(cFamily.mother, main.x+xmodP, genM);//draw mother
  564.     }
  565.   } //end if cFamily
  566.  
  567.  
  568.  
  569.   ///////IF PERSON IS A PARENT (has FAMS)
  570.   if (sFamily != null)
  571.   {
  572.     //      println("FAMS = " + sFamily.ID);
  573.     //find children()
  574.     //if child is not drawn
  575.     //display
  576.   } //end if sFamily is null
  577. } //end if main
  578. } //end drawNodes
  579.  
  580. Person earliestPerson() {
  581.   int earlyYear = 3000;
  582.   Person earlyPerson = new Person();
  583.  
  584.   for (int i = 0 ; i < people.size() ; i++) {
  585.     if (people.get(i).DOB > 0 && people.get(i).DOB < earlyYear) {
  586.       earlyYear = people.get(i).DOB;
  587.       earlyPerson = people.get(i);
  588.     }
  589.   }
  590.  
  591.   return earlyPerson;
  592. }
  593.  
  594. class Person
  595. {
  596.   String ID; // unique ID for entry
  597.   String NAME; // full name string of person
  598.   String SURN; // surname of person
  599.   String GIVN; // given name of person
  600.   char SEX; // sex of person (M or F)
  601.   String BIRT; // birthdate of person
  602.   int DOB; //
  603.   String POB;
  604.   int DOD;
  605.   String POD;
  606.   String UID;
  607.   String FAMS;
  608.   String FAMC;
  609.   Person Mom;
  610.   Person Dad;
  611.   ArrayList<Person> children = new ArrayList();
  612.   float x, y;
  613.   boolean isDrawn = false;
  614.   int GEN = 0;
  615.   boolean selected = false;
  616.  
  617.  
  618.   Person (
  619.   String iID
  620.     //  String iNAME,
  621.   //  String iSURN,
  622.   //  String iGIVN,
  623.   //  char iSEX,
  624.   //  String iDOB,
  625.   //  String iPOB,
  626.   //  String iDOD,
  627.   //  String iPOD,
  628.   //  String iUID,
  629.   //  String iFAMS,
  630.   //  String iFAMC
  631.   )
  632.   {
  633.     ID = iID;
  634.     x = width/2;
  635.     y = height-20;
  636.     isDrawn = false;
  637.  
  638.     //    NAME = iNAME;
  639.     //    SURN = iSURN;
  640.     //    GIVN = iGIVN;
  641.     //    SEX = iSEX;
  642.     //    DOB = iDOB;
  643.     //    POB = iPOB;
  644.     //    DOD = iDOD;
  645.     //    POD = iPOD;
  646.     //    UID = iUID;
  647.     //    FAMS = iFAMS;
  648.     //    FAMC = iFAMC;
  649.   }
  650.  
  651.   Person () {
  652.   } //empty constructor
  653.  
  654.   void display()
  655.   {
  656.     if (isDrawn == false) {
  657.     noStroke();
  658.     fill(getFill(), 90);
  659.     rectMode(CENTER);
  660.     ellipseMode(CENTER);
  661.     ellipse(x, y, rectWidth, rectHeight);
  662.     fill(0);
  663.     textAlign(LEFT);
  664.     textSize(8);
  665.     println(NAME + " , " + x + " , " + y + " " + GEN);
  666.     if (selected == true)
  667.     {
  668.        text(NAME,x+(rectWidth/2)+3 , y+(textAscent()/2));
  669.     }
  670.     isDrawn = true;
  671.     }
  672.   }
  673.  
  674.   void showDetail() {
  675.     //highlight box
  676.     strokeWeight(1);
  677.     stroke(0);
  678.     fill(0,50,50,90);
  679.     rectMode(CENTER);
  680.     rect(x, y, rectWidth, rectHeight);
  681.     fill(0);
  682.     textAlign(LEFT);
  683.     textSize(8);
  684.     String newText = NAME + " " + DOB;
  685.     text(newText,x+(rectWidth/2)+3 , y+(textAscent()/2));
  686.   }
  687.  
  688.   color getFill()
  689.   {
  690.     color newColor;
  691.       int age = DOD-DOB;
  692.     age = (int) map(age, -20, 100, 0, 255);
  693.    
  694.     if (age <=40) {
  695.       newColor = color(150);
  696.     }
  697.     else if (DOB > 1922) //current
  698.     {
  699.     newColor = color(age,age,50);
  700.     }
  701.     else if (DOB > 1851) //Early 20th century
  702.     {
  703.       newColor = color(0,age, age);
  704.     }
  705.     else if (DOB > 1500) //Early Modern Britain
  706.     {
  707.       newColor = color(age, 0, age);
  708.     }
  709.      else
  710.      {
  711.      newColor = color(age);
  712.      
  713.     }
  714.    
  715.     return newColor;
  716.   }
  717. } //End class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement