This is the final code of this project…
boolean XPlus = true, YPlus = true;
boolean RTrue = true, GTrue = false, BTrue = false;
int once;
float SquareX, SquareY;
float Speed = 1;
float Size = 20;
float BackGround = 0;
float TraceX, TraceY;
int R = 0, G = 0, B = 0;
void setup() {
background(BackGround);
noSmooth();
fullScreen();
}
void draw() {
// Random Start Location //
if (once == 0) {SquareX = random(0,width); SquareY = random(0,height); once++;}
// Collision and Boundary Restriction Logic //
if (SquareX>=width-(Size/2)) {XPlus=false; SquareX=width-(Size/2);}
if (SquareX<=0) {XPlus=true; SquareX=0;}
if (SquareY>=height-(Size/2)) {YPlus=false; SquareY=height-(Size/2);}
if (SquareY<=0) {YPlus=true; SquareY=0;}
// Collision Reaction Logic //
if (XPlus==false) {SquareX=SquareX-Speed;}
if (XPlus==true) {SquareX=SquareX+Speed;}
if (YPlus==false) {SquareY=SquareY-Speed;}
if (YPlus==true) {SquareY=SquareY+Speed;}
// Trace Logic //
if (XPlus==false) {TraceX=SquareX+Speed;}
if (XPlus==true) {TraceX=SquareX-Speed;}
if (YPlus==false) {TraceY=SquareY+Speed;}
if (YPlus==true) {TraceY=SquareY-Speed;}
// Color Logic //
if (RTrue == true) {R++;}
if (GTrue == true) {G++;}
if (BTrue == true) {B++;}
if (R >= 255) {RTrue = false; GTrue = true;}
if (G >= 255) {GTrue = false; BTrue = true;}
if (B >= 255) {BTrue = false; RTrue = true;}
if (RTrue == false && R > 0) {R--;}
if (GTrue == false && G > 0) {G--;}
if (BTrue == false && B > 0) {B--;}
// Visuals //
noStroke();
fill(R, G, B);
rect(TraceX, TraceY, Size, Size);
noStroke();
fill(255);
rect(SquareX, SquareY, Size, Size);
}
void mousePressed() {
exit();
}
The only feature which I would like for this project is for maybe a way to speed up the process without having none smooth traces, if you don’t know what I mean try editing the speed variable at the very top to about 50 or 100 and you can definitely see that the square can’t trace everything perfectly.
Also thank you for the people who tried to help me.