Skip to content

Commit ca94186

Browse files
initial repo load
1 parent 423a0f8 commit ca94186

File tree

5 files changed

+56
-53
lines changed

5 files changed

+56
-53
lines changed

README.rst

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ Introduction
99
:alt: Discord
1010

1111

12-
.. image:: https://github.com/CedarGroveStudios/Cedargrove_CircuitPython_ColorFader/workflows/Build%20CI/badge.svg
13-
:target: https://github.com/CedarGroveStudios/Cedargrove_CircuitPython_ColorFader/actions
12+
.. image:: https://github.com/CedarGroveStudios/CircuitPython_ColorFader/workflows/Build%20CI/badge.svg
13+
:target: https://github.com/CedarGroveStudios/CircuitPython_ColorFader/actions
1414
:alt: Build Status
1515

1616

1717
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
1818
:target: https://github.com/psf/black
1919
:alt: Code Style: Black
2020

21-
A CircuitPython helper for brightness and gamma adjustment of an integer RGB color value.
22-
21+
A CircuitPython helper for brightness and gamma adjustment of an integer RGB
22+
color value. Gamma is optionally applied after the brightness calculation.
23+
Transparency is preserved. Returns an adjusted integer color value.
24+
To adjust a ``displayio`` palette or multiple color list, use the
25+
``cedargrove_palettefader.PaletteFader`` class.
2326

2427
Dependencies
2528
=============
@@ -31,35 +34,7 @@ Please ensure all dependencies are available on the CircuitPython filesystem.
3134
This is easily achieved by downloading
3235
`the Adafruit library and driver bundle <https://circuitpython.org/libraries>`_
3336
or individual libraries can be installed using
34-
`circup <https://github.com/adafruit/circup>`_.Installing from PyPI
35-
=====================
36-
.. note:: This library is not available on PyPI yet. Install documentation is included
37-
as a standard element. Stay tuned for PyPI availability!
38-
39-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
40-
41-
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
42-
PyPI <https://pypi.org/project/Cedargrove-circuitpython-colorfader/>`_.
43-
To install for current user:
44-
45-
.. code-block:: shell
46-
47-
pip3 install Cedargrove-circuitpython-colorfader
48-
49-
To install system-wide (this may be required in some cases):
50-
51-
.. code-block:: shell
52-
53-
sudo pip3 install Cedargrove-circuitpython-colorfader
54-
55-
To install in a virtual environment in your current project:
56-
57-
.. code-block:: shell
58-
59-
mkdir project-name && cd project-name
60-
python3 -m venv .venv
61-
source .env/bin/activate
62-
pip3 install Cedargrove-circuitpython-colorfader
37+
`circup <https://github.com/adafruit/circup>`_.
6338

6439
Installing to a Connected CircuitPython Device with Circup
6540
==========================================================
@@ -76,7 +51,7 @@ following command to install:
7651

7752
.. code-block:: shell
7853
79-
circup install colorfader
54+
circup install cedargrove_colorfader
8055
8156
Or the following command to update an existing version:
8257

@@ -87,12 +62,22 @@ Or the following command to update an existing version:
8762
Usage Example
8863
=============
8964

90-
.. todo:: Add a quick, simple example. It and other examples should live in the
91-
examples folder and be included in docs/examples.rst.
65+
Scale a 24-bit RGB source color value in proportion to the brightness setting
66+
(0 to 1.0). The adjusted color's gamma value is typically from 0.0 to 2.0 with
67+
a default of 1.0 for no gamma adjustment. Returns an adjusted 24-bit RGB color
68+
value or None if the source color is None (transparent).
69+
70+
.. code-block:: python
71+
72+
>>> from cedargrove_colorfader import color_fader
73+
>>> # Dim a pure red color to 50%; no gamma adjustment
74+
>>> print(hex(color_fader(source_color=0xFF0000, brightness=0.5, gamma=1.0)
75+
0x7f0000
76+
9277
9378
Documentation
9479
=============
95-
API documentation for this library can be found on `Read the Docs <https://circuitpython-colorfader.readthedocs.io/>`_.
80+
API documentation for this library can be found `here <https://circuitpython-colorfader.readthedocs.io/>`_.
9681
9782
For information on building library documentation, please check out
9883
`this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
@@ -101,5 +86,5 @@ Contributing
10186
============
10287
10388
Contributions are welcome! Please read our `Code of Conduct
104-
<https://github.com/CedarGroveStudios/Cedargrove_CircuitPython_ColorFader/blob/HEAD/CODE_OF_CONDUCT.md>`_
89+
<https://github.com/CedarGroveStudios/CircuitPython_ColorFader/blob/HEAD/CODE_OF_CONDUCT.md>`_
10590
before contributing to help this project stay welcoming.

cedargrove_colorfader.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,41 @@
1616
1717
**Hardware:**
1818
19-
.. todo:: Add links to any specific hardware product page(s), or category page(s).
20-
Use unordered list & hyperlink rST inline format: "* `Link Text <url>`_"
21-
2219
**Software and Dependencies:**
2320
2421
* Adafruit CircuitPython firmware for the supported boards:
2522
https://circuitpython.org/downloads
23+
"""
2624

27-
.. todo:: Uncomment or remove the Bus Device and/or the Register library dependencies
28-
based on the library's use of either.
25+
__version__ = "0.0.0+auto.0"
26+
__repo__ = "https://github.com/CedarGroveStudios/CircuitPython_ColorFader.git"
2927

30-
# * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
31-
# * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
32-
"""
3328

34-
# imports
29+
def color_fader(source_color=None, brightness=1.0, gamma=1.0):
30+
"""Scale a 24-bit RGB source color value in proportion to the brightness
31+
setting (0 to 1.0). Returns an adjusted 24-bit RGB color value or None if
32+
the source color is None (transparent). The adjusted color's gamma value is
33+
typically from 0.0 to 2.0 with a default of 1.0 for no gamma adjustment.
3534
36-
__version__ = "0.0.0+auto.0"
37-
__repo__ = "https://github.com/CedarGroveStudios/Cedargrove_CircuitPython_ColorFader.git"
35+
:param int source_color: The color value to be adjusted. Default is None.
36+
:param float brightness: The brightness value for color value adjustment.
37+
Value range is 0.0 to 1.0. Default is 1.0 (maximum brightness).
38+
:param float gamma: The gamma value for color value adjustment. Value range
39+
is 0.0 to 2.0. Default is 1.0 (no gamma adjustment).
40+
41+
:return int: The adjusted color value."""
42+
43+
if source_color is None:
44+
return source_color
45+
46+
# Extract primary colors and scale to brightness
47+
r = min(int(brightness * ((source_color & 0xFF0000) >> 16)), 0xFF)
48+
g = min(int(brightness * ((source_color & 0x00FF00) >> 8)), 0xFF)
49+
b = min(int(brightness * ((source_color & 0x0000FF) >> 0)), 0xFF)
50+
51+
# Adjust result for gamma
52+
r = min(int(round((r**gamma), 0)), 0xFF)
53+
g = min(int(round((g**gamma), 0)), 0xFF)
54+
b = min(int(round((b**gamma), 0)), 0xFF)
55+
56+
return (r << 16) + (g << 8) + b

examples/colorfader_simpletest.py

Lines changed: 0 additions & 4 deletions
This file was deleted.
66.8 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: CedarGroveStudios
2+
3+
SPDX-License-Identifier: Unlicense

0 commit comments

Comments
 (0)