Move a cursor to a new spot without leaving behind the previous position

Hello,

I'm trying to make a finger cursor to draw in an environment. I have the environment drawn, but the cursor is giving me trouble. Whenever I move it, the cursor leaves its shape behind in the previously occupied spot. How would I make the cursor leave its mark and then move it to the next position?

Tagged:

Answers

  • @chrisu --

    Please share a short sketch demonstrating your problem.

    It sounds like you are using an image() and need to call background() at the beginning of your draw(). The alternative is to use cursor().

  • void setup() //set up the drawing environment { size(700, 700);

    fill(141); rect(0, 0, 700, 40);

    fill(141); rect(25, 340, 650, 20); rect(25, 680, 650, 20);

    fill(255, 248, 56); rect(0, 40, 25, 640); rect(675, 40, 25, 640); //this ends the school bus drawing environment
    }

    void draw() //draw with a finger { translate(mouseX,mouseY); // draw the finger fill(252,207,161); rect(mouseX, mouseY , 25, 125); }

    This is the processing code. I will attach a file when I find the attach button.

    Thank you so much

  • Sorry it's so rough

  • int num=60; //declare "num" variable 
    float mx[]=new float[num];
    float my[]=new float[num];
    
    void setup()  //set up the drawing environment
    {
      size(700, 700);
    
      fill(141);
      rect(0, 0, 700, 40);
    
      fill(141);
      rect(25, 340, 650, 20);
      rect(25, 680, 650, 20);
    
      fill(255, 248, 56);
      rect(0, 40, 25, 640);
      rect(675, 40, 25, 640); //this ends the school bus drawing environment  
    }
    
    void draw() //draw with a finger
    {
    {
    }
    // Stores previous value as first value in new array
      for(int i=1; i<num; i++) {
        mx[i-1]=mx[i];
        my[i-1]=my[i];
    }
      mx[num-1]=mouseX;
      my[num-1]=mouseY;
    // Drag the finger cursor to a new spot in environment 
      for(int i=0; i<num; i++){
       fill(252,207,161);
       rect(mouseX, mouseY, 25, 125);
      }
    }
    
  • Dude, again, thank you so much for all the help

  • The general idea is to make a drawing environment that simulates drawing with your finger through the dew on school bus windows. Just in case you were wondering.

  • int num = 60; //declare "num" variable 
    float mx[] = new float[num];
    float my[] = new float[num];
    
    void setup() //set up the drawing environment
     {
      size(700, 700);
    
     }
    
    void draw() //draw with a finger
     {
      background(0);
      drawStuff();
      // Stores previous value as first value in new array
      for (int i = 1; i < num; i++) {
       mx[i - 1] = mx[i];
       my[i - 1] = my[i];
      }
      mx[num - 1] = mouseX;
      my[num - 1] = mouseY;
      // Drag the finger cursor to a new spot in environment 
      for (int i = 0; i < num; i++) {
       fill(252, 207, 161);
       rect(mouseX, mouseY, 25, 125);
      }
     }
    
    void drawStuff() {
     fill(141);
     rect(0, 0, 700, 40);
    
     fill(141);
     rect(25, 340, 650, 20);
     rect(25, 680, 650, 20);
    
     fill(255, 248, 56);
     rect(0, 40, 25, 640);
     rect(675, 40, 25, 640); //this ends the school bus drawing environment   
    }
    

    What you'll want to use is the background(0) command in the draw loop at the very top. Currently in your program, what happens is the program just keeps stacking rectangles where your mouse was, and doesn't delete them once the mouse is not there (think of it as just painting rectangles on a canvas : When you move your paintbrush, the previous paint is still going to be there until you paint over it) The background() function, in a sense, paints over the whole screen in a solid black color, so that the previous rectangle will be painted over so the new one can be the only rectangle on the screen. Now, if I just typed this in the draw method, the nice background you made wouldn't be seen, as the moment after it was created, the black background would completely cover it. So instead, I packaged all of your background shapes into one method that I can execute just by typing the method's (or package's) name : drawStuff(). After drawing a black background, the program will then draw all the little background shapes that are supposed to look like a window. Then, the program will draw the rectangle where your mouse currently is. Then, the program will paint over everything in black, redraw the background, and then make a rectangle where your mouse is ... rinse and repeat!

    Hope this helps!

  • Awesome. I'll get back to you in the morning, man!

  • Oh, so the "void drawStuff" locks that down so that the changing cursor will show up?

Sign In or Register to comment.