Skip to content

Drawing some shapes

Ryan G edited this page Aug 28, 2017 · 3 revisions

Now that we have a window, we should populate it with something.

import dgt;

void main()
{
    WindowConfig config;
    Window window = Window("Your First Window", 800, 600, config);
    Rectanglei camera = Rectanglei(0, 0, 800, 600);
    while(window.isOpen)
    {
        window.begin(Color.white, camera);
        window.draw(Color.blue, Circlei(400, 300, 40));
        window.draw(Color.red, Rectanglei(100, 0, 32, 32));
        window.end();
    }
}

The window should now have a blue circle and a red square. The blue circle should be exactly centered, and the red square should be at the top of the window offset 100 pixels from the left.

New lines

window.draw(Color.blue, Circlei(400, 300, 40)); draws a blue Circle. 400 gives the x, 300 gives the y, and 40 gives the radius. (Like Rectanglei, Circlei is an alias for Circle!int)

window.draw(Color.red, Rectanglei(100, 0, 32, 32)); draws a red Rectangle. It is constructed much the same way as the camera.

Clone this wiki locally