void drawGrid() { stroke(160); strokeWeight(1); for(int i = 0; i < width; i = i + unitX) { line(i,0,i,height); for(int k = 0; k < height; k = k + unitY) { line(0,k,width,k); } } } void drawPlot() { int value1 = floor(map(RainNumber, 0, 100, 60, 10)); noStroke(); fill(value1); rectMode(CORNERS); rect(plotX1,plotY1,plotX2,plotY2); // int value1 = floor(map(RainNumber, 0, 100, 60, 10)); // int value2 = 20; // color b1 = color(value1, value1, value1); // color b2 = color(0, 0, 0); // setGradient(plotX1,plotY1,plotX2-plotX1,plotY2-plotY1, b1, b2, Y_AXIS); } void drawTitle() { fill(255); textAlign(LEFT); textFont(font2); text("The effect of rainfall on the volume of travel books borrowed from the Seattle Public Library in 2009", plotX1, plotY1 - unitY); // textAlign(RIGHT); // text("BAJ", plotX2, plotY1 - unitY); } void drawAxisLabels() { fill(120); textLeading(15); textFont(font0); textAlign(CENTER, CENTER); // Use \n (enter/linefeed) to break the text into separate lines //text("CATEGORY",(plotX1+plotX2)/2, labelY); textAlign(CENTER, CENTER); rotate(radians(270)); text("Average number of books checked out per day", -(plotY1+plotY2)/2, labelX); //-(plotY1+plotY2)/2 rotate(-radians(270)); rotate(radians(90)); text("Increasing rainfall (inches)", (plotY1+plotY2)/2, -(width -labelX+3*(unitX)/2)); //-(plotY1+plotY2)/2 rotate(-radians(90)); } void drawXLabels() { fill(70); textAlign(CENTER, TOP); // Use thin, gray lines to draw the grid stroke(255,120); strokeWeight(1); for (int row = 0; row <= XMAX; row++) { if (row % unitX == 0) { float x = map(row, XMIN, XMAX, plotX1, plotX2); textFont(font0); textAlign(CENTER, TOP); // Center vertically fill(70); text(row, x, plotY2 + 10); line(x, plotY1, x, plotY2+5); } } } void drawYLabels() { fill(120); textFont(font0); stroke(128); strokeWeight(1); for (float v = dataMin; v <= dataMax; v += unitY) { if (v % unitY == 0) { // If a tick mark float y = map(v, dataMin, dataMax, plotY2, plotY1); if (v % unitY == 0) { // If a major tick mark textAlign(RIGHT, CENTER); // Center vertically text(floor(v), plotX1 - 7, y); line(plotX1 - 4, y, plotX1, y); // Draw major tick } else { line(plotX1 - 2, y, plotX1, y); // Draw minor tick } } } } void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ){ // calculate differences between color components float deltaR = red(c2)-red(c1); float deltaG = green(c2)-green(c1); float deltaB = blue(c2)-blue(c1); // choose axis if(axis == Y_AXIS){ /*nested for loops set pixels in a basic table structure */ // column for (int i=x; i<=(x+w); i++){ // row for (int j = y; j<=(y+h); j++){ color c = color( (red(c1)+(j-y)*(deltaR/h)), (green(c1)+(j-y)*(deltaG/h)), (blue(c1)+(j-y)*(deltaB/h)) ); set(i, j, c); } } } else if(axis == X_AXIS){ // column for (int i=y; i<=(y+h); i++){ // row for (int j = x; j<=(x+w); j++){ color c = color( (red(c1)+(j-x)*(deltaR/h)), (green(c1)+(j-x)*(deltaG/h)), (blue(c1)+(j-x)*(deltaB/h)) ); set(j, i, c); } } } } void drawArrow(){ int x_end = plotX2+3*unitX; int x_st = plotX2+3*unitX; int y_st = plotY1-2 + int(map(RainNumber,0,100,plotY2-plotY1, 0)); int y_end = plotY2;// float ar_wid = int(map(RainNumber, 0,100,0,20)); fill(255); stroke(255); strokeWeight(map(RainNumber, 0, 100, 0,3)); line(x_st, y_st, x_end, y_end); line(x_st,y_st, x_end+ar_wid/2-1,y_st+ar_wid); line(x_st,y_st, x_end-ar_wid/2+1,y_st+ar_wid); }