Rotate lines in the middle of the square

Can some1 help me please? I want to make these lines in the middle of the square rotating but i actually can’t. I tried…again…some processing coding, and…unfortunately…it showed me rotate error. thx for help

float angle = 250;

void setup() {
  size(500, 500);
  background(255, 255, 255);
}
void draw() {
  rotate(angle);
  line(250, 250, 200, 50);
  line(250, 250, 50, 200);
  angle = angle +1;
}
1 Like

A few things:

  1. I believe you are trying to do the angles in degrees, which is not the default setting. By default, Processing uses radians which go between 0 and tau (6.282… or 2*pi) rather than 360. For that reason, adding 1 to the angle each frame makes it rotate really quickly (about 57 degrees each frame) and it does not rotate smoothly. A simple solution to this is to convert your angle into radians using the function radians() so rotate(angle) becomes rotate(radians(angle)).

  2. I could be wrong here but I assume that you want to not see where the lines were before so rather than just drawing the background once, you want to draw it every frame and then draw the lines on top of that.

  3. Again, I am just guessing here (I couldn’t quite understand what you wanted), but I think you want the lines to rotate around the middle not around the corner. How you achieve this is by making (0,0) the middle of the screen with the line translate(width/2, height/2);.

  4. Please can you format you code with the </> button next time and make sure it is properly intented (ctrl + T in the Processing IDE).

Here is the code having made those modifications:

float angle = 250;

void setup() {
  size(700, 700);
}

void draw() {
  background(255, 255, 255);
  
  translate(width/2, height/2);
  rotate(radians(angle));
  
  line(250, 250, 200, 50);
  line(250, 250, 50, 200);
  
  angle += 1;
}

Feel free to ask any questions.

4 Likes

Ok, thanks, but i mentioned something moving like : (picture attached to this message)

  translate(width/2, height/2);
  rotate(radians(angle));


that is the correct way,
now you should know that after translate the center is middle of screen,
and should draw your lines with that in mind

1 Like

We just need to change the coordinates (remember that the center is (0,0) now).

This it what is should be so that it rotates around that point:

line(0, 0, -50, -200);
line(0, 0, -200, -50);
3 Likes