Logic Error! White rectangle is supposed to move and reveal a white to black gradient
in
Programming Questions
•
1 year ago
I tried to move the background call to the draw method but this just made everything disappear.
can anyone help? thanks.
- int transp = 0 ;
- boolean showgradientbar = true;
- int barW;
- int barH = 40;
- int topleftX;
- int topleftY;
- float speed = 1;
- float rectxloc = 125;
- void setup (){
- size (500,300);
- background (255);
- barW = width/2;
- topleftX = width/2-width/4;
- topleftY = height/2 - 20;
- drawgradientbar ();
- }
- void draw(){
- move();
- movewhiterectangle ();
- }
- void drawgradientbar (){
- rectMode (CENTER);
- rect (width/2, height/2, 260, 50);
- if (showgradientbar == true) {
- for (int i=0; i<barW; i+=1) {
- transp +=1;
- stroke (0,0,0,transp);
- line (topleftX+i,topleftY,topleftX+i,topleftY+barH);
- }
- }
- }
- void move (){
- rectxloc += speed;
- if (rectxloc > width) {
- rectxloc = 0;
- }
- }
- void movewhiterectangle (){
- noStroke();
- fill (255);
- rectMode(CORNER);
- rect (rectxloc,topleftY,barW,barH);
- }
1