For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Example Code

Example 1: A Tree!

Here is a simple example drawing a tree with a rectangle and three triangles. The background is set to sky blue with a hex color value, and the triangles are rotated 30 degrees.

public class Main {
    public static void main(String[] args) {
        EasyDraw.loadCanvas();

        EasyDraw.setCanvasColor("#87CEEB");

        EasyDraw.Rectangle trunk = new EasyDraw.Rectangle(250, 300, 100, 310);
        trunk.setColor(160, 82, 45);

        EasyDraw.RegPolygon top = new EasyDraw.RegPolygon(3, 300, 175, 125);
        top.setColor(0, 255, 0);
        top.rotate(30);

        EasyDraw.RegPolygon middle = new EasyDraw.RegPolygon(3, 300, 275, 175);
        middle.setColor(0, 255, 0);
        middle.rotate(30);

        EasyDraw.RegPolygon bottom = new EasyDraw.RegPolygon(3, 300, 400, 250);
        bottom.setColor(0, 255, 0);
        bottom.rotate(30);

        EasyDraw.end();
    }
}

Example 2: Property Change and Event Handling

Here is an example of drawing a square and an octagon, then animating them when clicked.

When the square is clicked, it changes color to a new random value and rotates by 10 degrees.

When the octagon is clicked, it changes color to a new random value and rotates by 10 degrees.

Example 3: Moving with the Arrow Keys

The arrow keys move the blue circle. Clicking the circle adds 1 to the score.

score is a static variable of the class, not a local variable in main. A lambda can only change variables like this one. See Event Handling.

Was this helpful?