Hi, im pretty new to programming and was set a piece of work on my course. I need to draw a bar chart of figures in processing, then display the value of each bar. however if the value = 0 then i dont want the text to show.
Heres my code so far, i know its really basic, but im really shit at programming
{ size(200, 600); //setup for the canvas and the background background(265,265,0);
int step = 20; // assigns the "step" int a = number[0]; // assigns each value in the array to a variable a - j int b = number[1]; int c = number[2]; int d = number[3]; int e = number[4]; int f = number[5]; int g = number[6]; int h = number[7]; int i = number[8]; int j = number[9]; draw(); // draws the rectangles bellow { fill(265,100,0); // sets the colour to orange rect(0, 0, 20, a*step); rect(20, 0, 20, b*step); rect(40, 0, 20, c*step); fill(0,265,80); // sets the colour to green rect(60, 0, 20, d*step); fill(265,0,0); // and now to red rect(80, 0, 20, e*step); fill(256,100,0); // back to orange rect(100, 0, 20, f*step); rect(120, 0, 20, g*step); rect(140, 0, 20, h*step); rect(160, 0, 20, i*step); fill(265,0,0); // back to red rect(180, 0, 20, j*step); } { PFont font; font = loadFont("Serif-12.vlw"); //loads font textFont(font); textAlign(CENTER); fill(0); text(a, 10, 11);//writes out the values along the base of the bars text(b, 30, 11); text(c, 50, 11); text(d, 70, 11); text(e, 90, 11); text(f, 110, 11); text(g, 130, 11); text(h, 150, 11); text(i, 170, 11); text(j, 190, 11); }
I dont know whats the best way to do it. I tried to put an if statement at the top of the text functions, saying if the variables = 0 i.e. a=0 then the fill on teh text is the same as the background, so therefore invisible, but it just filled all the text yellow.
any help would be fantastic!
thanks, George.