How do I draw a rectangle or a circle?

We will assume that you know how to import Minueto into your project and how to create a MinuetoWindow. If this is not the case, please read How to build your first game Window?.

Minueto allows you to build MinuetoImages of circles and rectangles. You can the draw those circles or rectangles over another MinuetoImage or MinuetoWindow.

The first step in drawing a rectangle is building the rectangle itself.ControlsThis will create an empty red rectangle of 150 pxels by 50 pxels. If you required a full rectangle, you need only to change the boolean parameter to true.

Empty rectangle vs full rectangle

The second (and final) step is to draw the rectangle on another MinuetoImage or on the MinuetoWindow. In the following example, we draw the rectangle in the top left corner of the screen.

window.draw(rectangle, 0, 0);

Drawing a circle (or an ellipse) is similar. Instead of creating a MinuetoRectangle object, you must create a MinuetoCircle object. However, that object is still a MinuetoImage and can be manipulated like any other MinuetoImage. The following example creates various squares, rectangles, circles and ellipses.

// Creates an empty 50 by 1000 black rectangle.
MinuetoImage rectangle2 = new MinuetoRectangle(50,1000,MinuetoColor.BLACK,false);
        
// Creates a full 300 by 300 blue square.
MinuetoImage rectangle3 = new MinuetoRectangle(300,300,MinuetoColor.BLUE,true);

// Creates an empty 200 by 200 red circle.
MinuetoImage circle1 = new MinuetoCircle(200,200,MinuetoColor.RED,false);

// Creates a full white circle of 100 pxel of radius.
MinuetoImage circle2 = new MinuetoCircle(100,MinuetoColor.WHITE,true);

// Creates an empty 150 by 50 gray ellipse.
MinuetoImage circle3 = new MinuetoCircle(150,50,new MinuetoColor(128,128,128),false);

This howto would not be complete without an example application that draws rectangles and circles.

import org.minueto.*; 
import org.minueto.handlers.*; 
import org.minueto.image.*; 
import org.minueto.window.*; 

public class Demo {

    public static void main(String[] args) {
        MinuetoWindow window; 
        MinuetoImage rectangle;
        MinuetoImage circle;

        window = new MinuetoFrame(640, 480, true); 

        MinuetoImage rectangle = new MinuetoRectangle(50,1000,MinuetoColor.BLACK,false);
        MinuetoImage circle = new MinuetoCircle(100,MinuetoColor.WHITE,true);

        window.setVisible(true);

        while(true) { 
            window.draw(rectangle, 10, 10);
            window.draw(circle, 250, 250);
            window.render();
            Thread.yield();
        }
    }
}