Skip to main content

Basic drawing

What this example shows​

Draw a pixel, a line and several shapes in color near the top-left corner, then repeat them in all four screen rotations. The result is a symmetrical pattern around the screen, shown with a single refresh.

Example code​

"""Draw shapes around the upper left corner, then rotate the screen.

Creates a symmetrical-looking pattern of various shapes.
"""

# Include all the required libraries
from inkplate7spectra import Inkplate

# Create Inkplate object
display = Inkplate()


# Initialize the display, needs to be called only once
display.begin()

# Let's draw some shapes!
# This example will draw shapes around the upper left corner, and then rotate the screen
# This creates a symmetrical-looking pattern of various shapes
for r in range(4):
# Sets the screen rotation
display.set_rotation(r)

# All drawing functions
# Available colors are:
# Black, white, green, blue, red, yellow, orange
display.draw_pixel(100, 100, display.BLACK)
display.draw_rect(50, 50, 75, 75, display.GREEN)
display.draw_circle(200, 200, 30, display.BLUE)
display.fill_circle(300, 300, 30, display.RED)
display.draw_fast_hline(20, 100, 50, display.BLACK)
display.draw_round_rect(100, 10, 100, 100, 10, display.BLACK)
display.fill_round_rect(10, 100, 100, 100, 10, display.YELLOW)
display.draw_triangle(300, 100, 400, 150, 400, 100, display.BLACK)

# Reset the rotation
display.set_rotation(0)

# Show on the display
display.display()

The comment in the file lists orange, but the module defines six colors only: BLACK, WHITE, YELLOW, RED, BLUE and GREEN.

Functions used​

Inkplate()returns Inkplate

Creates the display object from the inkplate7spectra module.

ReturnsThe display object.

display.begin()returns bool

Sets up the board and a white frame buffer. Call it once.

ReturnsTrue.

display.set_rotation(x)returns None

Sets the rotation, 0 to 3. Rotations 1 and 3 swap width and height (480 × 800).

ReturnsNothing.

display.draw_pixel(x, y, c)returns None

Sets one pixel to color c.

ReturnsNothing.

display.draw_rect(x, y, w, h, c)returns None

Draws a rectangle outline with its top-left corner at (x, y).

ReturnsNothing.

display.draw_circle(x, y, r, c)returns None

Draws a circle outline centered at (x, y) with radius r.

ReturnsNothing.

display.fill_circle(x, y, r, c)returns None

Draws a filled circle centered at (x, y) with radius r.

ReturnsNothing.

display.draw_fast_hline(x, y, w, c)returns None

Draws a horizontal line w pixels long, starting at (x, y).

ReturnsNothing.

display.draw_round_rect(x, y, q, h, r, c)returns None

Draws a rounded rectangle outline, q wide and h high, with corner radius r.

ReturnsNothing.

display.fill_round_rect(x, y, q, h, r, c)returns None

Draws a filled rounded rectangle, q wide and h high, with corner radius r.

ReturnsNothing.

display.draw_triangle(x0, y0, x1, y1, x2, y2, c)returns None

Draws a triangle outline through the three corner points.

ReturnsNothing.

display.display(leave_on=False)returns None

Sends the frame buffer to the panel and refreshes it.

ReturnsNothing.

Every color argument is a color index; use the class constants such as display.RED. A value above 5 is ignored.

What to expect​

After the refresh, the same group of shapes appears four times, once from each corner of the screen: black lines and outlines, a green square outline, a blue circle outline, a filled red circle and a filled yellow rounded square. Nothing is printed in the shell.

🔗Open the complete example

examples/inkplate7spectra/basic_color.py

→