Skip to content

Commit 45eff5c

Browse files
committed
New example using setter feature in the circle library
1 parent b19f0cc commit 45eff5c

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

docs/examples.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,48 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/display_shapes_simpletest.py
77
:caption: examples/display_shapes_simpletest.py
88
:linenos:
9+
10+
Simple test MagTag
11+
------------------
12+
13+
Simple test with the MagTag.
14+
15+
.. literalinclude:: ../examples/display_shapes_simpletest_magtag.py
16+
:caption: examples/display_shapes_simpletest_magtag.py
17+
:linenos:
18+
19+
Sparkline Simple Test
20+
---------------------
21+
22+
Simple test with Sparklines
23+
24+
.. literalinclude:: ../examples/display_shapes_sparkline_simpletest.py
25+
:caption: examples/display_shapes_sparkline_simpletest.py
26+
:linenos:
27+
28+
Sparkline Ticks Example
29+
-----------------------
30+
31+
Example using tick with the Sparkline class
32+
33+
.. literalinclude:: ../examples/display_shapes_sparkline_ticks.py
34+
:caption: examples/display_shapes_sparkline_ticks.py
35+
:linenos:
36+
37+
Sparkline Triple Test
38+
---------------------
39+
40+
reate background bitmaps and sparklines
41+
42+
.. literalinclude:: ../examples/display_shapes_sparkline_triple.py
43+
:caption: examples/display_shapes_sparkline_triple.py
44+
:linenos:
45+
46+
Circle Animation
47+
----------------
48+
49+
Example showing the features of the new Circle setter
50+
51+
.. literalinclude:: ../examples/display_shapes_circle_animation.py
52+
:caption: examples/display_shapes_circle_animation.py
53+
:linenos:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This is an animation to demonstrate the use of Circle Setter Attribute.
6+
"""
7+
8+
import time
9+
import gc
10+
import board
11+
import displayio
12+
from adafruit_display_shapes.circle import Circle
13+
14+
# use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.)
15+
# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
16+
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
17+
display = board.DISPLAY
18+
19+
# Make the display context
20+
main_group = displayio.Group(max_size=2)
21+
22+
# Make a background color fill
23+
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
24+
color_palette = displayio.Palette(1)
25+
color_palette[0] = 0xFFFFFF
26+
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
27+
main_group.append(bg_sprite)
28+
29+
# Setting up the Circle starting position
30+
posx = 50
31+
posy = 50
32+
33+
# Define Circle characteristics
34+
circle_radius = 20
35+
circle = Circle(posx, posy, circle_radius, fill=0x00FF00, outline=0xFF00FF)
36+
main_group.append(circle)
37+
38+
# Define Circle Animation Steps
39+
delta_x = 2
40+
delta_y = 2
41+
42+
# Showing the items on the screen
43+
display.show(main_group)
44+
45+
while True:
46+
47+
if circle.y + circle_radius >= display.height - circle_radius:
48+
delta_y = -1
49+
if circle.x + circle_radius >= display.width - circle_radius:
50+
delta_x = -1
51+
if circle.x - circle_radius <= 0 - circle_radius:
52+
delta_x = 1
53+
if circle.y - circle_radius <= 0 - circle_radius:
54+
delta_y = 1
55+
56+
circle.x = circle.x + delta_x
57+
circle.y = circle.y + delta_y
58+
59+
time.sleep(0.02)
60+
gc.collect()

0 commit comments

Comments
 (0)