Skip to content

Drawing some shapes

Ryan G edited this page Sep 18, 2017 · 3 revisions

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

import dgt;

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

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

New lines

window.draw(Color.blue, Circle(400, 300, 40)); draws a blue Circle. 400 gives the x, 300 gives the y, and 40 gives the radius.

window.draw(Color.red, Rectangle(100, 0, 32, 48)); draws a red Rectangle. 100 gives the x, 0 gives the y, 32 gives the width, and 48 gives the height.

Clone this wiki locally