import processing.opengl.*; import proxml.*; /*static public void main(String args[]) { PApplet.main(new String[] { "--present", "demo_fl_mode" }); }*/ // save data to xml XMLElement users; XMLInOut xmlInOut; PFont font_meta11, font_meta24, font_meta14, font_meta12, font_meta10, font_meta18, font_meta48,font_meta20; // basic information int sw=900; int sh=700; // counting for add object int count=0; int userCount; // variable for detecting collision int over; int sameid; int[] sidArray; float targeup; Nodeflower[] nodef,nodef_1; UIset uset; //topEmotion float eW,eH; boolean initiation; boolean saveb; boolean startGui; boolean othersOver; // UserArc active boolean isActive; boolean isAniStart; float scaleAni; // user input variable array int[] genderArray; int[] ageArray; int[] locationArray; String[] nameArray; String[] commentArray; String[] emotionArray; String[] shapeArray_s; float[] shapeArray_00, shapeArray_01, shapeArray_02, shapeArray_03, shapeArray_04, shapeArray_05, shapeArray_06, shapeArray_07; int[] rv,gv,bv; // start button Button2 start_b; EmotionColor[] emotionTop; //timecheck float timeCheck; boolean startHide; // draw sample flower Sflower[] sample; int sfNum; //radomPlay int randomPlay; float updateCheck; //for the demo version String url = "http://www.experiencecode.com/prox/user.xml"; void setup(){ size(900,700,OPENGL); hint(ENABLE_OPENGL_4X_SMOOTH); frameRate=30; noStroke(); smooth(); //demo version---- xmlInOut = new XMLInOut(this); try{ xmlInOut.loadElement(url); XMLElement users = xmlInOut.loadElementFrom(url); } catch(Exception e){ //if the xml file could not be loaded it has to be created xmlInOut.loadElement(url); // xmlEvent(new XMLElement("users")); //xmlEvent(new XMLElement(url)); } //demo version---- /* //xml check---------------------------------- xmlInOut = new XMLInOut(this); try{ xmlInOut.loadElement("user.xml"); } catch(Exception e){ //if the xml file could not be loaded it has to be created xmlEvent(new XMLElement("users")); } // xml end---------------------------------------- */ //basic initiation = true; startGui = false; scaleAni =0.0; isAniStart = true; othersOver = false; // check starting of GUI; font_meta10 = loadFont("Meta-Normal-10.vlw"); font_meta11 = loadFont("Meta-Normal-11.vlw"); font_meta24 = loadFont("Meta-Normal-24.vlw"); font_meta14 = loadFont("Meta-Normal-14.vlw"); font_meta18 = loadFont("Meta-Normal-18.vlw"); font_meta12 = loadFont("Meta-Normal-12.vlw"); font_meta48 = loadFont("Meta-Normal-48.vlw"); font_meta20 = loadFont("Meta-Normal-20.vlw"); // array for same IDs of the node sidArray = new int[0]; // item_ GUI and nodeF count = users.countChildren(); nodef = new Nodeflower[count]; uset = new UIset((sw-760)/2,80); emotionTop = new EmotionColor[count]; // use this count after added data into xml userCount = 0; // user input variable array genderArray = new int[userCount]; ageArray = new int[userCount]; locationArray = new int[userCount]; nameArray = new String[userCount]; commentArray = new String[userCount]; emotionArray = new String[userCount]; shapeArray_00 = new float[userCount]; shapeArray_01 = new float[userCount]; shapeArray_02 = new float[userCount]; shapeArray_03 = new float[userCount]; shapeArray_04 = new float[userCount]; shapeArray_05 = new float[userCount]; shapeArray_06 = new float[userCount]; shapeArray_07 = new float[userCount]; rv = new int[userCount]; gv = new int[userCount]; bv = new int[userCount]; //topEmotion // start button start_b = new Button2("Start adding your flower ", 100, sh-50, 220, 20,10, 1,1,font_meta20 ); //get xmlelement ----------------------------------------- users.printElementTree(" "); XMLElement user_info; XMLElement user_demographic; XMLElement emotion; XMLElement evaluation; // data update from saved xml start----------------------------------------------------- if(users.countChildren()>0){ for(int i = 0; i < users.countChildren();i++){ user_info = users.getChild(i); user_demographic = user_info.getChild(0); emotion = user_info.getChild(1); evaluation = user_info.getChild(2); emotionArray = splice(emotionArray, emotion.getAttribute("selectedemotion"), i); rv = splice(rv, emotion.getIntAttribute("redV") ,i); gv = splice(gv, emotion.getIntAttribute("greenV") ,i); bv = splice(bv, emotion.getIntAttribute("blueV") ,i); // Question part02-evaluation shapeArray_00 = splice(shapeArray_00, evaluation.getFloatAttribute("question_00"),i); shapeArray_01 = splice(shapeArray_01, evaluation.getFloatAttribute("question_01"),i); shapeArray_02 = splice(shapeArray_02, evaluation.getFloatAttribute("question_02"),i); shapeArray_03 = splice(shapeArray_03, evaluation.getFloatAttribute("question_03"),i); shapeArray_04 = splice(shapeArray_04, evaluation.getFloatAttribute("question_04"),i); shapeArray_05 = splice(shapeArray_05, evaluation.getFloatAttribute("question_05"),i); shapeArray_06 = splice(shapeArray_06, evaluation.getFloatAttribute("question_06"),i); shapeArray_07 = splice(shapeArray_07, evaluation.getFloatAttribute("question_07"),i); locationArray = splice(locationArray, evaluation.getIntAttribute("location"), i); commentArray = splice(commentArray, evaluation.getAttribute("comment"),i); // Question part03-demographic genderArray = splice(genderArray, user_demographic.getIntAttribute("gender"), i); ageArray = splice(ageArray, user_demographic.getIntAttribute("age"), i); nameArray = splice( nameArray, user_demographic.getAttribute("name"), i); } } // data update from saved xml end----------------------------------------------------- for(int i = 0; i < count;i++){ float location = map(locationArray[i], 0, 100, 130, sw-130); nodef[i] = new Nodeflower(30+(ageArray[i]*25),random(100,sw-100), 0.5, ageArray[i], i, nodef);//location+ emotionTop[i] = new EmotionColor(100, sh-220, sw-200, 78, 3.0, i); } // sample flower sfNum = 150; sample = new Sflower[sfNum]; for(int i=0; i=5){ randomPlay = int(random(count)); updateCheck = 0; } // emotionTop[randomPlay].display(); emotionTop[randomPlay].randomP(randomPlay); userForRandom(randomPlay); } }//end of randomplay // hide mouse void hideMouse(){ if(mouseX-pmouseX == 0){ timeCheck += 0.1; if(timeCheck > 10){ startHide = true; timeCheck = 31; mouseX = sw; mouseY = sh; noCursor(); } } else if(mouseX-pmouseX !=0){ timeCheck =0; startHide = false; cursor(ARROW); } }//end of hide mouse //////////////////////////////////////////////////////////////////////////// void grid_up_display(){ int gLine_Num = 15; int gRow_Num = 5; int pointArr = gLine_Num*gRow_Num; float gap = 3; float sellwidth = (sw-200-((gLine_Num-1)*gap))/gLine_Num; float sellheight = (78-((gRow_Num-1)*gap))/gRow_Num; eW = sellwidth; eH = sellheight; for(int i=0; i< gLine_Num ; i++){ for(int j=0; j< gRow_Num ; j++){ stroke(255,40); fill(255,20); rect(int(100+(sellwidth+gap)*i), int(sh-220+(sellheight+gap)*j), int(sellwidth), int(sellheight)); noStroke(); } } } ///////////////////////////////////////////////////////////////////////// //user detail void userdetail(){ UserDeatilArc userDetailShape; for(int i = 0; i< count; i++){ userDetailShape = new UserDeatilArc(nodef[i].x1, nodef[i].y1-150, 0, 0, 0.5, 1, 220,i); if(nodef[i].topnodeR.isstop){ userDetailShape.display(); userDetailShape.textDisplay(); stroke(255,60); line(nodef[i].x2, nodef[i].y2, emotionTop[i].cenX, emotionTop[i].cenY); fill(255,60); ellipse(emotionTop[i].cenX, emotionTop[i].cenY, 10, 10); noStroke(); noFill(); } } }//end of userdetail //user detail for randomPlay void userForRandom(int k){ UserDeatilArc userDetailShape; userDetailShape = new UserDeatilArc(nodef[k].x1, nodef[k].y1-150, 0, 0, 0.5, 1, 220,k); userDetailShape.display(); userDetailShape.textDisplay(); stroke(255,60); line(nodef[k].x2, nodef[k].y2, emotionTop[k].cenX, emotionTop[k].cenY); fill(255,60); ellipse(emotionTop[k].cenX, emotionTop[k].cenY, 10, 10); noStroke(); noFill(); }//end of userForRandom //////////////////////////////////////////////////////////////////////// //hill void hill(float sx, int cn, color c){ int num = (sw/2+100)/10; float ybase = sh - 290; float d = (PI/2)/num; float[] xpos = new float[num]; float[] ypos = new float[num]; float[] lxpos = new float[num]; float[] lypos = new float[num]; float ht =100; float htu = ht/num; for(int i =1 ; i< num ; i++){ xpos[0] = sx; ypos[0] = ybase+20; lxpos[0] = sx; lypos[0] =ybase+50; xpos[i] = sx+10*(i); switch(cn){ case 1: ypos[i] = ybase - ht + (htu*i) + 30 * noise(0.05*(i-1)); break; case 2: ypos[i] = ybase - htu*(i-1) + 30* noise(0.05*(i-1)) ; break; } lxpos[i] = sx+10*(i); lypos[i] = ybase+50; noStroke(); beginShape(QUAD_STRIP); fill(c); vertex( xpos[i-1], ypos[i-1]); vertex( xpos[i], ypos[i]); fill(213,227,25); vertex( lxpos[i-1], lypos[i-1]); vertex( lxpos[i], lypos[i]); endShape(); } }// end of hill //grass void grass(){ int num = sw+50/10; float ybase = sh - 280; float[] xpos = new float[num]; float[] ypos = new float[num]; float[] lxpos = new float[num]; float[] lypos = new float[num]; for(int i =1 ; i< num ; i++){ xpos[0] = -50; ypos[0] = ybase; lxpos[0] = -50; lypos[0] =ybase; xpos[i] = 10*(i-1); ypos[i] = ybase- 35 + 30*noise(0.05*(i-1)); lxpos[i] = 10*(i-1); lypos[i] = ybase; //stroke(0); beginShape(QUAD_STRIP); fill(84,129,60); vertex( xpos[i-1], ypos[i-1]); vertex( xpos[i], ypos[i]); fill(30); vertex( lxpos[i-1], lypos[i-1]); vertex( lxpos[i], lypos[i]); endShape(); } fill(20); noStroke(); rect(0,sh-280,sw,280); }// end of grass // grid_display() void grid_display(){ for(int i=0; i< 11 ; i++){ if(i>=2){ fill(0,20); float grid = sh-280-(30+(25*i)); rect(0, grid+24, sw-100, 1); ellipse(sw-100,grid+24,6,6); String[] ageGroup = { "","","0-to-10 ","11-to-20","21-to-30","31-to-40","41-to-50","51-to-60","61-to-70","over 70s","Age Group" }; fill(0,100); textFont(font_meta11); text(ageGroup[i], int(sw-90) , grid+15); } } }//--- end of grid_display() //bg_display() void bg_display(){ float ha = (hour()+1); float hp = (hour()+1)-12; beginShape(QUAD_STRIP); if(hour() <= 12){ fill(ha*2, ha*5, ha*6); }else{ fill(24-hp*12,120-hp*12,146-hp*12); } vertex(sw, 0); vertex(0, 0); fill(255); vertex(sw, sh-290); vertex(0, sh-290); endShape(); }//- - end of bg_display() //watch void watch(float x, float y){ fill(255,80); textFont(font_meta11); String day_s = (day() <= 9) ? str(0)+str(day()) : str(day()); String month_s = (month() <=9) ? str(0)+str(month()) : str(month()); String yesr_s = str(year()); text(day_s + ":" + month_s +":"+ yesr_s, x , y); textFont(font_meta20); fill(255,80); String hour_s = (hour() <=9 ) ? str(0)+str(hour()) : str(hour()); String minute_s = (minute() <=9 ) ? str(0)+str(minute()) : str(minute()); String second_s = (second() <=9 ) ? str(0)+str(second()) : str(second()); float lengthOfdate = textAscent() + textDescent(); text(hour_s + ":" + minute_s +":"+ second_s, x , y+18); }//watch end //participant void participant(float x, float y){ if(count>0){ float leading = 5.f; // participant fill(255,80); textFont(font_meta11); String parts = "The latest Participant "; float mniw = textWidth(parts); float lengthOfdate2 = textAscent() + textDescent(); text(parts, x , y); fill(255,120); textFont(font_meta24); String pname = nameArray[count-1]; float nw = textWidth(pname); float locFirst = y+lengthOfdate2+leading+6; text(pname, x , locFirst); } }//end of patticipant void explain(float x, float y){ //explian float leading = 5.f; fill(250, 115, 8); textFont(font_meta18); float lengthOfdate3 = textAscent() + textDescent(); String numMember = str(count)+" people have participated in this experimemt to contibute to plant a flower."; float numMemberWith = textWidth(numMember); float locSecond = leading*2; text( numMember, x , y+locSecond ); //fill(250, 115, 8, 150); fill(180); textFont(font_meta12); String[] explain = loadStrings("explain.txt"); text(explain[0], int(x) , y+locSecond+leading*2 , numMemberWith + 100,100); } //////////////////////////////////////////////////////////////////////// void keyPressed() { // listener for textfiel if( keyCode == DELETE || keyCode == BACKSPACE ){ uset.u_info.input_name.delete(); uset.u_info.input_comment.delete(); } else{ uset.u_info.input_name.write(); uset.u_info.input_comment.write(); } if(keyCode == ESC){ exit(); // Stop the program } } ///////////////