How do you make a quadrilateral follow the mouse in this code below:

It is making a trail of quadrilaterals:

boolean Var1 = false; boolean Var2 = false;

void setup() {

//Set the size of the window to 800 by 650 size(800, 650);

//Set the color mode to HSB with ranges of 360, 100, and 100 respectively colorMode(HSB, 360, 100, 100);

//Set the shapes so it has no outline/stroke noStroke();

//Set the color of the background background(37, 9, 84);

//Set the color of the trapezoid behind all shapes fill(354, 25, 78);

//Draw the trapezoid quad(100, 50, 850, 150, 700, 680, 20, 500);

//Set the color of the uppermost red quadrilateral fill(354, 68, 70);

//Draw the uppermost red quadrilateral quad(800, 60, 800, 110, 550, 50, 630, 5);

//Set the gray quadrilateral color above the pink trapezoid & draw it fill(0, 0, 33);

beginShape();

vertex(250, 640);

vertex(400, -15);

vertex(675, 40);

vertex(785, 550);

bezierVertex(785, 550, 500, 400, 250, 640);

endShape();

//Set the color of the black diagonal rectangle fill(359, 0, 0);

//Draw the rectangle quad(435, 20, 505, 50, 215, 540, 150, 515);

//Set the color of the big triangle in the middle of the whole painting fill(7, 76, 67);

//Draw the big triangle in the middle of the whole painting triangle(100, 2, 775, 350, 450, 700);

//Set the color of the small trapezoid in the middle of the painting fill(51, 10, 83);

//Draw the small trapezoid in the middle of the painting quad(500, 350, 550, 450, 730, 500, 680, 250);

}

void draw() { //create white trapezoid that follows mouse fill(255, 255, 255); quad(mouseX, mouseY, mouseX+50, mouseY+100, mouseX+230, mouseY+150, mouseX+180, mouseY-100);

}

void mousePressed() {

//Set fill of rectangle fill(52, 75, 98);

//Set mode of rectangle to CENTER rectMode(CENTER);

//Draw Rectangle rect(mouseX, mouseY, 16, 32); }

void keyPressed() { clear();

//Set the shapes so it has no outline/stroke noStroke();

//Set the color of the background background(37, 9, 84);

//Set the color of the trapezoid behind all shapes fill(354, 25, 78);

//Draw the trapezoid quad(100, 50, 850, 150, 700, 680, 20, 500);

//Set the color of the uppermost red quadrilateral fill(240, 99, 99);

//Draw the uppermost red quadrilateral quad(800, 60, 800, 110, 550, 50, 630, 5);

//Set the gray quadrilateral color above the pink trapezoid & draw it fill(0, 0, 33);

beginShape();

vertex(250, 640);

vertex(400, -15);

vertex(675, 40);

vertex(785, 550);

bezierVertex(785, 550, 500, 400, 250, 640);

endShape();

//Set the color of the black diagonal rectangle fill(359, 0, 0);

//Draw the rectangle quad(435, 20, 505, 50, 215, 540, 150, 515);

//Set the color of the big triangle in the middle of the whole painting fill(7, 76, 67);

//Draw the big triangle in the middle of the whole painting triangle(100, 2, 775, 350, 450, 700);

//Set the color of the small trapezoid in the middle of the painting fill(51, 10, 83);

//Draw the small trapezoid in the middle of the painting quad(500, 350, 550, 450, 730, 500, 680, 250); }

Tagged:

Answers

  • edited May 2016

    Any immediate answer would be appreciated!

  • use background() to clear the screen every frame.

    also, format your code - highlight it and press ctrl-o.

  • edited May 2016

    7:55PM
    8:01PM

    that's 6 minutes. on a sunday...

  • edited May 2016
    boolean Var1 = false;
    boolean Var2 = false;
    
    void setup() {
    
      //Set the size of the window to 800 by 650
      size(800, 650);
    
      //Set the color mode to HSB with ranges of 360, 100, and 100 respectively
      colorMode(HSB, 360, 100, 100);
    
      //Set the shapes so it has no outline/stroke
      noStroke();
    
      //Set the color of the background
      background(37, 9, 84);
    
      //Set the color of the trapezoid behind all shapes
      fill(354, 25, 78);
    
      //Draw the trapezoid
      quad(100, 50, 850, 150, 700, 680, 20, 500);
    
      //Set the color of the uppermost red quadrilateral
      fill(354, 68, 70);
    
      //Draw the uppermost red quadrilateral
      quad(800, 60, 800, 110, 550, 50, 630, 5);
    
      //Set the gray quadrilateral color above the pink trapezoid & draw it
      fill(0, 0, 33);
    
      beginShape();
      vertex(250, 640);
      vertex(400, -15);
      vertex(675, 40);
      vertex(785, 550);
      bezierVertex(785, 550, 500, 400, 250, 640);
      endShape();
    
      //Set the color of the black diagonal rectangle
      fill(359, 0, 0);
    
      //Draw the rectangle
      quad(435, 20, 505, 50, 215, 540, 150, 515);
    
      //Set the color of the big triangle in the middle of the whole painting
      fill(7, 76, 67);
    
      //Draw the big triangle in the middle of the whole painting
      triangle(100, 2, 775, 350, 450, 700);
    
      //Set the color of the small trapezoid in the middle of the painting
      fill(51, 10, 83);
    
      //Draw the small trapezoid in the middle of the painting
      quad(500, 350, 550, 450, 730, 500, 680, 250);
    }
    
    void draw() {
       //create white trapezoid that follows mouse
      fill(255, 255, 255);
      quad(mouseX, mouseY, mouseX+50, mouseY+100, mouseX+230, mouseY+150, mouseX+180, mouseY-100);
    }
    
    void mousePressed() {
      //Set fill of rectangle
      fill(52, 75, 98);
    
      //Set mode of rectangle to CENTER
      rectMode(CENTER);
    
      //Draw Rectangle
      rect(mouseX, mouseY, 16, 32);
    }
    
    void keyPressed() {
      clear();
    
      //Set the shapes so it has no outline/stroke
      noStroke();
    
      //Set the color of the background
      background(37, 9, 84);
    
      //Set the color of the trapezoid behind all shapes
      fill(354, 25, 78);
    
      //Draw the trapezoid
      quad(100, 50, 850, 150, 700, 680, 20, 500);
    
      //Set the color of the uppermost red quadrilateral
      fill(240, 99, 99);
    
      //Draw the uppermost red quadrilateral
      quad(800, 60, 800, 110, 550, 50, 630, 5);
    
      //Set the gray quadrilateral color above the pink trapezoid & draw it
      fill(0, 0, 33);
    
      beginShape();
      vertex(250, 640);
      vertex(400, -15);
      vertex(675, 40);
      vertex(785, 550);
      bezierVertex(785, 550, 500, 400, 250, 640);
      endShape();
    
      //Set the color of the black diagonal rectangle
      fill(359, 0, 0);
    
      //Draw the rectangle
      quad(435, 20, 505, 50, 215, 540, 150, 515);
    
      //Set the color of the big triangle in the middle of the whole painting
      fill(7, 76, 67);
    
      //Draw the big triangle in the middle of the whole painting
      triangle(100, 2, 775, 350, 450, 700);
    
      //Set the color of the small trapezoid in the middle of the painting
      fill(51, 10, 83);
    
      //Draw the small trapezoid in the middle of the painting
      quad(500, 350, 550, 450, 730, 500, 680, 250);
    }
    

    OK but still koogs how can i get the quadrilateral to move here because here it is making a trail of that shape, how can I stop that

  • What is the 6 minutes thing koogs???

    SOMEONE HELP ME PLZ MY ASSIGNMENT IS DUE IN 7 HOURS HLEP PLZ

  • Answer ✓

    SOMEONE HELP ME PLZ MY ASSIGNMENT IS DUE IN 7 HOURS HLEP PLZ

    please don't shout.

    it's making a trail because you aren't clearing the screen between frames.

    draw() runs 60 times a second but if you don't clear the screen every frame, using background() then anything you draw will just act as a paintbrush, which is what you're seeing.

    the problem here is that you have a background image.

    you need to, in draw(),

    clear the screen
    draw your background shapes
    draw the trapezoid at the mouse position

    all the repeated code in setup() and keyPressed() should be in draw() BEFORE the two lines currently in there.

Sign In or Register to comment.