lundi 13 juin 2016

Easier way to draw this?

I'm attempting to draw a type of crosshair with the Java graphics methods. I wrote this but it seems way overkill and I feel like it can be simplified quite a bit. I will include a picture of what it looks like.

How can I simplify this?

    graphics.setColor(mainColor);
    graphics.drawRect(Mouse.getPos().x - 13, Mouse.getPos().y - 13, 27, 27); // Rectangle stroke.
    graphics.drawRect(Mouse.getPos().x, Mouse.getPos().y - 512, 1, 500);     // Top y axis stroke.
    graphics.drawRect(Mouse.getPos().x, Mouse.getPos().y + 13, 1, 500);      // Bottom y axis stroke.
    graphics.drawRect(Mouse.getPos().x + 13, Mouse.getPos().y, 800, 1);      // Right x axis stroke.
    graphics.drawRect(Mouse.getPos().x - 812, Mouse.getPos().y, 800, 1);     // left x axis stroke.
    graphics.fillOval(Mouse.getPos().x - 3, Mouse.getPos().y - 3, 7, 7);     // Center dot stroke.
    graphics.setColor(offColor);
    graphics.drawRect(Mouse.getPos().x - 12, Mouse.getPos().y - 12, 25, 25); // Rectangle.
    graphics.drawRect(Mouse.getPos().x, Mouse.getPos().y - 512, 0, 500);     // Top y axis line.
    graphics.drawRect(Mouse.getPos().x, Mouse.getPos().y + 13, 0, 500);      // Bottom y axis line.
    graphics.drawRect(Mouse.getPos().x + 13, Mouse.getPos().y, 800, 0);      // Right x axis line.
    graphics.drawRect(Mouse.getPos().x - 812, Mouse.getPos().y, 800, 0);     // left x axis line.
    graphics.fillOval(Mouse.getPos().x - 2, Mouse.getPos().y - 2, 5, 5);     // Center dot.

This is what it looks like and what it's supposed to look like. enter image description here

Aucun commentaire:

Enregistrer un commentaire