Skip to content

Ran pre-commit, added licenses #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

*.mpy
.idea
__pycache__
Expand All @@ -8,4 +12,4 @@ bundles
*.DS_Store
.eggs
dist
**/*.egg-info
**/*.egg-info
4 changes: 4 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

[MASTER]

# A comma-separated list of package or module names from where C extensions may
Expand Down
4 changes: 4 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

python:
version: 3
requirements_file: requirements.txt
14 changes: 10 additions & 4 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
SPDX-FileCopyrightText: 2014 Coraline Ada Ehmke
SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries
SPDX-License-Identifier: CC-BY-4.0
-->

# Adafruit Community Code of Conduct

## Our Pledge
Expand Down Expand Up @@ -43,7 +49,7 @@ Examples of unacceptable behavior by participants include:

The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you don’t just aim to be
"technically unimpeachable", but rather try to be your best self.
"technically unimpeachable", but rather try to be your best self.

We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
Expand Down Expand Up @@ -74,9 +80,9 @@ You may report in the following ways:
In any situation, you may send an email to <[email protected]>.

On the Adafruit Discord, you may send an open message from any channel
to all Community Moderators by tagging @community moderators. You may
also send an open message from any channel, or a direct message to
@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442,
to all Community Moderators by tagging @community moderators. You may
also send an open message from any channel, or a direct message to
@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442,
@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175.

Email and direct message reports will be kept confidential.
Expand Down
324 changes: 324 additions & 0 deletions LICENSES/CC-BY-4.0.txt

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions LICENSES/MIT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 changes: 20 additions & 0 deletions LICENSES/Unlicense.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute
this software, either in source code form or as a compiled binary, for any
purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and
to the detriment of our heirs and successors. We intend this dedication to
be an overt act of relinquishment in perpetuity of all present and future
rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information,
please refer to <https://unlicense.org/>
3 changes: 3 additions & 0 deletions README.rst.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries

SPDX-License-Identifier: MIT
158 changes: 70 additions & 88 deletions adafruit_fancyled/adafruit_fancyled.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
# The MIT License (MIT)
# SPDX-FileCopyrightText: 2017 PaintYourDragon for Adafruit Industries
#
# Copyright (c) 2017 PaintYourDragon for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# SPDX-License-Identifier: MIT

"""
`adafruit_fancyled.adafruit_fancyled`
====================================================
Expand Down Expand Up @@ -48,19 +31,19 @@
class CRGB:
"""Color stored in Red, Green, Blue color space.

One of two ways: separate red, gren, blue values (either as integers
(0 to 255 range) or floats (0.0 to 1.0 range), either type is
'clamped' to valid range and stored internally in the normalized
(float) format), OR can accept a CHSV color as input, which will be
converted and stored in RGB format.
One of two ways: separate red, gren, blue values (either as integers
(0 to 255 range) or floats (0.0 to 1.0 range), either type is
'clamped' to valid range and stored internally in the normalized
(float) format), OR can accept a CHSV color as input, which will be
converted and stored in RGB format.

Following statements are equivalent - all return red:
Following statements are equivalent - all return red:

.. code-block:: python
.. code-block:: python

c = CRGB(255, 0, 0)
c = CRGB(1.0, 0.0, 0.0)
c = CRGB(CHSV(0.0, 1.0, 1.0))
c = CRGB(255, 0, 0)
c = CRGB(1.0, 0.0, 0.0)
c = CRGB(CHSV(0.0, 1.0, 1.0))
"""

def __init__(self, red, green=0.0, blue=0.0):
Expand Down Expand Up @@ -131,7 +114,7 @@ def __getitem__(self, key):
def pack(self):
"""'Pack' a `CRGB` color into a 24-bit RGB integer.

:returns: 24-bit integer a la ``0x00RRGGBB``.
:returns: 24-bit integer a la ``0x00RRGGBB``.
"""

return (
Expand All @@ -144,21 +127,21 @@ def pack(self):
class CHSV:
"""Color stored in Hue, Saturation, Value color space.

Accepts hue as float (any range) or integer (0-256 -> 0.0-1.0) with
no clamping performed (hue can 'wrap around'), saturation and value
as float (0.0 to 1.0) or integer (0 to 255), both are clamped and
stored internally in the normalized (float) format. Latter two are
optional, can pass juse hue and saturation/value will default to 1.0.
Accepts hue as float (any range) or integer (0-256 -> 0.0-1.0) with
no clamping performed (hue can 'wrap around'), saturation and value
as float (0.0 to 1.0) or integer (0 to 255), both are clamped and
stored internally in the normalized (float) format. Latter two are
optional, can pass juse hue and saturation/value will default to 1.0.

Unlike `CRGB` (which can take a `CHSV` as input), there's currently
no equivalent RGB-to-HSV conversion, mostly because it's a bit like
trying to reverse a hash...there may be multiple HSV solutions for a
given RGB input.
Unlike `CRGB` (which can take a `CHSV` as input), there's currently
no equivalent RGB-to-HSV conversion, mostly because it's a bit like
trying to reverse a hash...there may be multiple HSV solutions for a
given RGB input.

This might be OK as long as conversion precedence is documented,
but otherwise (and maybe still) could cause confusion as certain
HSV->RGB->HSV translations won't have the same input and output.
"""
This might be OK as long as conversion precedence is documented,
but otherwise (and maybe still) could cause confusion as certain
HSV->RGB->HSV translations won't have the same input and output.
"""

def __init__(self, h, s=1.0, v=1.0):
if isinstance(h, float):
Expand Down Expand Up @@ -197,28 +180,27 @@ def __getitem__(self, key):
def pack(self):
"""'Pack' a `CHSV` color into a 24-bit RGB integer.

:returns: 24-bit integer a la ``0x00RRGGBB``.
:returns: 24-bit integer a la ``0x00RRGGBB``.
"""

# Convert CHSV to CRGB, return packed result
return CRGB(self).pack()


def clamp(val, lower, upper):
"""Constrain value within a numeric range (inclusive).
"""
"""Constrain value within a numeric range (inclusive)."""
return max(lower, min(val, upper))


def normalize(val, inplace=False):
"""Convert 8-bit (0 to 255) value to normalized (0.0 to 1.0) value.

Accepts integer, 0 to 255 range (input is clamped) or a list or tuple
of integers. In list case, 'inplace' can be used to control whether
the original list is modified (True) or a new list is generated and
returned (False).
Accepts integer, 0 to 255 range (input is clamped) or a list or tuple
of integers. In list case, 'inplace' can be used to control whether
the original list is modified (True) or a new list is generated and
returned (False).

Returns float, 0.0 to 1.0 range, or list of floats (or None if inplace).
Returns float, 0.0 to 1.0 range, or list of floats (or None if inplace).
"""

if isinstance(val, int):
Expand All @@ -239,12 +221,12 @@ def normalize(val, inplace=False):
def denormalize(val, inplace=False):
"""Convert normalized (0.0 to 1.0) value to 8-bit (0 to 255) value

Accepts float, 0.0 to 1.0 range or a list or tuple of floats. In
list case, 'inplace' can be used to control whether the original list
is modified (True) or a new list is generated and returned (False).
Accepts float, 0.0 to 1.0 range or a list or tuple of floats. In
list case, 'inplace' can be used to control whether the original list
is modified (True) or a new list is generated and returned (False).

Returns integer, 0 to 255 range, or list of integers (or None if
inplace).
Returns integer, 0 to 255 range, or list of integers (or None if
inplace).
"""

# 'Denormalizing' math varies slightly from normalize(). This is on
Expand All @@ -269,9 +251,9 @@ def denormalize(val, inplace=False):
def unpack(val):
"""'Unpack' a 24-bit color into a `CRGB` instance.

:param int val: 24-bit integer a la ``0x00RRGGBB``.
:returns: CRGB color.
:rtype: CRGB
:param int val: 24-bit integer a la ``0x00RRGGBB``.
:returns: CRGB color.
:rtype: CRGB
"""

# See notes in normalize() for math explanation. Large constants here
Expand All @@ -286,10 +268,10 @@ def unpack(val):

def mix(color1, color2, weight2=0.5):
"""Blend between two colors using given ratio. Accepts two colors (each
may be `CRGB`, `CHSV` or packed integer), and weighting (0.0 to 1.0)
of second color.
may be `CRGB`, `CHSV` or packed integer), and weighting (0.0 to 1.0)
of second color.

:returns: `CRGB` color in most cases, `CHSV` if both inputs are `CHSV`.
:returns: `CRGB` color in most cases, `CHSV` if both inputs are `CHSV`.
"""

clamp(weight2, 0.0, 1.0)
Expand Down Expand Up @@ -337,31 +319,31 @@ def mix(color1, color2, weight2=0.5):

def gamma_adjust(val, gamma_value=None, brightness=1.0, inplace=False):
"""Provides gamma adjustment for single values, `CRGB` and `CHSV` types
and lists of any of these.

Works in one of three ways:
1. Accepts a single normalized level (0.0 to 1.0) and optional
gamma-adjustment factor (float usu. > 1.0, default if
unspecified is GFACTOR) and brightness (float 0.0 to 1.0,
default is 1.0). Returns a single normalized gamma-corrected
brightness level (0.0 to 1.0).
2. Accepts a single `CRGB` or `CHSV` type, optional single gamma
factor OR a (R,G,B) gamma tuple (3 values usu. > 1.0), optional
single brightness factor OR a (R,G,B) brightness tuple. The
input tuples are RGB even when a `CHSV` color is passed. Returns
a normalized gamma-corrected `CRGB` type (NOT `CHSV`!).
3. Accept a list or tuple of normalized levels, `CRGB` or `CHSV`
types (and optional gamma and brightness levels or tuples
applied to all). Returns a list of gamma-corrected values or
`CRGB` types (NOT `CHSV`!).

In cases 2 and 3, if the input is a list (NOT a tuple!), the 'inplace'
flag determines whether a new tuple/list is calculated and returned,
or the existing value is modified in-place. By default this is
'False'. If you try to inplace-modify a tuple, an exception is raised.

In cases 2 and 3, there is NO return value if 'inplace' is True --
the original values are modified.
and lists of any of these.

Works in one of three ways:
1. Accepts a single normalized level (0.0 to 1.0) and optional
gamma-adjustment factor (float usu. > 1.0, default if
unspecified is GFACTOR) and brightness (float 0.0 to 1.0,
default is 1.0). Returns a single normalized gamma-corrected
brightness level (0.0 to 1.0).
2. Accepts a single `CRGB` or `CHSV` type, optional single gamma
factor OR a (R,G,B) gamma tuple (3 values usu. > 1.0), optional
single brightness factor OR a (R,G,B) brightness tuple. The
input tuples are RGB even when a `CHSV` color is passed. Returns
a normalized gamma-corrected `CRGB` type (NOT `CHSV`!).
3. Accept a list or tuple of normalized levels, `CRGB` or `CHSV`
types (and optional gamma and brightness levels or tuples
applied to all). Returns a list of gamma-corrected values or
`CRGB` types (NOT `CHSV`!).

In cases 2 and 3, if the input is a list (NOT a tuple!), the 'inplace'
flag determines whether a new tuple/list is calculated and returned,
or the existing value is modified in-place. By default this is
'False'. If you try to inplace-modify a tuple, an exception is raised.

In cases 2 and 3, there is NO return value if 'inplace' is True --
the original values are modified.
"""
# pylint: disable=too-many-branches

Expand Down
Loading