import noc.*; import processing.opengl.*; //import javax.media.opengl.*; import proxml.*; /*static public void main(String args[]) { PApplet.main(new String[] { "--present", "drawingWithNode_savedata" }); }*/ // save data to xml XMLElement users; XMLInOut xmlInOut; PFont font_meta11, font_meta24, font_meta14, font_meta12, font_meta10, font_meta48,font_meta20, font_helv_20, font_helv_11; //font_helv_14; //font_helv_75; float t; // basic information int sw=900;//screen.width; int sh=700;//screen.height; // counting for add object int count=0; int userCount; // variable for detecting collision int over; int sameid; int[] sidArray; float targeup; RythumBar[] rBar; UIset uset; float eW,eH; //topEmotion int styleOfvisual = 5;// grobal style of visual in class_node float mx; //timecheck float timeCheck; boolean startHide; float udx; // X cordination of userDetail float udy; // y cordination of userDetail float uvx; // udate X cordination of userDetail float uvy; // udate y cordination of userDetail float uthelta; // angle of userDetail int overId; 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[] askFeelArray, distanceArray, darkArray, softArray; int[] rv,gv,bv; // start button Button2 start_b; String url = "http://www.experiencecode.com/prox/spaceIssue.xml"; void setup(){ size(900,700,OPENGL); hint(ENABLE_OPENGL_2X_SMOOTH); frameRate=30; noStroke(); smooth(); //demo xml check---------------------------------- 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 xmlEvent(new XMLElement(url)); } // xml end---------------------------------------- /* //xml check---------------------------------- xmlInOut = new XMLInOut(this); try{ xmlInOut.loadElement("spaceIssue.xml"); } catch(Exception e){ //if the xml file could not be loaded it has to be created xmlEvent(new XMLElement("spaceIssue")); } // 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_meta12 = loadFont("Meta-Normal-12.vlw"); font_meta20 = loadFont("Meta-Normal-20.vlw"); font_meta48 = loadFont("Meta-Normal-48.vlw"); font_helv_11 = loadFont("Helvetica-Normal-11.vlw"); font_helv_20 = loadFont("Helvetica-Normal-20.vlw"); // array for same IDs of the node sidArray = new int[0]; // item_ GUI and nodeF count = users.countChildren(); rBar = new RythumBar[count]; uset = new UIset((sw-710)/2,120); // 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]; askFeelArray = new float[userCount]; distanceArray = new float[userCount]; darkArray = new float[userCount]; softArray = new float[userCount]; rv = new int[userCount]; gv = new int[userCount]; bv = new int[userCount]; //topEmotion // start button start_b = new Button2("Start making the dot ", 60, sh-90, 150, 20,10, 1,1,font_meta24 ); //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 askFeelArray = splice(askFeelArray, evaluation.getFloatAttribute("askFeelArray"),i); distanceArray = splice(distanceArray, evaluation.getFloatAttribute("distanceArray"),i); darkArray = splice(darkArray, evaluation.getFloatAttribute("darkArray"),i); softArray = splice(softArray, evaluation.getFloatAttribute("softArray"),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); rBar[i] = new RythumBar(random(50,sw-50), random(50 , sh-50), distanceArray[i], distanceArray[i], i, rBar);//location+ } } void xmlEvent(XMLElement element){ users = element; users.printElementTree(" "); XMLElement name; XMLElement gender; XMLElement age; } void draw(){ //background(80); bg_display(); grid_display(); hideMouse(); //start button //start_b.r = color(162, 162, 162, 60); start_b.display(); if(start_b.on == 1){ startGui = true; othersOver = true; //println(startGui); } if(!startGui ){ for(int i = 0; i< count; i++){ rBar[i].run(); } } // accessories watch(60, 50); participant(60, sh-200); // gui if(startGui){ uset.display(); } // show user deatail userDetail(); } ///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// void mouseReleased(){ // save event if( uset.save_b.on == 1 && uset.isUncheck==false){ //println( uset.save_b.on); // add node uset.addArray(); addNode(count); startGui = false; count ++; othersOver = false; //println(startGui); uset.save_b.on =0; //save xml part XMLElement user_info = new XMLElement("user_info"); users.addChild(user_info); // user demographic XMLElement user_demographic = new XMLElement("user_demographic"); user_demographic.addAttribute("user_no", count-1); user_demographic.addAttribute("name",nameArray[count-1]); user_demographic.addAttribute("gender",genderArray[count-1]); user_demographic.addAttribute("age",ageArray[count-1]); user_info.addChild(user_demographic); // user emotion XMLElement emotion = new XMLElement("emotion"); emotion.addAttribute("selectedemotion",emotionArray[count-1]); emotion.addAttribute("redV",rv[count-1]); emotion.addAttribute("greenV",gv[count-1]); emotion.addAttribute("blueV",bv[count-1]); user_info.addChild(emotion); // question 00 XMLElement evaluation = new XMLElement("evaluation"); evaluation.addAttribute("askFeelArray",askFeelArray[count-1]); evaluation.addAttribute("distanceArray",distanceArray[count-1]); evaluation.addAttribute("darkArray",darkArray[count-1]); evaluation.addAttribute("softArray",softArray[count-1]); evaluation.addAttribute("location",locationArray[count-1]); evaluation.addAttribute("comment",commentArray[count-1]); user_info.addChild(evaluation); //demo version xmlInOut.loadElement(url); //save data into xml file //xmlInOut.saveElement(users,"spaceIssue.xml"); redraw(); } if(uset.cancel_b.on == 1 || uset.save_b.on == 1 && uset.isUncheck==false){ startGui = false; othersOver = false; sidArray = subset(sidArray, 0,0); } } ////////////////////////////////////////////////////////////////////////////// // the function to expand object array void addNode(int x){ rBar = (RythumBar[]) expand(rBar,x+1); rBar[x] = new RythumBar(random(50,sw-50), random(50 , sh-50), distanceArray[x], distanceArray[x], x, rBar);//location+ // make sidArray be empty uset.reset(); //sidArray = subset(sidArray, 0,0); } //////////////////////////////////////////////////////////////////////////// void hideMouse(){ if(mouseX-pmouseX == 0){ timeCheck += 0.1; if(timeCheck > 30){ startHide = true; timeCheck = 31; mouseX = sw; mouseY = sh; noCursor(); } } else if(mouseX-pmouseX !=0){ timeCheck =0; startHide = false; cursor(ARROW); } } ///----------------------------------------------- //grid_display void grid_display(){ float[][] distances; float maxDistance; maxDistance = dist(sh/2,sw/2, sh, sw); int gLine_Num = 32; int gRow_Num = 24; int pointArr = gLine_Num*gRow_Num; float gap = 0; float sellwidth = (sw-((gLine_Num-1)*gap))/gLine_Num; float sellheight = (sh-((gRow_Num-1)*gap))/gRow_Num; distances = new float[gRow_Num+1][gLine_Num+1 ]; eW = sellwidth; eH = sellheight; for(int i=0; i< gLine_Num+1 ; i++){ for(int j=0; j< gRow_Num+1 ; j++){ float dista = dist(sh/2, sw/2, (sellheight+gap)*j, (sellwidth+gap)*i); distances[j][i] = 255-(dista/maxDistance*255); noStroke(); fill( distances[j][i],30); rect((sellwidth+gap)*i-2, (sellheight+gap)*j, 5, 1); rect((sellwidth+gap)*i, (sellheight+gap)*j-2, 1, 5); } } }//end of grid_display ////-------------------------------------------------------- //bg_display() void bg_display(){ beginShape(QUAD_STRIP); fill(30); vertex(0,0); vertex(sw,0); fill(40); vertex(0,sh); vertex(sw,sh); endShape(); }//end of bg_display //--------------------------------------------------------------- // //// userDetail void userDetail(){ for(int i=0; i rBar[i].rh+td*3) { uthelta = TWO_PI-PI/4; uvx = 0; uvy = 0; }else if(rBar[i].loc.x > sw/2 && rBar[i].loc.y > rBar[i].rh+td*3){ uthelta = PI+PI/4; uvx = dw+20; uvy = 0; }else if ( rBar[i].loc.x < sw/2 && rBar[i].loc.y < rBar[i].rh+td*3 ){ uthelta = PI/4; uvx = 0; uvy = -td*3; } else if ( rBar[i].loc.x > sw/2 && rBar[i].loc.y < rBar[i].rh+td*3 ){ uthelta = PI/2+PI/4; uvx = em+10; uvy = -td*3; } udx = rBar[i].loc.x + ((100-distanceArray[i]/2)/2)*cos(uthelta); udy = rBar[i].loc.y + ((100-distanceArray[i]/2)/2)*sin(uthelta); fill(255); rect(int(udx-uvx), int(udy-td-uvy), dw+20, td); rect(int(udx-uvx), int(udy-td*2-1-uvy), com+20, td); rect(int(udx-uvx), int(udy-td*3-2-uvy), em+20, td); fill(60); text(demogra, int(udx+5-uvx), int(udy-4-uvy)); text(comm, int(udx+5-uvx), int(udy-4-td-1-uvy)); text(emo, int(udx+5-uvx), int(udy-4-td*2-2-uvy)); stroke(255); line(rBar[i].loc.x, rBar[i].loc.y, udx, udy); noStroke(); } } }// end ofuserDetail //watch void watch(float x, float y){ fill(120); textFont(font_helv_11); 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_helv_20); fill(250, 115, 8); 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+lengthOfdate); }//watch end //participant void participant(float x, float y){ if(count>0){ float leading = 5.f; // participant fill(120); textFont(font_meta11); String parts = "The latest Participant "; float mniw = textWidth(parts); float lengthOfdate2 = textAscent() + textDescent(); text(parts, x , y); fill(250, 115, 8); textFont(font_meta20); String pname = nameArray[count-1]; float nw = textWidth(pname); float locFirst = y+lengthOfdate2+leading+3; text(pname, x , locFirst); //explian fill(250, 115, 8); textFont(font_meta20); float lengthOfdate3 = textAscent() + textDescent(); String numMember = str(count)+" people have participated in this experiment to create the visual sketch."; float numMemberWith = textWidth(numMember); float locSecond = locFirst+lengthOfdate3 + leading*2; text( numMember, x , locSecond ); //fill(250, 115, 8, 150); fill(180); textFont(font_meta12); textLeading(13); String[] explain = loadStrings("explain.txt"); text(explain[0], int(x) , locSecond + lengthOfdate2, numMemberWith + 100,100); } }//end of patticipant //////////////////////////////////////////////////////////////////////// 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 } } /* void keyTyped() { uset.testf.write(); }*/ ///////////////