Need help with a gradual lerpColor fading function.
in
Programming Questions
•
2 years ago
Hey guys, first year student currently struggling my way through one of my early assignments and have hit a serious stumbling block.
I know it mustn't be that hard, but I have spent hours trying to solve how to get my ball to hit the wall of its respective color change to that color then have it gradually fade back to the neutral color two diameters away from the wall.
Any help would be much appreciated, I've tried so many methods and none have worked correctly. So I give you my code, the clean slate, and would very much welcome all and any help.
Thankyou.
float xPos, yPos, xSpeed, ySpeed, posMorpher;
float top, right, left, bottom;
float radius;
float yBumperWidth, yBumperHeight, xBumperWidth, xBumperHeight;
float fMorpher, sMorpher;
color rC, lC, bC, tC, nC;
int balls = 20;
int rCounter = 00;
int lCounter = 00;
int tCounter = 00;
int bCounter = 00;
void setup()
{
size(800,600);
smooth();
noStroke();
xPos = width/2;
yPos = height/2;
xSpeed = 5.0f;
ySpeed = 5.0f;
frameRate(40);
}
void draw()
{
background(0);
top = 0;
bottom = height;
left = 0;
right = width;
radius = (width + height)/25;
yBumperWidth = (width + height)/40;
yBumperHeight = (width + height)/15;
xBumperWidth = (width + height)/15;
xBumperHeight = (width + height)/40;
rC = color(242, 68, 68);
lC = color(35,65,240);
bC = color(90,0,180);
tC = color(35,255,18);
nC = color(250,250,250);
xPos += xSpeed;
yPos += ySpeed;
//-------------------------------------------------------------------------theBall
fill(255);
ellipse(xPos, yPos, (width + height)/25, (width + height)/25);
//----------------------------------------------------------------------theBumpers
rectMode(CENTER);
fill(lC);
rect(yBumperWidth/2, yPos, yBumperWidth, yBumperHeight);
fill(rC);
rect(right-((yBumperWidth)/2), yPos, yBumperWidth, yBumperHeight);
fill(tC);
rect(xPos, xBumperHeight/2, xBumperWidth, xBumperHeight);
fill(bC);
rect(xPos, bottom - (xBumperHeight/2), xBumperWidth, xBumperHeight);
//wallBounce
xPos = constrain(xPos, left + radius/2 + yBumperWidth, right - radius/2 - yBumperWidth);
if(xPos >= right - radius/2 - yBumperWidth || xPos <= left + radius/2 + yBumperWidth)
{
xSpeed = -xSpeed;
}
yPos = constrain(yPos, top + radius/2 + xBumperHeight, bottom - radius/2 - xBumperHeight);
if(yPos >= bottom - radius/2 - xBumperHeight || yPos <= top + radius/2 + xBumperHeight)
{
ySpeed = -ySpeed;
}
//colorChanger
//---------------------------------------------------rightChange
if (xPos >= right - radius/2 - yBumperWidth)
{
rCounter += 1;
println("Right Bumper hit = " + rCounter + " times");
}
//----------------------------------------------------leftChange
if (xPos <= left + radius/2 + yBumperWidth)
{
//here is where I need help with the lerpColor function. I think this is where it should sit.
lCounter += 1;
println("Left Bumper hit = " + lCounter + " times");
}
//---------------------------------------------------bottomChange
if (yPos >= bottom - radius/2 - xBumperHeight)
{
bCounter += 1;
println("Bottom Bumper hit = " + bCounter + " times");
}
//------------------------------------------------------topChange
if (yPos <= top + radius/2 + xBumperHeight)
{
tCounter += 1;
println("Top Bumper hit = " + tCounter + " times");
}
}
1