2

I have a simple question which I cannot find an answer for. In eclipse I have a simple GRect and GOval. How can I rotate them 90 degrees clockwise? I have tried move and movePolar but it doesn't have any effect. Here is the code:

import acm.graphics.*;
import acm.program.*;
import java.awt.*;

public class asd extends GraphicsProgram {

    public void run() {
        double x = (getWidth() - FIGURE_WIDTH) / 2;
        double y = (getHeight() - FIGURE_HEIGHT) / 2;
        GRect rect = new GRect(x, y, FIGURE_WIDTH, FIGURE_HEIGHT);
        rect.setFilled(true);
        rect.setColor(Color.RED);
        add(rect);
        GOval oval = new GOval(x, y, FIGURE_WIDTH, FIGURE_HEIGHT);
        oval.setFilled(true);
        oval.setFillColor(Color.GREEN);
        add(oval);
}

I would like to rotate this 90 degree clockwise.

demongolem
  • 9,474
  • 36
  • 90
  • 105
regeme
  • 872
  • 6
  • 17
  • 30

2 Answers2

0

You cannot rotate any object except GPolygon in acm.graphics. You could easily model the GRect as a GPolygon of course, but I suppose the GOval would have to be approximated by a polygon to use this scheme.

If your rotation is limited, I suppose as a next best course you could create multiple objects in the case of GOval. For example, if you create ovalH and ovalV, you have the 0, 90, 180 and 270 degree rotations.

demongolem
  • 9,474
  • 36
  • 90
  • 105
0

You can actually rotate GObject shapes in the ACM library with the rotate() method. For example:

GRect rect1 = new GRect(100, 100, 50, 50);
rect1.setFilled(true);
add(rect1);
rect1.rotate(90);

However, the pivot point for this is the top left corner.