Update Fill color in Shape
in
Programming Questions
•
11 months ago
Hello,
My code currently updates the colors of shapes (rm) if the current hour and minute matches a field in the txt file. My problem is that I need the shapes to stay that assigned color until it is overwritten by a new matching field in the txt file.
Also, I only need to check if the fields match at hh:00 or hh:30, so I feel like draw() should only be called when the current time is either of those times. But then the clock doesn't run continuously...
Let me know if this isn't clear!! Thank you!!
*********************************
Record[] records; int recordCount; int m = minute(); int h = hour(); PFont font; PShape eighthfl; PShape rm; String[] Active = { "801","802","803","804","806","8CS","terrace"}; String[] NotActive = { "rm1","rm2","rm3","rm9","rm10","rm11","rm12","rm14","rm15","rm17","rm18","rm19","rm20","rm21","rm22","rm23","rm24","rm25"}; int stayColor = color(0, 0, 0); void setup() { size(830, 440); font = loadFont("Futura-Medium-20.vlw"); textFont(font); // file of the 8th floor eighthfl = loadShape("CUS.svg"); smooth(); // Improves the drawing quality of the SVG String lines[] = loadStrings("days.txt"); records = new Record[lines.length]; for (int k = 0 ; k < lines.length; k++){ String[] pieces = split(lines[k], '\t'); if (pieces.length == 5) { records[recordCount] = new Record(pieces); recordCount++; } } println("there are " + recordCount + " records to filter thru"); print("the time is " + nf(h,2)); println(nf(m,2)); for (int k = 0; k < recordCount; k++){ println("it is " + records[k].taken + " that " + records[k].room + " is taken at " + nf(records[k].hourslot,2) + ":" + nf(records[k].minuteslot,2) + " on " + records[k].weekday); int m = minute(); int h = hour(); //roomColorStay(records[k].room, stayColor); } } class Record { String room; String weekday; int hourslot; int minuteslot; boolean taken; Record(String[] pieces) { room = pieces[0]; weekday = pieces[1]; hourslot = int(pieces[2]); minuteslot = int(pieces[3]); taken = boolean(pieces[4]); } } void draw() { background(0); // Draw the full map shape(eighthfl, 0, 0); int s = second(); int m = minute(); int h = hour(); String t = nf(h,2) + ":" + nf(m,2) + ":" + nf(s,2); text(t, 155, 420); //if (m == 05){ for (int k = 0; k < recordCount; k++){ if (records[k].hourslot == h && records[k].minuteslot == m){ println(records[k].taken + " says true or false"); String lightMe = records[k].room; boolean amITaken = records[k].taken; if (amITaken == false) { text("it is available", 255, 420); println(lightMe); stayColor = color(42, 183, 126); roomColorChange(lightMe, stayColor); } else if (amITaken == true) { text("it is occupied", 255, 420); println(lightMe); stayColor = color(165, 15, 54); roomColorChange(lightMe, stayColor); } } else { //String keepMeLit = records[k].room; println("all stay same color" + stayColor); //roomColorChange(keepMeLit, stayColor); } } } //} void roomColorChange(String goOn, int c){ PShape rm = eighthfl.getChild(goOn); rm.disableStyle(); fill(c); noStroke(); shape(rm, 0, 0); } //void checkColors() { // if(m == 28) { // redraw(); // } //} //void roomColorStay(String stayOn, int d){ // PShape rm = eighthfl.getChild(stayOn); // rm.disableStyle(); // fill(d); // noStroke(); // shape(rm, 0, 0); // } ********************************days.txt**BELOW**************
rm12 M 10 05 true rm11 M 12 05 false rm10 M 13 05 true rm9 M 15 05 false rm8 M 18 05 true rm7 M 21 05 false rm6 T 09 05 true rm5 T 12 05 false rm4 T 14 05 true rm3 T 16 05 false rm1 T 21 08 true rm2 T 21 11 false rm1 M 10 05 true rm2 M 10 30 true rm3 M 11 05 true rm4 M 11 30 true rm5 M 12 05 true rm6 M 13 05 true rm7 M 13 30 true rm8 M 14 05 true rm9 M 14 30 true rm10 M 15 05 true rm11 M 18 05 true rm12 M 18 30 true rm13 M 19 05 true rm14 M 19 30 true rm15 M 20 05 true rm16 M 20 30 true rm17 M 21 05 true rm18 T 11 05 true rm19 T 11 30 true rm20 T 12 05 true rm21 T 12 30 true rm22 T 13 05 true rm23 T 13 30 true rm24 T 21 22 true rm25 T 21 21 true rm1 T 21 21 true
1