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.

import easy_draw

easy_draw.load_canvas()

easy_draw.set_canvas_color("#87CEEB")

trunk = easy_draw.Rectangle(
    xy = (250, 300), 
    width = 100, 
    height = 310,
    color = (160, 82, 45)
)

top = easy_draw.RegPolygon(
    nsides = 3,
    center_xy = (300, 175), 
    radius = 125, 
    color = (0, 255, 0)
)
top.rotate(30)

middle = easy_draw.RegPolygon(
    nsides = 3,
    center_xy = (300, 275), 
    radius = 175, 
    color = (0, 255, 0)
)
middle.rotate(30)

bottom = easy_draw.RegPolygon(
    nsides = 3,
    center_xy = (300, 400), 
    radius = 250, 
    color = (0, 255, 0)
)
bottom.rotate(30)

easy_draw.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: Decagon Islamic Design

Provided by Jackie Lin from Taiwan CSHS (Chung-shan Senior High School)

More examples coming soon!

Last updated

Was this helpful?