Changing background color after rotating object

hello guys.
I am new to processing. my question is how can I make my rotating object not to leave a trail behind him. I know that it can be done by using background() function but my background is gray and my object is in a rectangle that is filled blue using fill() command

import processing.serial.*;

Serial mySerial;
  
float a=0.0;

void setup(){
//Pozadina
  size(1000,1000);
  background(#838383);
//Pravokutnici na dnu
   rectMode(CORNERS);
     fill(#FAF203);
       rect(0,800,250,1000);
     fill(#FF1A00);
       rect(250,800,500,1000);
     fill(#0BFF00);
       rect(500,800,750,1000);
     fill(#0028FF);
       rect(750,800,1000,1000);
//Obrub pravokutnika     
   strokeWeight(5);
     line(250,800,250,1000);
     line(500,800,500,1000);
     line(750,800,750,1000);
     line(999,800,999,1000);
     line(0,800,1000,800);
     line(0,800,0,1000);
     line(0,999,1000,999);
   strokeWeight(0);

}
//Model glavnog drona
void dron_main(){
  fill(#000000);
    ellipseMode(CENTER);
    ellipse(500,400,300,300);
  
    beginShape();
      vertex(712,682);
      vertex(217,187);
      vertex(287,117);
      vertex(782,612);
    endShape(CLOSE);
  
    beginShape();
      vertex(217,612);
      vertex(712,117);
      vertex(782,187);
      vertex(287,682);
    endShape(CLOSE);
    
    ellipse(252,152,100,100);
    ellipse(747,152,100,100);
    ellipse(747,647,100,100);
    ellipse(252,647,100,100);
}
//Model animiranog drona
void dron_anim(){
   fill(#000000);
    ellipseMode(CENTER);
    ellipse(0,0,75,75);
    
    beginShape();
      vertex(45,-60);
      vertex(-60,45);
      vertex(-45,60);
      vertex(60,-45);
    endShape(CLOSE);
    
    beginShape();
      vertex(-60,-45);
      vertex(45,60);
      vertex(60,45);
      vertex(-45,-60);
    endShape(CLOSE);
    
    ellipse(-53,53,20,20);
    ellipse(53,53,20,20);
    ellipse(-53,-53,20,20);
    ellipse(53,-53,20,20);
    
}

void motor1(){
    fill(#FF8C00);
    rectMode(CENTER);
      rect(252,152,75,15);
     fill(#C0C0C0);
      rect(252,123,75,45);
     fill(#FF8C00);
      rect(252,93,75,15);
     fill(#C0C0C0);
      rect(252,70,10,30);
     fill(#000000);
     textSize(32);
       text("M1",230,134);
}

void motor2(){
    fill(#FF8C00);
    rectMode(CENTER);
      rect(747,152,75,15);
     fill(#C0C0C0);
      rect(747,123,75,45);
     fill(#FF8C00);
      rect(747,93,75,15);
     fill(#C0C0C0);
      rect(747,70,10,30);
     fill(#000000);
     textSize(32);
       text("M2",725,134);
}

void motor3(){
    fill(#FF8C00);
    rectMode(CENTER);
      rect(252,647,75,15);
     fill(#C0C0C0);
      rect(252,618,75,45);
     fill(#FF8C00);
      rect(252,589,75,15);
     fill(#C0C0C0);
      rect(252,566,10,30);
     fill(#000000);
     textSize(32);
       text("M3",230,630);
}

void motor4(){
    fill(#FF8C00);
    rectMode(CENTER);
      rect(747,647,75,15);
     fill(#C0C0C0);
      rect(747,618,75,45);
     fill(#FF8C00);
      rect(747,589,75,15);
     fill(#C0C0C0);
      rect(747,566,10,30);
     fill(#000000);
     textSize(32);
       text("M4",725,630);
}

void draw(){
    dron_main();
    
    motor1();
    motor2();
    motor3();
    motor4();
    
    pushMatrix();
      fill(#0028FF);
      translate(875,900);
      rotate(a);
      dron_anim();
    popMatrix();
    
    a+=.01;
}
1 Like

don’t draw stuff in setup()

instead draw it in draw() after background()

import processing.serial.*;

Serial mySerial;

float a=0.0;

void setup() {
  //Pozadina
  size(1000, 1000);
  background(#838383);
}

//Model glavnog drona
void dron_main() {
  fill(#000000);
  ellipseMode(CENTER);
  ellipse(500, 400, 300, 300);

  beginShape();
  vertex(712, 682);
  vertex(217, 187);
  vertex(287, 117);
  vertex(782, 612);
  endShape(CLOSE);

  beginShape();
  vertex(217, 612);
  vertex(712, 117);
  vertex(782, 187);
  vertex(287, 682);
  endShape(CLOSE);

  ellipse(252, 152, 100, 100);
  ellipse(747, 152, 100, 100);
  ellipse(747, 647, 100, 100);
  ellipse(252, 647, 100, 100);
}
//Model animiranog drona
void dron_anim() {
  fill(#000000);
  ellipseMode(CENTER);
  ellipse(0, 0, 75, 75);

  beginShape();
  vertex(45, -60);
  vertex(-60, 45);
  vertex(-45, 60);
  vertex(60, -45);
  endShape(CLOSE);

  beginShape();
  vertex(-60, -45);
  vertex(45, 60);
  vertex(60, 45);
  vertex(-45, -60);
  endShape(CLOSE);

  ellipse(-53, 53, 20, 20);
  ellipse(53, 53, 20, 20);
  ellipse(-53, -53, 20, 20);
  ellipse(53, -53, 20, 20);
}

void motor1() {
  fill(#FF8C00);
  rectMode(CENTER);
  rect(252, 152, 75, 15);
  fill(#C0C0C0);
  rect(252, 123, 75, 45);
  fill(#FF8C00);
  rect(252, 93, 75, 15);
  fill(#C0C0C0);
  rect(252, 70, 10, 30);
  fill(#000000);
  textSize(32);
  text("M1", 230, 134);
}

void motor2() {
  fill(#FF8C00);
  rectMode(CENTER);
  rect(747, 152, 75, 15);
  fill(#C0C0C0);
  rect(747, 123, 75, 45);
  fill(#FF8C00);
  rect(747, 93, 75, 15);
  fill(#C0C0C0);
  rect(747, 70, 10, 30);
  fill(#000000);
  textSize(32);
  text("M2", 725, 134);
}

void motor3() {
  fill(#FF8C00);
  rectMode(CENTER);
  rect(252, 647, 75, 15);
  fill(#C0C0C0);
  rect(252, 618, 75, 45);
  fill(#FF8C00);
  rect(252, 589, 75, 15);
  fill(#C0C0C0);
  rect(252, 566, 10, 30);
  fill(#000000);
  textSize(32);
  text("M3", 230, 630);
}

void motor4() {
  fill(#FF8C00);
  rectMode(CENTER);
  rect(747, 647, 75, 15);
  fill(#C0C0C0);
  rect(747, 618, 75, 45);
  fill(#FF8C00);
  rect(747, 589, 75, 15);
  fill(#C0C0C0);
  rect(747, 566, 10, 30);
  fill(#000000);
  textSize(32);
  text("M4", 725, 630);
}

void draw() {
  //background(111);
  background(#838383);

  //Pravokutnici na dnu
  rectMode(CORNERS);
  fill(#FAF203);
  rect(0, 800, 250, 1000);
  fill(#FF1A00);
  rect(250, 800, 500, 1000);
  fill(#0BFF00);
  rect(500, 800, 750, 1000);
  fill(#0028FF);
  rect(750, 800, 1000, 1000);
  //Obrub pravokutnika     
  strokeWeight(5);
  line(250, 800, 250, 1000);
  line(500, 800, 500, 1000);
  line(750, 800, 750, 1000);
  line(999, 800, 999, 1000);
  line(0, 800, 1000, 800);
  line(0, 800, 0, 1000);
  line(0, 999, 1000, 999);
  strokeWeight(0);

  dron_main();

  motor1();
  motor2();
  motor3();
  motor4();

  pushMatrix();
  fill(#0028FF);
  translate(875, 900);
  rotate(a);
  dron_anim();
  popMatrix();

  a+=.01;
}
//
2 Likes

the sketch I posted can be improved

  • setup and draw should be one after another at the beginning of the sketch, right after all the global vars and arrays

  • the section in draw() named //Pravokutnici na dnu should be a new function that you call from draw()

Chrisir