/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Capitulo_6.Dibujo2;

import java.awt.Color;
import java.awt.Graphics;

/**
 *
 * @author felix
 */

public class Rectangulo implements Figura{
    int x0, y0, x1, y1;
    private Color c;
    
    public void set(int x0, int y0, int x1, int y1, Color c) {
        int dx, dy;
        
        this.x0 = x0;
        this.y0 = y0;
        this.x1 = x1;
        this.y1 = y1;
        
        dx = Math.abs(x0 - x1);  
        dy = Math.abs(y0 - y1);
        
        if(this.x0 > this.x1) {
            this.x1 = this.x0;
            this.x0 = this.x1 - dx;
        }
        
        if(this.y0 > this.y1) {
            this.y1 = this.y0;
            this.y0 = this.y1- dy;
        }
        
        this.c = c;     
    }

    @Override
    public void dibuja(Graphics g) {
        g.setColor(c);
        g.drawRect(x0, y0, Math.abs(x0-x1), Math.abs(y0-y1));
    }    
}
