volume bar please help
in
Programming Questions
•
2 years ago
Hello guys,
I am VERY fresh with processing so please be gentle.
I am having a great trouble with this task.
I need to do a volume bar - black rect and inside 8 green, 8 yellow and 8 red bars. Bars are drawn when keyPressed.
The problem is with background. In my project background must be in draw().
I've tried many versions but can't resolve it :(
This is what I want to do, but with bg in draw()
//line position on x axis
int x = 237;
//line position on y axis
int y = 445;
//lenght of line
int len = 12;
//spacing between each line
int spacing = 6;
//value on x axis where green lines end, after that display yellow
int endGreen = 285;
//value on x axis where yellow lines end, after that display red
int endYellow = 333;
//value on x axis where red lines end
int endRed = 381;
void setup() {
size(600,500);
background(255);
frameRate(15);
}
void draw() {
//draw big rectangle
noFill();
stroke(0);
strokeWeight(6);
rect(230,440,152,22);
//draw line
strokeWeight(4);
strokeCap(SQUARE);
//if key pressed, display green lines one at a time
if (keyPressed == true) {
//display green lines for 8 lines
if (x < endGreen) {
//draw line
stroke(0,200,0);
line(x,y,x,y+len);
//increment by 6
x += spacing;
//change color to yellow at x,y position
} else if (x < endYellow) {
stroke(255,255,0);
line(x,y,x,y+len);
x += spacing;
//change color to red at x,y position
} else if (x < endRed) {
stroke(255,0,0);
line(x,y,x,y+len);
x += spacing;
}
}
}
I'll be greatful for your help.
I am VERY fresh with processing so please be gentle.
I am having a great trouble with this task.
I need to do a volume bar - black rect and inside 8 green, 8 yellow and 8 red bars. Bars are drawn when keyPressed.
The problem is with background. In my project background must be in draw().
I've tried many versions but can't resolve it :(
This is what I want to do, but with bg in draw()
//line position on x axis
int x = 237;
//line position on y axis
int y = 445;
//lenght of line
int len = 12;
//spacing between each line
int spacing = 6;
//value on x axis where green lines end, after that display yellow
int endGreen = 285;
//value on x axis where yellow lines end, after that display red
int endYellow = 333;
//value on x axis where red lines end
int endRed = 381;
void setup() {
size(600,500);
background(255);
frameRate(15);
}
void draw() {
//draw big rectangle
noFill();
stroke(0);
strokeWeight(6);
rect(230,440,152,22);
//draw line
strokeWeight(4);
strokeCap(SQUARE);
//if key pressed, display green lines one at a time
if (keyPressed == true) {
//display green lines for 8 lines
if (x < endGreen) {
//draw line
stroke(0,200,0);
line(x,y,x,y+len);
//increment by 6
x += spacing;
//change color to yellow at x,y position
} else if (x < endYellow) {
stroke(255,255,0);
line(x,y,x,y+len);
x += spacing;
//change color to red at x,y position
} else if (x < endRed) {
stroke(255,0,0);
line(x,y,x,y+len);
x += spacing;
}
}
}
I'll be greatful for your help.
1
