class Clock{ String Cs; String localTime = ""; String dayNight; String cityName; int h,m; int clockX; int clockZ; float light; float rZ=PI*2*h/12; Clock(String _Cs){ Cs=_Cs; } void getTime() { //Get all the HTML/XML source code into an array of strings (each line is one element in the array) String[] lines = loadStrings(Cs); String xml = join(lines, " "); // Get rid of the array and make it one very long String // The manual way to concatenate // String xml = ""; // for (int i = 0; i < lines.length; i++) { // xml += lines[i]; // } // Searching for weather condition String lookfor = "\"ct\""; String end = "Show clock"; localTime = giveMe(xml,lookfor,end); lookfor = "big\">"; end = "/strong"; localTime = giveMe(localTime,lookfor,end); println(localTime); } void getHour() { String lookfor = "at "; String end = ":"; h = int(giveMe(localTime,lookfor,end)); println(h); } void getMin() { String lookfor = ":"; String end = ":"; m = int(giveMe(localTime,lookfor,end)); println(m); } void getAMPM() { String lookfor = "at "; String end = "<"; dayNight = giveMe(localTime,lookfor,end); lookfor = " "; end = "M"; dayNight = giveMe(dayNight,lookfor,end); println(dayNight); } String giveMe(String s, String before, String after) { String found = ""; int start = s.indexOf(before); // Find the index of the beginning tag if (start == -1) return ""; // If we don't find anything, send back a blank String start += before.length(); // Move to the end of the beginning tag int end = s.indexOf(after,start); // Find the index of the end tag if (end == -1) return ""; // If we don't find the end tag, send back a blank String return s.substring(start,end); // Return the text in between } void drawClock(){ //// define the variables in pushMatrix //// if(Cs.equals(cities[0])){ cityName=" Taipei"; clockX = mouseX; clockZ = (height/2-mouseY)/2; } if(Cs.equals(cities[1])){ cityName="New York"; clockX = width-mouseX; clockZ = (-height/2+mouseY)/2; } ///// draw the hour hand //// pushMatrix(); translate(clockX,height/2,clockZ); rotateX(PI/4); stroke(200,0,0); rotateZ(PI*2*h/12); line(0,-10,0,0); popMatrix(); ///// draw the minute hand //// pushMatrix(); translate(clockX,height/2,clockZ); rotateX(PI/4); rotateZ(PI*2*m/60); line(0,-18,0,0); popMatrix(); //// draw the clock //// pushMatrix(); translate(clockX,height/2,clockZ); rotateX(PI/4); rZ+=(PI*2)/15; rotateZ(rZ); noFill(); //// according to the h in AM or PM to decide the light //// if(dayNight.equals("A")){ if(h==12){light=50;} else light=h*150/12+50;} if(dayNight.equals("P")){ if(h==12){light=200;} else light=(12-h)*150/12+50;} stroke(light); line(0,-25,0,-20); ellipse(0,0,50,50); textMode(SCREEN); textFont(f, 10); text(cityName,clockX-28,height/2+35); if(m<10){ text(h+":"+"0"+m+dayNight+"M",clockX-25,height/2+45);} if(m>10){text(h+":"+m+dayNight+"M",clockX-25,height/2+45);} popMatrix(); } }