Scales Library

scales

Allows display data in a graduated level

  • Author(s): Jose David M.

Implementation Notes

Scales version in CircuitPython

class scales.Axes(*args: Any, **kwargs: Any)
Parameters:
  • x (int) – pixel position. Defaults to 0

  • y (int) – pixel position. Defaults to 0

  • limits (int,int) – tuple of value range for the scale. Defaults to (0, 100)

  • ticks (list) – list to ticks to display. If this is not enter a equally spaced scale will be created between the given limits.

  • direction (str) – direction of the scale either horizontal or vertical defaults to horizontal

  • stroke (int) – width in pixels of the scale axes. Defaults to 3

  • length (int) – scale length in pixels. Defaults to 100

  • color (int) – 24-bit hex value axes line color, Defaults to Purple 0x990099

class scales.Scale(*args: Any, **kwargs: Any)
Parameters:
  • x (int) – pixel position. Defaults to 0

  • y (int) – pixel position. Defaults to 0

  • direction (str) – direction of the scale either horizontal or vertical defaults to horizontal

  • stroke (int) – width in pixels of the axes line. Defaults to 3 pixels

  • length (int) – scale length in pixels. Defaults to 100 pixels

  • color (int) – 24-bit hex value axes line color, Defaults to Purple 0x990099

  • width (int) – scale width in pixels. Defaults to 50 pixels

  • limits – tuple of value range for the scale. Defaults to (0, 100)

  • ticks (list) – list to ticks to display. If this is not enter a equally spaced scale will be created between the given limits.

  • back_color (int) – 24-bit hex value axes line color. Defaults to Light Blue 0x9FFFFF

  • tick_length (int) – Scale tick length in pixels. Defaults to 10

  • tick_stroke (int) – Scale tick width in pixels. Defaults to 4

  • pointer_length (int) – length in pixels for the point. Defaults to 20 pixels

  • pointer_stroke (int) – pointer thickness in pixels. Defaults to 6 pixels

Quickstart: Importing and using Scales

Here is one way of importing the Scale class, so you can use it as the name my_scale:

from scale import Scale

Now you can create a vertical Scale at pixel position x=50, y=180 and a range of 0 to 80 using:

my_scale = Scale(x=50, y=180, direction="vertical", limits=(0, 80))

Once you setup your display, you can now add my_scale to your display using:

display.show(my_scale)

If you want to have multiple display elements, you can create a group and then append the scale and the other elements to the group. Then, you can add the full group to the display as in this example:

my_scale= Scale(x=20, y=30)
my_group = displayio.Group() # make a group
my_group.append(my_scale) # Add my_slider to the group

#
# Append other display elements to the group
#

display.show(my_group) # add the group to the display

Summary: Slider Features and input variables

The Scale class has some options for controlling its position, visible appearance, and value through a collection of input variables:

  • position: x`, y

  • size: length and width

  • color: color, back_color

  • linewidths: stroke and tick_stroke

  • range: limits

Diagram of scales

Diagram showing a simple scale.

animate_pointer(new_value)

Public function to animate the pointer

Parameters:

new_value – value to draw the pointer

Returns:

None

scales.rectangle_draw(x0: int, y0: int, height: int, width: int, palette)

rectangle_draw function

Draws a rectangle using or vectorio.Rectangle

Parameters:
  • x0 (int) – rectangle lower corner x position

  • y0 (int) – rectangle lower corner y position

  • width (int) – rectangle upper corner x position

  • height (int) – rectangle upper corner y position

  • palette (Palette) – palette object to be used to draw the rectangle

scales.transform(oldrangemin: float | int, oldrangemax: float | int, newrangemin: float | int, newrangemax: float | int, value: float | int) float | int

This function converts the original value into a new defined value in the new range

Parameters:
  • oldrangemin (int|float) – minimum of the original range

  • oldrangemax (int|float) – maximum of the original range

  • newrangemin (int|float) – minimum of the new range

  • newrangemax (int|float) – maximum of the new range

  • value (int|float) – value to be converted

Return int|float:

converted value