package gy2balls;

import java.awt.Graphics;

class Rotator {

    private int x, y, size, angle;

    private double toRadian(int degree) {
        return ((double) (degree % 360)) * Math.PI / 180.0;
    }

    public Rotator(int x, int y, int size, int angle) {
        this.x = x;
        this.y = y;
        this.size = size;
        this.angle = angle;
    }

    public void paint(Graphics g) {
        int x1 = this.x + (int) (size * Math.sin(toRadian(angle + 3)));
        int y1 = this.y + (int) (size * Math.cos(toRadian(angle + 3)));
        int x2 = this.x + (int) (size * Math.sin(toRadian(angle - 3)));
        int y2 = this.y + (int) (size * Math.cos(toRadian(angle - 3)));
        int x3 = this.x + (int) (size * Math.sin(toRadian(angle + 183)));
        int y3 = this.y + (int) (size * Math.cos(toRadian(angle + 183)));
        int x4 = this.x + (int) (size * Math.sin(toRadian(angle - 183)));
        int y4 = this.y + (int) (size * Math.cos(toRadian(angle - 183)));
        g.drawLine(x1, y1, x2, y2);
        g.drawLine(x2, y2, x3, y3);
        g.drawLine(x3, y3, x4, y4);
        g.drawLine(x4, y4, x1, y1);
    }
}
