Hi all, I've been wrestling with my sketch for days trying to get it to do what I want, but no joy, hopefully someone can spare a little time to help (& highlight my novice mistakes)!
Currently my sketch checks a webpage for a number twice each minute and adds it to an array.
Next it draws 60 cubes in a line, each cube sits at a height depending on the corresponding number in the array (if the webpage number at minute 38 was 2, array[38] = 2 etc).
This all works fine, but I want to add a bit more complexity to it by making the blocks drawn for 'hour 2' not over the top of the last but a block's width behind, so over 3 hours i'd have 3rows of blocks in a 'wall'.
I'd really appreciate anyone helping me achieve this, or helping me tidy up my code, I've been learning Processing (as my first programming language) in isolation, and it seems as soon as I start getting somewhere it suddenly becomes incomprehensible! :-[
Many thanks, L.
(I have only used simple code, except the regex bit - returns an int. I will explain anything i have neglected to mention if this doesnt make sense! thanks again).
Code:PFont font;
String workCountStringh;
int workCountStringInt1h;
int workCountStringInt2h;
int workCountInth;
int ch = 255;
int lastHourHitsh;
int thisMinuteHitsh;
int endHourHitCounth;
int[] hitsThisMinuteh = new int[60];
int[] rateArrayh = new int[60];
float xh;
float yh;
float z = 1;
int backSpace;
int a;
int b;
int startHourHitCounth = 110561;
void setup() {
size(3500, 2000, P3D);
font = createFont("ArialMT", 15);
textFont(font);
background(0);
text("a, w, s, d, r, f, p", 10, 10);
String urlh = "http://cagd.leedsmet.ac.uk/";
if(urlh != null){
String[] htmlTexth = loadStrings(urlh);
String htmlTextJoinedh = join(htmlTexth, " ");
int starth = htmlTextJoinedh.indexOf("relative; top: 8px\">"); //where in html string to start.
int endh = htmlTextJoinedh.indexOf("</p>", starth); //where in html string to end.
String selectedTexth = htmlTextJoinedh.substring(starth, endh); //make new string of my selection from all html text.
String pageh = htmlTextJoinedh;
String regexh = "id=\"total_count\".*?>([\\d,]+)</p>";
String valueh = null;
Matcher m1 = Pattern.compile(regexh).matcher(pageh);
if (m1.find()){
valueh = m1.group(1);
}
workCountStringInt1h = int(valueh.substring(0,3));
workCountStringInt2h = int(valueh.substring(4,7));
workCountInth = ((workCountStringInt1h*1000)+(workCountStringInt2h));
for(int i = 0; i < hitsThisMinuteh.length; i++){ //initialise my arrays to zero's.
hitsThisMinuteh[i] = 0;
}
}
}
void draw() {
smooth();
lights();
hourtest();
if(second() == 05){
save("shotauto"+hour()+":"+minute()+":"+second()+".jpg"); //this makes it stop working!
}
}//end of draw.
void hourtest(){
if((second() == 1) || (second() == 51)){
String urlh = "http://cagd.leedsmet.ac.uk/";
if(urlh != null){
String[] htmlTexth = loadStrings(urlh);
String htmlTextJoinedh = join(htmlTexth, " ");
int starth = htmlTextJoinedh.indexOf("relative; top: 8px\">"); //where in html string to start.
int endh = htmlTextJoinedh.indexOf("</p>", starth); //where in html string to end.
String selectedTexth = htmlTextJoinedh.substring(starth, endh); //make new string of my selection from all html text.
String pageh = htmlTextJoinedh;
String regexh = "id=\"total_count\".*?>([\\d,]+)</p>";
String valueh = null;
Matcher m1 = Pattern.compile(regexh).matcher(pageh);
if (m1.find()){
valueh = m1.group(1);
}
workCountStringInt1h = int(valueh.substring(0,3));
workCountStringInt2h = int(valueh.substring(4,7));
workCountInth = ((workCountStringInt1h*1000)+(workCountStringInt2h));
}
}
if((second() == 01)){//finds work count at start of each minute.
startHourHitCounth = workCountInth;
println(startHourHitCounth+"startminutecount");
if(minute()>0){
String[] rateArrayStringsArrayh = loadStrings("rateArrayMinutes"+(minute()-1)+".txt");//should mean it can run over an hour break.
String joinedRateArrayh = join(rateArrayStringsArrayh, ",");
rateArrayh = int(split(joinedRateArrayh, ","));
}
else if(minute() == 0){
String[] rateArrayStringsArrayh = loadStrings("rateArrayMinutes59"+".txt");
String joinedRateArrayh = join(rateArrayStringsArrayh, ",");
rateArrayh = int(split(joinedRateArrayh, ","));
}
b = a+1;
if(a<b){//makes it draw only once each refresh?
background(0);
for(int i=0; i<rateArrayh.length-1; i++){// need to stop this from repeating.
noFill();
rotateX(xh);
rotateY(yh);//row controls.
pushMatrix();
for(int n=0;n<rateArrayh.length;n++){
pushMatrix();
translate(50, height-200, 100);
translate((width/2 + (( (n-1)-30)*50)), -(rateArrayh[n]*50), -a);
fill(255,255, 3*(a/50));
box(50, 50, 50);
text(n+1, 0, 25);
popMatrix();
}
popMatrix();
}
println("drawn");
}
}
if((second() == 56)){//finds work count at end of each minute. MAKE CORRECT WHEN DONE!
endHourHitCounth = workCountInth;
println(endHourHitCounth+"endminutecount");
thisMinuteHitsh = endHourHitCounth-startHourHitCounth; //FINDS NUMBER OF HITS THIS minute. - ADDS TO 'LAST minute' ARRAY ETC 60 LONG.
hitsThisMinuteh[minute()] = thisMinuteHitsh;
println(thisMinuteHitsh +"thisminuteHitcount");
println(hitsThisMinuteh);
String hitsThisMinuteJoinedh = join(nf(hitsThisMinuteh, 0), ",");
String[] hitsThisMinuteJoinedListh = split(hitsThisMinuteJoinedh, ",");//EXPORTS RATE ARRAY.
saveStrings("rateArrayMinutes"+minute()+".txt", hitsThisMinuteJoinedListh);//how to draw these each time!?
}
}