How do I make my object rotate in a specific angle?

Hello there,

I'm really not much experienced with processing, I have an object that must be moving in a specific angle. My object is already in the center (I'm glad I made it that far) and I want it to rotate 30 degrees up and down, I already could manage to make it move 30 degrees down but I have not the slightest clue how to make it a fluently move that continues moving up and down. I already tried a lot of things but just can't figure out how to do it. Btw this is the code that I could create yet:

int myRotation;

void setup() { size(600, 600); background(150); fill(255); noStroke(); }

void draw() {

background(255); fill(0);

if(myRotation < 30) { myRotation++; }

for (int i = 2; i<3; i++) { for (int e = 3; e < 4; e++) { pushMatrix(); translate(300, 300); rotate(radians(myRotation)); quad(0, 0, -50, -100, 50, 0, -150, 50); popMatrix(); } } }

thanks a lot in advance! :)

Tagged:

Answers

  • edited January 2018

    What do you mean when you say you want to make it move 30 degrees down? Do you have any mock images? Also please properly format your code using the code button in the forum editor.

  • edited January 2018

    my object is aiming to the right and its supposed to rotate to 30 degrees upwards, then stops, starts to rotate 60 degrees downwards, and over and over again. sry for that shitty explanation.

    int myRotation;
    
    void setup() {
      size(600, 600);
      background(150);
      fill(255);
      noStroke();
    }
    
    void draw() {
    
      background(255);
      fill(0);
    
      if(myRotation < 30) {
        myRotation++;
      }
    
    
    
      for (int i = 2; i<3; i++) {
        for (int e = 3; e < 4; e++) {
          pushMatrix();
          translate(300, 300); 
          rotate(radians(myRotation));
          quad(0, 0, -50, -100, 50, 0, -150, 50);
          popMatrix();
        }
      }
    }
    

    thanks a lot

  • Answer ✓

    Example below.

    Kf

    int myRotation=0;
    int omega=1;
    
    void setup() {
      size(600, 600);
      background(150);
      fill(255);
      noStroke();
    
      rectMode(CENTER);
    }
    
    void draw() {
    
      background(255);
      fill(0);
    
      if (frameCount%15==0) {  //Slow downs operation. Only every 15 frames
        if (abs(myRotation) > 30 ) { //Changes direction when going over 30deg either pos or neg
    
          omega=-omega;
        }
      }
    
      myRotation+=omega;
    
      pushMatrix();
      //Body
      translate(width/2, height/2); 
      rotate(radians(myRotation));
      rect(0,0, 50, 90);
    
      //Tip
      translate(0,45); //Half body's length
      rotate(PI/4.0);  //45 deg rotation wrt current reference frame
      rect(0,0,50,50);
    
      popMatrix();
    }
    
  • Thank you very much sir, problem solved

Sign In or Register to comment.