Hi,
I have a function whose purpose(for now) is to:
1) display Album Art for background (disabled for debugging, for now)
2) Grow a bar up to a certain point, based on the length of the title.
3) "rubberband" back and forth just slightly before stabilizing at the title length.
Currently, the bar appears but does not grow past 4 pixels. It seems draw() keeps looping as it should, but executes the function only once? Here is the code:
Code:
String title = "Micawber's Moan"; //Initial Strings. This string is measured for bar length.
String artist = "Random"; //Ignore/unused for now.
String album = "Bad Joke EP"; //Ignore, unused for now.
boolean onOff = false; //rubberBand needs this, it's the first parameter.
PImage arts; //background
PFont a; //font of choice
int h = 20; //used for bar height.
float stringSize = 0; //used to measure how lengthy bar should be.
float rubber = 0.0; //used for "angle"
int down = 50; //used for "d"
int starter = 0; //used for "i" growth
void setup() {
arts = loadImage("bad joke ep.jpg");
size(arts.width,arts.height);
background(50); // gray background
a = loadFont("Futura-MediumItalic-12.vlw");
textFont(a); //this HAS to be used here or compiler error.
stringSize = textWidth(title); // finds the length of the String (Micawber's Moan) in pixels.
}
void draw() {
frameRate(60);
int ypos = arts.height - 80;
//y-pos scales to the size of the album art.
rubberBand(onOff, arts, starter, ypos, stringSize, h, rubber, down);
//We've sent the boolean state, the background image,
//the y-position that will be close to the bottom, and "i"
//the float length of the string for the bar,
//and h, the height of bar.
// "rubber" and "down" are special use stuff.
}
void mouseClicked() {
onOff = true; // if mouse gets clicked, the function operates.
}
void rubberBand (boolean clicked, PImage bg, int i, int tempY, float xLimit, int tempH, float angle, int d) {
//function recieves a bool, an Image for background, a Ypos for location,
//a float for width of bar(xLimit) , and a height of bar.
//angle and 'd' are for special purpose.
//maybe the ENTIRE FUNCTION runs only once? Irrelevent. We've narrowed it down, apparently functions within draw happen only once.
// Right
//problems with the portion below.
if(clicked == true && i < xLimit){
//Initial state, grows up to the width of the String.
background(10,100,10); //this appears as a medium Green status---never gets past here.
//refresh background.
fill(200); // Full Opacity for now.
rect(10, tempY, i * 6, tempH);
//a rectangle starting at left side, grows at the rate of i.
i += 4;// 4 because otherwise the damn thing grows way too slow---this only occurs once, should occur more.
angle = 0.0; // resets it for next time
d =50;//here too
println(i);
}
else if (i >= 50 && i< (xLimit+50))//once the box has grown to its full height the rubberband effect comes in
{
background(50,50,10); //this is a "yellow light" status--I have yet to see this status.
fill(200);
rect(10, tempY,sin(angle)*d + 300 , tempH);
i += 2;
angle += 0.4;
d--;
clicked = false;
}
else if( i >= xLimit && i < (xLimit + 100))
{
background(10,10,100);
fill(200, 50);
rect(1, tempY, 300 , tempH);
i++;
}
else
{
background(100,10,10);
i = 0;
}
}
Any thoughts? The rubberBand function is in a seperate tab, btw.