INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
Draw a between x0 y0 and x1 y1 in an RGB color. | def drawLine(self, x0, y0, x1, y1, color=None, colorFunc=None, aa=False):
"""
Draw a between x0, y0 and x1, y1 in an RGB color.
:param colorFunc: a function that takes an integer from x0 to x1 and
returns a color corresponding to that point
:param aa: if True, use Bresenham'... |
Draw line from point x0 y0 to x1 y1 using Bresenham s algorithm. | def bresenham_line(self, x0, y0, x1, y1, color=None, colorFunc=None):
"""
Draw line from point x0, y0 to x1, y1 using Bresenham's algorithm.
Will draw beyond matrix bounds.
"""
md.bresenham_line(self.set, x0, y0, x1, y1, color, colorFunc) |
Draw rectangle with top - left corner at x y width w and height h | def drawRect(self, x, y, w, h, color=None, aa=False):
"""
Draw rectangle with top-left corner at x,y, width w and height h
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.draw_rect(self.set, x, y, w, h, colo... |
Draw a solid rectangle with top - left corner at ( x y ) width w and height h. | def fillRect(self, x, y, w, h, color=None, aa=False):
"""
Draw a solid rectangle with top-left corner at (x, y), width w and
height h.
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.fill_rect(self.s... |
Fill the matrix with the given RGB color | def fillScreen(self, color=None):
"""Fill the matrix with the given RGB color"""
md.fill_rect(self.set, 0, 0, self.width, self.height, color) |
Draw a rounded rectangle with top - left corner at ( x y ) width w height h and corner radius r | def drawRoundRect(self, x, y, w, h, r, color=None, aa=False):
"""
Draw a rounded rectangle with top-left corner at (x, y), width w,
height h, and corner radius r
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
... |
Draw a rounded rectangle with top - left corner at ( x y ) width w height h and corner radius r | def fillRoundRect(self, x, y, w, h, r, color=None, aa=False):
"""
Draw a rounded rectangle with top-left corner at (x, y), width w,
height h, and corner radius r
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
... |
Draw triangle with vertices ( x0 y0 ) ( x1 y1 ) and ( x2 y2 ) | def drawTriangle(self, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""
Draw triangle with vertices (x0, y0), (x1, y1) and (x2, y2)
:param aa: if True, use Bresenham's algorithm for line drawing;
Otherwise use Xiaolin Wu's algorithm
"""
md.draw_triangle(self.set, x... |
Draw filled triangle with points x0 y0 - x1 y1 - x2 y2 | def fillTriangle(self, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""
Draw filled triangle with points x0,y0 - x1,y1 - x2,y2
:param aa: if True, use Bresenham's algorithm for line drawing;
otherwise use Xiaolin Wu's algorithm
"""
md.fill_triangle(self.set, x0, y0... |
Draw a single character c at at ( x y ) in an RGB color. | def drawChar(self, x, y, c, color, bg,
aa=False, font=font.default_font, font_scale=1):
"""
Draw a single character c at at (x, y) in an RGB color.
"""
md.draw_char(self.fonts, self.set, self.width, self.height,
x, y, c, color, bg, aa, font, font_sca... |
Draw a line of text starting at ( x y ) in an RGB color. | def drawText(self, text, x=0, y=0, color=None,
bg=colors.COLORS.Off, aa=False, font=font.default_font,
font_scale=1):
"""
Draw a line of text starting at (x, y) in an RGB color.
:param colorFunc: a function that takes an integer from x0 to x1 and
re... |
Set the base project for routing. | def set_project(self, project):
"""Set the base project for routing."""
def visit(x):
# Try to set_project, then recurse through any values()
set_project = getattr(x, 'set_project', None)
if set_project:
set_project(project)
values = getatt... |
Returns a ( receiver msg ) pair where receiver is None if no route for the message was found or otherwise an object with a receive method that can accept that msg. | def receive(self, msg):
"""
Returns a (receiver, msg) pair, where receiver is `None` if no route for
the message was found, or otherwise an object with a `receive` method
that can accept that `msg`.
"""
x = self.routing
while not isinstance(x, ActionList):
... |
Set pixel to RGB color tuple | def set(self, ring, angle, color):
"""Set pixel to RGB color tuple"""
pixel = self.angleToPixel(angle, ring)
self._set_base(pixel, color) |
Get RGB color tuple of color at index pixel | def get(self, ring, angle):
"""Get RGB color tuple of color at index pixel"""
pixel = self.angleToPixel(angle, ring)
return self._get_base(pixel) |
Create input output queues call function in a subprocess or a thread. | def run(function, *args, use_subprocess=False, daemon=True, **kwds):
"""
Create input, output queues, call `function` in a subprocess or a thread.
``function`` is called like this: ``function(input, output, *args, **kwds)``
:param use_subprocess: if true, create a new multiprocess;
... |
Scale RGB tuple by level 0 - 256 | def color_scale(color, level):
"""
Scale RGB tuple by level, 0 - 256
"""
return tuple([int(i * level) >> 8 for i in list(color)]) |
Load/ reload the description from a YML file. Prompt if no file given. | def load(self, project_file=''):
"""Load/reload the description from a YML file. Prompt if no file given."""
self._request_project_file(project_file)
self.clear()
self.desc.update(data_file.load(self._project_file)) |
Save the description as a YML file. Prompt if no file given. | def save(self, project_file=''):
"""Save the description as a YML file. Prompt if no file given."""
self._request_project_file(project_file)
data_file.dump(self.desc.as_dict(), self.project_file) |
Return a color interpolated from the Palette. | def get(self, position=0):
"""
Return a color interpolated from the Palette.
In the case where continuous=False, serpentine=False, scale=1,
autoscale=False, and offset=0, this is exactly the same as plain old []
indexing, but with a wrap-around.
The constructor paramete... |
Wait for the event run the task trigger the next task. | def run(self, next_task):
"""Wait for the event, run the task, trigger the next task."""
self.event.wait()
self.task()
self.event.clear()
next_task.event.set() |
Run a function catch report and discard exceptions | def report(function, *args, **kwds):
"""Run a function, catch, report and discard exceptions"""
try:
function(*args, **kwds)
except Exception:
traceback.print_exc() |
Receive a message from the input source and perhaps raise an Exception. | def _receive(self, msg):
"""
Receive a message from the input source and perhaps raise an Exception.
"""
msg = self._convert(msg)
if msg is None:
return
str_msg = self.verbose and self._msg_to_str(msg)
if self.verbose and log.is_debug():
l... |
APA102 & SK9822 support on - chip brightness control allowing greater color depth. | def set_device_brightness(self, val):
"""
APA102 & SK9822 support on-chip brightness control, allowing greater
color depth.
APA102 superimposes a 440Hz PWM on the 19kHz base PWM to control
brightness. SK9822 uses a base 4.7kHz PWM but controls brightness with a
variable ... |
Comprehensively adds a new logging level to the logging module and the currently configured logging class. | def _addLoggingLevel(levelName, levelNum, methodName=None):
"""
Comprehensively adds a new logging level to the `logging` module and the
currently configured logging class.
`levelName` becomes an attribute of the `logging` module with the value
`levelNum`. `methodName` becomes a convenience method ... |
: param level: the level to set - either a string level name from frame debug info warning error or an integer log level from: log. FRAME log. DEBUG log. INFO log. WARNING log. ERROR | def set_log_level(level):
"""
:param level: the level to set - either a string level name from
'frame', 'debug', 'info', 'warning', 'error'
or an integer log level from:
log.FRAME, log.DEBUG, log.INFO, log.WARNING, log.ERROR
"""
if isinstance(level, ... |
Construct a layout. SHOULD BE PRIVATE | def construct(cls, project, **desc):
"""Construct a layout.
SHOULD BE PRIVATE
"""
return cls(project.drivers, maker=project.maker, **desc) |
Return an independent copy of this layout with a completely separate color_list and no drivers. | def clone(self):
"""
Return an independent copy of this layout with a completely separate
color_list and no drivers.
"""
args = {k: getattr(self, k) for k in self.CLONE_ATTRS}
args['color_list'] = copy.copy(self.color_list)
return self.__class__([], **args) |
Set the internal colors starting at an optional offset. | def set_color_list(self, color_list, offset=0):
"""
Set the internal colors starting at an optional offset.
If `color_list` is a list or other 1-dimensional array, it is reshaped
into an N x 3 list.
If `color_list` too long it is truncated; if it is too short then only
... |
Set single pixel using individual RGB values instead of tuple | def setRGB(self, pixel, r, g, b):
"""Set single pixel using individual RGB values instead of tuple"""
self._set_base(pixel, (r, g, b)) |
Set single pixel to HSV tuple | def setHSV(self, pixel, hsv):
"""Set single pixel to HSV tuple"""
color = conversions.hsv2rgb(hsv)
self._set_base(pixel, color) |
Fill the entire strip with RGB color tuple | def fill(self, color, start=0, end=-1):
"""Fill the entire strip with RGB color tuple"""
start = max(start, 0)
if end < 0 or end >= self.numLEDs:
end = self.numLEDs - 1
for led in range(start, end + 1): # since 0-index include end in range
self._set_base(led, col... |
Fill entire strip by giving individual RGB values instead of tuple | def fillRGB(self, r, g, b, start=0, end=-1):
"""Fill entire strip by giving individual RGB values instead of tuple"""
self.fill((r, g, b), start, end) |
Fill the entire strip with HSV color tuple | def fillHSV(self, hsv, start=0, end=-1):
"""Fill the entire strip with HSV color tuple"""
self.fill(conversions.hsv2rgb(hsv), start, end) |
DEPRECATED: use self. color_list | def set_colors(self, buf):
"""
DEPRECATED: use self.color_list
Use with extreme caution!
Directly sets the internal buffer and bypasses all brightness and
rotation control buf must also be in the exact format required by the
display type.
"""
deprecated.d... |
Hardware specific method to set the global brightness for this driver s output. This method is required to be implemented however users should call: py: meth:. driver_base. DriverBase. set_brightness instead of calling this method directly. | def set_device_brightness(self, brightness):
"""Hardware specific method to set the global brightness for
this driver's output. This method is required to be implemented,
however, users should call
:py:meth:`.driver_base.DriverBase.set_brightness`
instead of calling this method d... |
Helper for wheel_color that distributes colors over length and allows shifting position. | def wheel_helper(pos, length, cycle_step):
"""Helper for wheel_color that distributes colors over length and
allows shifting position."""
return wheel_color((pos * len(_WHEEL) / length) + cycle_step) |
Decorator for RestServer methods that take a single address | def single(method):
"""Decorator for RestServer methods that take a single address"""
@functools.wraps(method)
def single(self, address, value=None):
address = urllib.parse.unquote_plus(address)
try:
error = NO_PROJECT_ERROR
if not self.project:
raise ... |
Decorator for RestServer methods that take multiple addresses | def multi(method):
"""Decorator for RestServer methods that take multiple addresses"""
@functools.wraps(method)
def multi(self, address=''):
values = flask.request.values
address = urllib.parse.unquote_plus(address)
if address and values and not address.endswith('.'):
add... |
Advance a list of unique ordered elements in - place lexicographically increasing or backward by rightmost or leftmost digit. | def advance_permutation(a, increasing=True, forward=True):
"""
Advance a list of unique, ordered elements in-place, lexicographically
increasing or backward, by rightmost or leftmost digit.
Returns False if the permutation wrapped around - i.e. went from
lexicographically greatest to least, and Tru... |
Override this method to get called right after self. index is set. | def _on_index(self, old_index):
"""
Override this method to get called right after ``self.index`` is set.
:param int old_index: the previous index, before it was changed.
"""
if self.animation:
log.debug('%s: %s',
self.__class__.__name__, self.c... |
: returns: the selected animation based on self. index or None if self. index is out of bounds | def animation(self):
"""
:returns: the selected animation based on self.index, or None if
self.index is out of bounds
"""
if 0 <= self._index < len(self.animations):
return self.animations[self._index] |
For each row or column in cuts read a list of its colors apply the function to that list of colors then write it back to the layout. | def apply(self, function):
"""
For each row or column in cuts, read a list of its colors,
apply the function to that list of colors, then write it back
to the layout.
"""
for cut in self.cuts:
value = self.read(cut)
function(value)
self... |
Set single pixel using individual RGB values instead of tuple | def setRGB(self, pixel, r, g, b):
"""Set single pixel using individual RGB values instead of tuple"""
self.set(pixel, (r, g, b)) |
Set single pixel to HSV tuple | def setHSV(self, pixel, hsv):
"""Set single pixel to HSV tuple"""
color = conversions.hsv2rgb(hsv)
self.set(pixel, color) |
Compose a sequence of events into one event. | def compose_events(events, condition=all):
"""
Compose a sequence of events into one event.
Arguments:
events: a sequence of objects looking like threading.Event
condition: a function taking a sequence of bools and returning a bool.
"""
events = list(events)
master_event = th... |
These arguments are redundant with just using a project and we should encouraging that as you don t have to learn any dumb flags! | def _add_redundant_arguments(parser):
"""
These arguments are redundant with just using a project, and we should
encouraging that as you don't have to learn any dumb flags!
For example, instead of
bp foo.yml --animation=wombat --numbers=float
use
bp foo.yml + '{animation: wombat, n... |
Draws a circle at point x0 y0 with radius r of the specified RGB color | def draw_circle(setter, x0, y0, r, color=None):
"""
Draws a circle at point x0, y0 with radius r of the specified RGB color
"""
f = 1 - r
ddF_x = 1
ddF_y = -2 * r
x = 0
y = r
setter(x0, y0 + r, color)
setter(x0, y0 - r, color)
setter(x0 + r, y0, color)
setter(x0 - r, y0,... |
Draws a filled circle at point x0 y0 with radius r and specified color | def fill_circle(setter, x0, y0, r, color=None):
"""Draws a filled circle at point x0,y0 with radius r and specified color"""
_draw_fast_vline(setter, x0, y0 - r, 2 * r + 1, color)
_fill_circle_helper(setter, x0, y0, r, 3, 0, color) |
Draw line from point x0 y0 to x 1 y1. Will draw beyond matrix bounds. | def bresenham_line(setter, x0, y0, x1, y1, color=None, colorFunc=None):
"""Draw line from point x0,y0 to x,1,y1. Will draw beyond matrix bounds."""
steep = abs(y1 - y0) > abs(x1 - x0)
if steep:
x0, y0 = y0, x0
x1, y1 = y1, x1
if x0 > x1:
x0, x1 = x1, x0
y0, y1 = y1, y0
... |
Draw rectangle with top - left corner at x y width w and height h | def draw_rect(setter, x, y, w, h, color=None, aa=False):
"""Draw rectangle with top-left corner at x,y, width w and height h"""
_draw_fast_hline(setter, x, y, w, color, aa)
_draw_fast_hline(setter, x, y + h - 1, w, color, aa)
_draw_fast_vline(setter, x, y, h, color, aa)
_draw_fast_vline(setter, x + ... |
Draw solid rectangle with top - left corner at x y width w and height h | def fill_rect(setter, x, y, w, h, color=None, aa=False):
"""Draw solid rectangle with top-left corner at x,y, width w and height h"""
for i in range(x, x + w):
_draw_fast_vline(setter, i, y, h, color, aa) |
Draw rectangle with top - left corner at x y width w height h and corner radius r. | def draw_round_rect(setter, x, y, w, h, r, color=None, aa=False):
"""Draw rectangle with top-left corner at x,y, width w, height h,
and corner radius r.
"""
_draw_fast_hline(setter, x + r, y, w - 2 * r, color, aa) # Top
_draw_fast_hline(setter, x + r, y + h - 1, w - 2 * r, color, aa) # Bottom
... |
Draw solid rectangle with top - left corner at x y width w height h and corner radius r | def fill_round_rect(setter, x, y, w, h, r, color=None, aa=False):
"""Draw solid rectangle with top-left corner at x,y, width w, height h,
and corner radius r"""
fill_rect(setter, x + r, y, w - 2 * r, h, color, aa)
_fill_circle_helper(setter, x + w - r - 1, y + r, r,
1, h - 2 * r ... |
Draw triangle with points x0 y0 - x1 y1 - x2 y2 | def draw_triangle(setter, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""Draw triangle with points x0,y0 - x1,y1 - x2,y2"""
draw_line(setter, x0, y0, x1, y1, color, aa)
draw_line(setter, x1, y1, x2, y2, color, aa)
draw_line(setter, x2, y2, x0, y0, color, aa) |
Draw solid triangle with points x0 y0 - x1 y1 - x2 y2 | def fill_triangle(setter, x0, y0, x1, y1, x2, y2, color=None, aa=False):
"""Draw solid triangle with points x0,y0 - x1,y1 - x2,y2"""
a = b = y = last = 0
if y0 > y1:
y0, y1 = y1, y0
x0, x1 = x1, x0
if y1 > y2:
y2, y1 = y1, y2
x2, x1 = x1, x2
if y0 > y1:
y0, y... |
Use with caution! | def set_colors(self, colors, pos):
"""
Use with caution!
Directly set the pixel buffers.
:param colors: A list of color tuples
:param int pos: Position in color list to begin set operation.
"""
self._colors = colors
self._pos = pos
end = self._p... |
Apply any corrections to the current color list and send the results to the driver output. This function primarily provided as a wrapper for each driver s implementation of: py: func: _compute_packet and: py: func: _send_packet. | def update_colors(self):
"""Apply any corrections to the current color list
and send the results to the driver output. This function primarily
provided as a wrapper for each driver's implementation of
:py:func:`_compute_packet` and :py:func:`_send_packet`.
"""
start = sel... |
Typically called from: py: func: _compute_packet this applies brightness and gamma correction to the pixels controlled by this driver. | def _render(self):
"""Typically called from :py:func:`_compute_packet` this applies
brightness and gamma correction to the pixels controlled by this
driver.
"""
if self.set_device_brightness:
level = 1.0
else:
level = self._brightness / 255.0
... |
Calculates the coordinates of a point on a circle given the center point radius and angle. | def pointOnCircle(cx, cy, radius, angle):
"""
Calculates the coordinates of a point on a circle given the center point,
radius, and angle.
"""
angle = math.radians(angle) - (math.pi / 2)
x = cx + radius * math.cos(angle)
if x < cx:
x = math.ceil(x)
else:
x = math.floor(x)... |
Generates a map of vector lengths from the center point to each coordinate. | def genVector(width, height, x_mult=1, y_mult=1):
"""
Generates a map of vector lengths from the center point to each coordinate.
width - width of matrix to generate
height - height of matrix to generate
x_mult - value to scale x-axis by
y_mult - value to scale y-axis by
"""
center_x = ... |
Return an iteration over all name color pairs in tables | def all_named_colors():
"""Return an iteration over all name, color pairs in tables"""
yield from _TO_COLOR_USER.items()
for name, color in _TO_COLOR.items():
if name not in _TO_COLOR_USER:
yield name, color |
Return true if this string or integer tuple appears in tables | def contains(x):
"""Return true if this string or integer tuple appears in tables"""
if isinstance(x, str):
x = canonical_name(x)
return x in _TO_COLOR_USER or x in _TO_COLOR
else:
x = tuple(x)
return x in _TO_NAME_USER or x in _TO_NAME |
Return a list of Segments that evenly split the strip. | def make_segments(strip, length):
"""Return a list of Segments that evenly split the strip."""
if len(strip) % length:
raise ValueError('The length of strip must be a multiple of length')
s = []
try:
while True:
s.append(s[-1].next(length) if s else Segment(strip, length))
... |
Return a new segment starting right after self in the same buffer. | def next(self, length):
"""Return a new segment starting right after self in the same buffer."""
return Segment(self.strip, length, self.offset + self.length) |
: param str address: a pair ( ip_address port ) to pass to socket. connect: param bool use_queue: if True run the connection in a different thread with a queue | def sender(address, use_queue=True, **kwds):
"""
:param str address: a pair (ip_address, port) to pass to socket.connect
:param bool use_queue: if True, run the connection in a different thread
with a queue
"""
return QueuedSender(address, **kwds) if use_queue else Sender(address) |
Creates and starts the project. | def start(self, threaded=None):
"""Creates and starts the project."""
if threaded is not None:
self.threaded = threaded
run = {'run': {'threaded': False}}
self.project = project.project(
self.desc, run, root_file=self.project_file)
self._run = self.project... |
Stop the builder if it s running. | def stop(self=None):
"""Stop the builder if it's running."""
if not self:
instance = getattr(Runner.instance(), 'builder', None)
self = instance and instance()
if not self:
return
self._runner.stop()
if self.project:
self.p... |
Open an instance of simpixel in the browser | def simpixel(new=0, autoraise=True):
"""Open an instance of simpixel in the browser"""
simpixel_driver.open_browser(new=new, autoraise=autoraise) |
Depth first recursion through a dictionary containing type constructors | def recurse(desc, pre='pre_recursion', post=None, python_path=None):
"""
Depth first recursion through a dictionary containing type constructors
The arguments pre, post and children are independently either:
* None, which means to do nothing
* a string, which means to use the static class method o... |
: param c: either an object or a class: return: the classname as a string | def class_name(c):
"""
:param c: either an object or a class
:return: the classname as a string
"""
if not isinstance(c, type):
c = type(c)
return '%s.%s' % (c.__module__, c.__name__) |
Tries to convert a value to a type constructor. | def to_type_constructor(value, python_path=None):
""""
Tries to convert a value to a type constructor.
If value is a string, then it used as the "typename" field.
If the "typename" field exists, the symbol for that name is imported and
added to the type constructor as a field "datatype".
Thro... |
Fill a portion of a strip from start to stop by step with a given item. If stop is not given it defaults to the length of the strip. | def fill(strip, item, start=0, stop=None, step=1):
"""Fill a portion of a strip from start to stop by step with a given item.
If stop is not given, it defaults to the length of the strip.
"""
if stop is None:
stop = len(strip)
for i in range(start, stop, step):
strip[i] = item |
Older animations in BPA and other areas use all sorts of different names for what we are now representing with palettes. | def pop_legacy_palette(kwds, *color_defaults):
"""
Older animations in BPA and other areas use all sorts of different names for
what we are now representing with palettes.
This function mutates a kwds dictionary to remove these legacy fields and
extract a palette from it, which it returns.
"""
... |
Square of the euclidean distance | def euclidean(c1, c2):
"""Square of the euclidean distance"""
diffs = ((i - j) for i, j in zip(c1, c2))
return sum(x * x for x in diffs) |
Write a series of frames as a single animated GIF. | def _write(self, filename, frames, fps, loop=0, palette=256):
"""
Write a series of frames as a single animated GIF.
:param str filename: the name of the GIF file to write
:param list frames: a list of filenames, each of which represents a single
frame of the animation. Ea... |
Dumps data into a nicely formatted JSON string. | def dumps(data, use_yaml=None, safe=True, **kwds):
"""
Dumps data into a nicely formatted JSON string.
:param dict data: a dictionary to dump
:param kwds: keywords to pass to json.dumps
:returns: a string with formatted data
:rtype: str
"""
if use_yaml is None:
use_yaml = ALWAYS... |
Dumps data as nicely formatted JSON string to a file or file handle | def dump(data, file=sys.stdout, use_yaml=None, **kwds):
"""
Dumps data as nicely formatted JSON string to a file or file handle
:param dict data: a dictionary to dump
:param file: a filename or file handle to write to
:param kwds: keywords to pass to json.dump
"""
if use_yaml is None:
... |
Loads not only JSON files but also YAML files ending in. yml. | def load(file, use_yaml=None):
"""
Loads not only JSON files but also YAML files ending in .yml.
:param file: a filename or file handle to read from
:returns: the data loaded from the JSON or YAML file
:rtype: dict
"""
if isinstance(file, str):
fp = open(file)
filename = fil... |
Load either a filename or a string representation of yml/ json. | def load_if(s):
"""Load either a filename, or a string representation of yml/json."""
is_data_file = s.endswith('.json') or s.endswith('.yml')
return load(s) if is_data_file else loads(s) |
Adapt the setter in an animation s layout so that Strip animations can run on on Matrix Cube or Circle layout and Matrix or Cube animations can run on a Strip layout. | def adapt_animation_layout(animation):
"""
Adapt the setter in an animation's layout so that Strip animations can run
on on Matrix, Cube, or Circle layout, and Matrix or Cube animations can run
on a Strip layout.
"""
layout = animation.layout
required = getattr(animation, 'LAYOUT_CLASS', Non... |
Converts an HSV tuple to RGB. Intended for internal use. You should use hsv2rgb_spectrum or hsv2rgb_rainbow instead. | def hsv2rgb_raw(hsv):
"""
Converts an HSV tuple to RGB. Intended for internal use.
You should use hsv2rgb_spectrum or hsv2rgb_rainbow instead.
"""
HSV_SECTION_3 = 0x40
h, s, v = hsv
# The brightness floor is minimum number that all of
# R, G, and B will be set to.
invsat = 255 - s... |
Generates RGB values from HSV values in line with a typical light spectrum. | def hsv2rgb_spectrum(hsv):
"""Generates RGB values from HSV values in line with a typical light
spectrum."""
h, s, v = hsv
return hsv2rgb_raw(((h * 192) >> 8, s, v)) |
Generates RGB values from HSV that have an even visual distribution. Be careful as this method is only have as fast as hsv2rgb_spectrum. | def hsv2rgb_rainbow(hsv):
"""Generates RGB values from HSV that have an even visual
distribution. Be careful as this method is only have as fast as
hsv2rgb_spectrum."""
def nscale8x3_video(r, g, b, scale):
nonzeroscale = 0
if scale != 0:
nonzeroscale = 1
if r != 0:
... |
Python default hsv to rgb conversion for when hue values in the range 0 - 359 are preferred. Due to requiring float math this method is slower than hsv2rgb_rainbow and hsv2rgb_spectrum. | def hsv2rgb_360(hsv):
"""Python default hsv to rgb conversion for when hue values in the
range 0-359 are preferred. Due to requiring float math, this method
is slower than hsv2rgb_rainbow and hsv2rgb_spectrum."""
h, s, v = hsv
r, g, b = colorsys.hsv_to_rgb(h / 360.0, s, v)
return (int(r * 255... |
Order colors by hue saturation and value in that order. | def color_cmp(a, b):
"""Order colors by hue, saturation and value, in that order.
Returns -1 if a < b, 0 if a == b and 1 if a < b.
"""
if a == b:
return 0
a, b = rgb_to_hsv(a), rgb_to_hsv(b)
return -1 if a < b else 1 |
Get a new or existing server for this key. | def get_server(self, key, **kwds):
"""
Get a new or existing server for this key.
:param int key: key for the server to use
"""
kwds = dict(self.kwds, **kwds)
server = self.servers.get(key)
if server:
# Make sure it's the right server.
ser... |
Set one section in a Project description | def set_one(desc, name, value):
"""Set one section in a Project description"""
old_value = desc.get(name)
if old_value is None:
raise KeyError('No section "%s"' % name)
if value is None:
value = type(old_value)()
elif name in CLASS_SECTIONS:
if isinstance(value, str):
... |
Update sections in a Project description | def update(desc, other=None, **kwds):
"""Update sections in a Project description"""
other = other and _as_dict(other) or {}
for i in other, kwds:
for k, v in i.items():
if isinstance(v, dict):
# Only for dicts, merge instead of overwriting
old_v = desc[k]... |
: param str name: a string identifying a color. It might be a color name from the two lists of color names juce and classic ; or it might be a list of numeric r g b values separated by commas.: returns: a color as an RGB 3 - tuple | def name_to_color(name):
"""
:param str name: a string identifying a color. It might be a color name
from the two lists of color names, juce and classic; or
it might be a list of numeric r, g, b values separated by
commas.
:returns: a color as ... |
: param tuple color: an RGB 3 - tuple of integer colors: returns: a string name for this color | def color_to_name(color, use_hex=False):
"""
:param tuple color: an RGB 3-tuple of integer colors
:returns: a string name for this color
``name_to_color(color_to_name(c)) == c`` is guaranteed to be true (but the
reverse is not true, because name_to_color is a many-to-one function).
"""
if i... |
Toggle back and forth between a name and a tuple representation. | def toggle(s):
"""
Toggle back and forth between a name and a tuple representation.
:param str s: a string which is either a text name, or a tuple-string:
a string with three numbers separated by commas
:returns: if the string was a text name, return a tuple. If it's a
... |
Try to coerce the argument into a color - a 3 - tuple of numbers - | def to_color(c):
"""Try to coerce the argument into a color - a 3-tuple of numbers-"""
if isinstance(c, numbers.Number):
return c, c, c
if not c:
raise ValueError('Cannot create color from empty "%s"' % c)
if isinstance(c, str):
return name_to_color(c)
if isinstance(c, lis... |
This may seem silly but on a Receiver step () need not do anything. Instead receive the data on the receive thread and set it on the buffer then call self. _hold_for_data. set () | def step(self, amt=1):
"""
This may seem silly, but on a Receiver step() need not do anything.
Instead, receive the data on the receive thread and set it on the buffer
then call self._hold_for_data.set()
"""
if not self._stop_event.isSet():
self._hold_for_data... |
Construct an animation set the runner and add in the two reserved fields name and data. | def construct(cls, project, *, run=None, name=None, data=None, **desc):
"""
Construct an animation, set the runner, and add in the two
"reserved fields" `name` and `data`.
"""
from . failed import Failed
exception = desc.pop('_exception', None)
if exception:
... |
Return an image in the given mode. | def convert_mode(image, mode='RGB'):
"""Return an image in the given mode."""
deprecated.deprecated('util.gif.convert_model')
return image if (image.mode == mode) else image.convert(mode=mode) |
Given a PIL. Image returns a ColorList of its pixels. | def image_to_colorlist(image, container=list):
"""Given a PIL.Image, returns a ColorList of its pixels."""
deprecated.deprecated('util.gif.image_to_colorlist')
return container(convert_mode(image).getdata()) |
Given an animated GIF return a list with a colorlist for each frame. | def animated_gif_to_colorlists(image, container=list):
"""
Given an animated GIF, return a list with a colorlist for each frame.
"""
deprecated.deprecated('util.gif.animated_gif_to_colorlists')
from PIL import ImageSequence
it = ImageSequence.Iterator(image)
return [image_to_colorlist(i, c... |
Parse a string representing a time interval or duration into seconds or raise an exception | def parse(s):
"""
Parse a string representing a time interval or duration into seconds,
or raise an exception
:param str s: a string representation of a time interval
:raises ValueError: if ``s`` can't be interpreted as a duration
"""
parts = s.replace(',', ' ').split()
if not parts:
... |
Wait a little and then open a web browser page for the control panel. | def opener(ip_address, port, delay=1):
"""
Wait a little and then open a web browser page for the control panel.
"""
global WEBPAGE_OPENED
if WEBPAGE_OPENED:
return
WEBPAGE_OPENED = True
raw_opener(ip_address, port, delay) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.