-
Bouncing DVD Logo: How do I change the shape color when it changes direction?
Hello all,
I am new to this forum and to after effects expressions. I thought an easy project to try using expressions on is the old bouncing DVD logo. Boy was I wrong. I learned to make the bouncing dvd logo expression from Dan Ebberts here: https://forums.creativecow.net/thread/227/1416
But what I am still missing is making the color of the shape layer change color every time it hits a wall and changes direction. I figured the best way would be to use the original expression and make the fill layer change color when the shape velocity hits 0 and changes direction, but I don’t know how expression math works.
Is there a way to do this? Please let me know!
(also if anyone knows a website or book to learn basic expressions please point me in the right direction)
Thanks,
Mason
left = 100;
top = 100;
right = thisComp.width -100;
bottom = thisComp.height -100;minSpeed = 200; //pixels per second
maxSpeed = 200;minX = left;
maxX = right;
minY = top + 20;
maxY = bottom - 20;minR = 5;
maxR = 85;seedRandom(index,true);
// calc start position
pos = random([minX,minY],[maxX,maxY])
quadrent = Math.floor(random(4))*90;
angle = random(minR,maxR) + quadrent;
spd = random(minSpeed,maxSpeed);// initialize time count;
t = 0;
while(t <= time){
rads = degreesToRadians(angle);
xVel = spd*Math.cos(rads);
yVel = spd*Math.sin(rads);// see if going up or down
if (yVel < 0) yLim = top else yLim = bottom;
// see if going right or left
if (xVel < 0) xLim = left else xLim = right;
timeX = (xLim - pos[0])/xVel;
timeY = (yLim - pos[1])/yVel;if (timeX < timeY){ //hit left or right wall
if (t + timeX >= time){
deltaT = time - t;
pos += [xVel,yVel]*deltaT;
break;
}else{
pos = [xLim,pos[1] + yVel*timeX];
angle = 180 - angle;
t += timeX;
}
}else{ //hit upper or lower wall
if (t + timeY >= time){
deltaT = time - t;
pos += [xVel,yVel]*deltaT;
break;
}else{
pos = [pos[0] + xVel*timeY,yLim];
angle = 360 - angle;
t += timeY;
}
}
}
pos
