How to make my shape move on a curve?

Hey! This is my first project using Processing. I decided to make a little landscape with a mouse-dependant animation of sunrise/sunset. It's obviously very crude, but my problem right now is I've only managed to make the moon/sun move on two mirrored lines, as opposed to a nice curve, which is what I'd really like. Can anyone offer their help? Here's what I have so far.

void setup() {
  size(500,500);

}
void draw() {

    noStroke(); 
  if (mouseX<250) {
     background(mouseX/0.98,mouseX/0.98,0);
     fill(255,255-mouseX/0.98,255-mouseX/0.98); 
    ellipse(mouseX,150-mouseX/2.5,50,50);  
  } else {
     background(255-(mouseX-250)/0.98,255-(mouseX-250)/0.98,0);
     fill(255,(mouseX-250)/0.98,(mouseX-250)/0.98);
    ellipse(mouseX,50.4+(mouseX-250)/2.5,50,50);
  }

  fill(23,122,11);
  ellipse(80,220,100,100);
  ellipse(265,250,230,200);
  ellipse(500,310,200,300);

  fill(40,180,20);
  ellipse(0,270,230,230);
  ellipse(150,280,230,190);
  ellipse(260,275,120,120);

  fill(30,215,7);
  ellipse(55,370,250,250);
  ellipse(235,380,200,175);
  ellipse(415,320,320,300);

  fill(26,255,0);
  rect(0,400,500,100);

}
Tagged:

Answers

  • edited May 2014 Answer ✓
    void setup() {
      size(500, 500);
      noStroke();void setup() {
      size(500, 500);
      noStroke();
    }
    void draw() {
      float rg = map(abs((millis()%10000)-5000), 0, 5000, 0, 255);
      background(rg, rg, 0);
      pushMatrix();
      translate(width/2, height/2);
      rotate(-PI);
      rotate(map(millis()%10000, 0, 10000, 0, TWO_PI));
      // The Sun
      fill(255, 255-rg, 255-rg); 
      ellipse(0, 200, 50, 50);
      // The Moon
      fill(255);
      ellipse(0, -200, 50, 50);
      popMatrix();
    
      fill(23, 122, 11);
      ellipse(80, 220, 100, 100);
      ellipse(265, 250, 230, 200);
      ellipse(500, 310, 200, 300);
    
      fill(40, 180, 20);
      ellipse(0, 270, 230, 230);
      ellipse(150, 280, 230, 190);
      ellipse(260, 275, 120, 120);
    
      fill(30, 215, 7);
      ellipse(55, 370, 250, 250);
      ellipse(235, 380, 200, 175);
      ellipse(415, 320, 320, 300);
    
      fill(26, 255, 0);
      rect(0, 400, 500, 100);
    }
    
Sign In or Register to comment.