_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q260000 | graph.add_node | validation | def add_node(self, id, radius=8, style=style.DEFAULT, category="", label=None, root=False,
properties={}):
""" Add node from id and return the node object.
"""
if self.has_key(id):
return self[id]
if not isinstance(style, str) ... | python | {
"resource": ""
} |
q260001 | graph.remove_node | validation | def remove_node(self, id):
""" Remove node with given id.
"""
if self.has_key(id):
n = self[id]
self.nodes.remove(n)
del self[id]
# Remove all edges involving id and all links to it.
for e in list(self.edges):
... | python | {
"resource": ""
} |
q260002 | graph.remove_edge | validation | def remove_edge(self, id1, id2):
""" Remove edges between nodes with given id's.
"""
for e in list(self.edges):
if id1 in (e.node1.id, e.node2.id) and \
id2 in (e.node1.id, e.node2.id):
e.node1.links.remove(e.node2)
e.n... | python | {
"resource": ""
} |
q260003 | graph.edge | validation | def edge(self, id1, id2):
""" Returns the edge between the nodes with given id1 and id2.
"""
if id1 in self and \
id2 in self and \
self[id2] in self[id1].links:
return self[id1].links.edge(id2)
return None | python | {
"resource": ""
} |
q260004 | graph.update | validation | def update(self, iterations=10):
""" Iterates the graph layout and updates node positions.
"""
# The graph fades in when initially constructed.
self.alpha += 0.05
self.alpha = min(self.alpha, 1.0)
# Iterates over the graph's layout.
# Each s... | python | {
"resource": ""
} |
q260005 | graph.offset | validation | def offset(self, node):
""" Returns the distance from the center to the given node.
"""
x = self.x + node.x - _ctx.WIDTH/2
y = self.y + node.y - _ctx.HEIGHT/2
return x, y | python | {
"resource": ""
} |
q260006 | graph.draw | validation | def draw(self, dx=0, dy=0, weighted=False, directed=False, highlight=[], traffic=None):
""" Layout the graph incrementally.
The graph is drawn at the center of the canvas.
The weighted and directed parameters visualize edge weight and direction.
The highlight specifies ... | python | {
"resource": ""
} |
q260007 | graph.prune | validation | def prune(self, depth=0):
""" Removes all nodes with less or equal links than depth.
"""
for n in list(self.nodes):
if len(n.links) <= depth:
self.remove_node(n.id) | python | {
"resource": ""
} |
q260008 | graph.betweenness_centrality | validation | def betweenness_centrality(self, normalized=True):
""" Calculates betweenness centrality and returns an node id -> weight dictionary.
Node betweenness weights are updated in the process.
"""
bc = proximity.brandes_betweenness_centrality(self, normalized)
for id, w in bc.iteritems... | python | {
"resource": ""
} |
q260009 | graph.eigenvector_centrality | validation | def eigenvector_centrality(self, normalized=True, reversed=True, rating={},
start=None, iterations=100, tolerance=0.0001):
""" Calculates eigenvector centrality and returns an node id -> weight dictionary.
Node eigenvalue weights are updated in the process.
"""
... | python | {
"resource": ""
} |
q260010 | graph.nodes_by_betweenness | validation | def nodes_by_betweenness(self, treshold=0.0):
""" Returns nodes sorted by betweenness centrality.
Nodes with a lot of passing traffic will be at the front of the list.
"""
nodes = [(n.betweenness, n) for n in self.nodes if n.betweenness > treshold]
nodes.sort(); nodes.reverse()
... | python | {
"resource": ""
} |
q260011 | graph.nodes_by_eigenvalue | validation | def nodes_by_eigenvalue(self, treshold=0.0):
""" Returns nodes sorted by eigenvector centrality.
Nodes with a lot of incoming traffic will be at the front of the list
"""
nodes = [(n.eigenvalue, n) for n in self.nodes if n.eigenvalue > treshold]
nodes.sort(); nodes.reverse()
... | python | {
"resource": ""
} |
q260012 | graph.nodes_by_category | validation | def nodes_by_category(self, category):
""" Returns nodes with the given category attribute.
"""
return [n for n in self.nodes if n.category == category] | python | {
"resource": ""
} |
q260013 | graph.crown | validation | def crown(self, depth=2):
""" Returns a list of leaves, nodes connected to leaves, etc.
"""
nodes = []
for node in self.leaves: nodes += node.flatten(depth-1)
return cluster.unique(nodes) | python | {
"resource": ""
} |
q260014 | graph._density | validation | def _density(self):
""" The number of edges in relation to the total number of possible edges.
"""
return 2.0*len(self.edges) / (len(self.nodes) * (len(self.nodes)-1)) | python | {
"resource": ""
} |
q260015 | xgraph.load | validation | def load(self, id):
""" Rebuilds the graph around the given node id.
"""
self.clear()
# Root node.
self.add_node(id, root=True)
# Directly connected nodes have priority.
for w, id2 in self.get_links(id):
self.add_edge(id, id... | python | {
"resource": ""
} |
q260016 | xgraph.click | validation | def click(self, node):
""" Callback from graph.events when a node is clicked.
"""
if not self.has_node(node.id): return
if node == self.root: return
self._dx, self._dy = self.offset(node)
self.previous = self.root.id
self.load(node.id) | python | {
"resource": ""
} |
q260017 | bezier_arc | validation | def bezier_arc(x1, y1, x2, y2, start_angle=0, extent=90):
""" Compute a cubic Bezier approximation of an elliptical arc.
(x1, y1) and (x2, y2) are the corners of the enclosing rectangle.
The coordinate system has coordinates that increase to the right and down.
Angles, measured in degress, start w... | python | {
"resource": ""
} |
q260018 | angle | validation | def angle(x1, y1, x2, y2):
""" The angle in degrees between two vectors.
"""
sign = 1.0
usign = (x1*y2 - y1*x2)
if usign < 0:
sign = -1.0
num = x1*x2 + y1*y2
den = hypot(x1,y1) * hypot(x2,y2)
ratio = min(max(num/den, -1.0), 1.0)
return sign * degrees(acos(ratio)) | python | {
"resource": ""
} |
q260019 | transform_from_local | validation | def transform_from_local(xp, yp, cphi, sphi, mx, my):
""" Transform from the local frame to absolute space.
"""
x = xp * cphi - yp * sphi + mx
y = xp * sphi + yp * cphi + my
return (x,y) | python | {
"resource": ""
} |
q260020 | Canvas.set_bot | validation | def set_bot(self, bot):
''' Bot must be set before running '''
self.bot = bot
self.sink.set_bot(bot) | python | {
"resource": ""
} |
q260021 | Canvas.settings | validation | def settings(self, **kwargs):
'''
Pass a load of settings into the canvas
'''
for k, v in kwargs.items():
setattr(self, k, v) | python | {
"resource": ""
} |
q260022 | Canvas.size_or_default | validation | def size_or_default(self):
'''
If size is not set, otherwise set size to DEFAULT_SIZE
and return it.
This means, only the first call to size() is valid.
'''
if not self.size:
self.size = self.DEFAULT_SIZE
return self.size | python | {
"resource": ""
} |
q260023 | Canvas.set_size | validation | def set_size(self, size):
'''
Size is only set the first time it is called
Size that is set is returned
'''
if self.size is None:
self.size = size
return size
else:
return self.size | python | {
"resource": ""
} |
q260024 | Canvas.snapshot | validation | def snapshot(self, target, defer=True, file_number=None):
'''
Ask the drawqueue to output to target.
target can be anything supported by the combination
of canvas implementation and drawqueue implmentation.
If target is not supported then an exception is thrown.
'''
... | python | {
"resource": ""
} |
q260025 | Canvas.flush | validation | def flush(self, frame):
'''
Passes the drawqueue to the sink for rendering
'''
self.sink.render(self.size_or_default(), frame, self._drawqueue)
self.reset_drawqueue() | python | {
"resource": ""
} |
q260026 | BezierPathEditor.overlap | validation | def overlap(self, x1, y1, x2, y2, r=5):
""" Returns True when point 1 and point 2 overlap.
There is an r treshold in which point 1 and point 2
are considered to overlap.
"""
if abs(x2-x1) < r and abs(y2-y1) < r:
return True
... | python | {
"resource": ""
} |
q260027 | BezierPathEditor.reflect | validation | def reflect(self, x0, y0, x, y):
""" Reflects the point x, y through origin x0, y0.
"""
rx = x0 - (x-x0)
ry = y0 - (y-y0)
return rx, ry | python | {
"resource": ""
} |
q260028 | BezierPathEditor.angle | validation | def angle(self, x0, y0, x1, y1):
""" Calculates the angle between two points.
"""
a = degrees( atan((y1-y0) / (x1-x0+0.00001)) ) + 360
if x1-x0 < 0: a += 180
return a | python | {
"resource": ""
} |
q260029 | BezierPathEditor.coordinates | validation | def coordinates(self, x0, y0, distance, angle):
""" Calculates the coordinates of a point from the origin.
"""
x = x0 + cos(radians(angle)) * distance
y = y0 + sin(radians(angle)) * distance
return Point(x, y) | python | {
"resource": ""
} |
q260030 | BezierPathEditor.contains_point | validation | def contains_point(self, x, y, d=2):
""" Returns true when x, y is on the path stroke outline.
"""
if self.path != None and len(self.path) > 1 \
and self.path.contains(x, y):
# If all points around the mouse are also part of the path,
# this mean... | python | {
"resource": ""
} |
q260031 | BezierPathEditor.insert_point | validation | def insert_point(self, x, y):
""" Inserts a point on the path at the mouse location.
We first need to check if the mouse location is on the path.
Inserting point is time intensive and experimental.
"""
try:
bezier = _ctx.ximport("b... | python | {
"resource": ""
} |
q260032 | BezierPathEditor.draw_freehand | validation | def draw_freehand(self):
""" Freehand sketching.
"""
if _ctx._ns["mousedown"]:
x, y = mouse()
if self.show_grid:
x, y = self.grid.snap(x, y)
if self.freehand_move == True:
cmd = MOVETO... | python | {
"resource": ""
} |
q260033 | BezierPathEditor.export_svg | validation | def export_svg(self):
""" Exports the path as SVG.
Uses the filename given when creating this object.
The file is automatically updated to reflect
changes to the path.
"""
d = ""
if len(self._points) > 0:
d += "M "+s... | python | {
"resource": ""
} |
q260034 | ShoebotWindow.gtk_mouse_button_down | validation | def gtk_mouse_button_down(self, widget, event):
''' Handle right mouse button clicks '''
if self.menu_enabled and event.button == 3:
menu = self.uimanager.get_widget('/Save as')
menu.popup(None, None, None, None, event.button, event.time)
else:
super(ShoebotWi... | python | {
"resource": ""
} |
q260035 | ShoebotWindow.show_variables_window | validation | def show_variables_window(self):
"""
Show the variables window.
"""
if self.var_window is None and self.bot._vars:
self.var_window = VarWindow(self, self.bot, '%s variables' % (self.title or 'Shoebot'))
self.var_window.window.connect("destroy", self.var_window_clo... | python | {
"resource": ""
} |
q260036 | ShoebotWindow.hide_variables_window | validation | def hide_variables_window(self):
"""
Hide the variables window
"""
if self.var_window is not None:
self.var_window.window.destroy()
self.var_window = None | python | {
"resource": ""
} |
q260037 | ShoebotWindow.trigger_fullscreen_action | validation | def trigger_fullscreen_action(self, fullscreen):
"""
Toggle fullscreen from outside the GUI,
causes the GUI to updated and run all its actions.
"""
action = self.action_group.get_action('fullscreen')
action.set_active(fullscreen) | python | {
"resource": ""
} |
q260038 | ShoebotWindow.do_fullscreen | validation | def do_fullscreen(self, widget):
"""
Widget Action to Make the window fullscreen and update the bot.
"""
self.fullscreen()
self.is_fullscreen = True
# next lines seem to be needed for window switching really to
# fullscreen mode before reading it's size values
... | python | {
"resource": ""
} |
q260039 | ShoebotWindow.do_unfullscreen | validation | def do_unfullscreen(self, widget):
"""
Widget Action to set Windowed Mode.
"""
self.unfullscreen()
self.is_fullscreen = False
self.bot._screen_ratio = None | python | {
"resource": ""
} |
q260040 | ShoebotWindow.do_window_close | validation | def do_window_close(self, widget, data=None):
"""
Widget Action to Close the window, triggering the quit event.
"""
publish_event(QUIT_EVENT)
if self.has_server:
self.sock.close()
self.hide_variables_window()
self.destroy()
self.window_open ... | python | {
"resource": ""
} |
q260041 | ShoebotWindow.do_toggle_fullscreen | validation | def do_toggle_fullscreen(self, action):
"""
Widget Action to Toggle fullscreen from the GUI
"""
is_fullscreen = action.get_active()
if is_fullscreen:
self.fullscreen()
else:
self.unfullscreen() | python | {
"resource": ""
} |
q260042 | ShoebotWindow.do_toggle_variables | validation | def do_toggle_variables(self, action):
"""
Widget Action to toggle showing the variables window.
"""
self.show_vars = action.get_active()
if self.show_vars:
self.show_variables_window()
else:
self.hide_variables_window() | python | {
"resource": ""
} |
q260043 | ShoebotWindow.main_iteration | validation | def main_iteration(self):
"""
Called from main loop, if your sink needs to handle GUI events
do it here.
Check any GUI flags then call Gtk.main_iteration to update things.
"""
if self.show_vars:
self.show_variables_window()
else:
self.hide... | python | {
"resource": ""
} |
q260044 | Bot._mouse_pointer_moved | validation | def _mouse_pointer_moved(self, x, y):
'''GUI callback for mouse moved'''
self._namespace['MOUSEX'] = x
self._namespace['MOUSEY'] = y | python | {
"resource": ""
} |
q260045 | Bot._key_pressed | validation | def _key_pressed(self, key, keycode):
'''GUI callback for key pressed'''
self._namespace['key'] = key
self._namespace['keycode'] = keycode
self._namespace['keydown'] = True | python | {
"resource": ""
} |
q260046 | Bot._makeInstance | validation | def _makeInstance(self, clazz, args, kwargs):
'''Creates an instance of a class defined in this document.
This method sets the context of the object to the current context.'''
inst = clazz(self, *args, **kwargs)
return inst | python | {
"resource": ""
} |
q260047 | Bot._makeColorableInstance | validation | def _makeColorableInstance(self, clazz, args, kwargs):
"""
Create an object, if fill, stroke or strokewidth
is not specified, get them from the _canvas
:param clazz:
:param args:
:param kwargs:
:return:
"""
kwargs = dict(kwargs)
fill = kw... | python | {
"resource": ""
} |
q260048 | Bot.show | validation | def show(self, format='png', as_data=False):
'''Returns an Image object of the current surface. Used for displaying
output in Jupyter notebooks. Adapted from the cairo-jupyter project.'''
from io import BytesIO
b = BytesIO()
if format == 'png':
from IPython.display... | python | {
"resource": ""
} |
q260049 | Bot.ximport | validation | def ximport(self, libName):
'''
Import Nodebox libraries.
The libraries get _ctx, which provides
them with the nodebox API.
:param libName: Library name to import
'''
# from Nodebox
lib = __import__(libName)
self._namespace[libName] = lib
... | python | {
"resource": ""
} |
q260050 | Bot.size | validation | def size(self, w=None, h=None):
'''Set the canvas size
Only the first call will actually be effective.
:param w: Width
:param h: height
'''
if not w:
w = self._canvas.width
if not h:
h = self._canvas.height
if not w and not h:
... | python | {
"resource": ""
} |
q260051 | Bot.speed | validation | def speed(self, framerate=None):
'''Set animation framerate.
:param framerate: Frames per second to run bot.
:return: Current framerate of animation.
'''
if framerate is not None:
self._speed = framerate
self._dynamic = True
else:
retu... | python | {
"resource": ""
} |
q260052 | InputDeviceMixin.set_callbacks | validation | def set_callbacks(self, **kwargs):
''' Set callbacks for input events '''
for name in self.SUPPORTED_CALLBACKS:
func = kwargs.get(name, getattr(self, name))
setattr(self, name, func) | python | {
"resource": ""
} |
q260053 | complement | validation | def complement(clr):
"""
Returns the color and its complement in a list.
"""
clr = color(clr)
colors = colorlist(clr)
colors.append(clr.complement)
return colors | python | {
"resource": ""
} |
q260054 | complementary | validation | def complementary(clr):
"""
Returns a list of complementary colors.
The complement is the color 180 degrees across
the artistic RYB color wheel.
The list contains darker and softer contrasting
and complementing colors.
"""
clr = color(clr)
colors = colorlist(clr)
# A contrastin... | python | {
"resource": ""
} |
q260055 | split_complementary | validation | def split_complementary(clr):
"""
Returns a list with the split complement of the color.
The split complement are the two colors to the left and right
of the color's complement.
"""
clr = color(clr)
colors = colorlist(clr)
clr = clr.complement
colors.append(clr.rotate_ryb(-30).light... | python | {
"resource": ""
} |
q260056 | left_complement | validation | def left_complement(clr):
"""
Returns the left half of the split complement.
A list is returned with the same darker and softer colors
as in the complementary list, but using the hue of the
left split complement instead of the complement itself.
"""
left = split_complementary(clr)[1]
co... | python | {
"resource": ""
} |
q260057 | right_complement | validation | def right_complement(clr):
"""
Returns the right half of the split complement.
"""
right = split_complementary(clr)[2]
colors = complementary(clr)
colors[3].h = right.h
colors[4].h = right.h
colors[5].h = right.h
colors = colorlist(
colors[0], colors[2], colors[1], colors[5]... | python | {
"resource": ""
} |
q260058 | analogous | validation | def analogous(clr, angle=10, contrast=0.25):
"""
Returns colors that are next to each other on the wheel.
These yield natural color schemes (like shades of water or sky).
The angle determines how far the colors are apart,
making it bigger will introduce more variation.
The contrast determines t... | python | {
"resource": ""
} |
q260059 | triad | validation | def triad(clr, angle=120):
"""
Returns a triad of colors.
The triad is made up of this color and two other colors
that together make up an equilateral triangle on
the artistic color wheel.
"""
clr = color(clr)
colors = colorlist(clr)
colors.append(clr.rotate_ryb(angle).lighten(0.1))... | python | {
"resource": ""
} |
q260060 | tetrad | validation | def tetrad(clr, angle=90):
"""
Returns a tetrad of colors.
The tetrad is made up of this color and three other colors
that together make up a cross on the artistic color wheel.
"""
clr = color(clr)
colors = colorlist(clr)
c = clr.rotate_ryb(angle)
if clr.brightness < 0.5:
c... | python | {
"resource": ""
} |
q260061 | compound | validation | def compound(clr, flip=False):
"""
Roughly the complement and some far analogs.
"""
def _wrap(x, min, threshold, plus):
if x - min < threshold:
return x + plus
else:
return x - min
d = 1
if flip: d = -1
clr = color(clr)
colors = colorlist(clr)
... | python | {
"resource": ""
} |
q260062 | outline | validation | def outline(path, colors, precision=0.4, continuous=True):
"""
Outlines each contour in a path with the colors in the list.
Each contour starts with the first color in the list,
and ends with the last color in the list.
Because each line segment is drawn separately,
works only with corner-mode... | python | {
"resource": ""
} |
q260063 | guess_name | validation | def guess_name(clr):
"""
Guesses the shade and hue name of a color.
If the given color is named in the named_colors list, return that name.
Otherwise guess its nearest hue and shade range.
"""
clr = Color(clr)
if clr.is_transparent: return "transparent"
if clr.is_black: return "black"
... | python | {
"resource": ""
} |
q260064 | shader | validation | def shader(x, y, dx, dy, radius=300, angle=0, spread=90):
"""
Returns a 0.0 - 1.0 brightness adjusted to a light source.
The light source is positioned at dx, dy.
The returned float is calculated for x, y position
(e.g. an oval at x, y should have this brightness).
The radius influences the st... | python | {
"resource": ""
} |
q260065 | aggregated | validation | def aggregated(cache=DEFAULT_CACHE):
"""
A dictionary of all aggregated words.
They keys in the dictionary correspond to subfolders in the aggregated cache.
Each key has a list of words. Each of these words is the name of an XML-file
in the subfolder. The XML-file contains color information harvest... | python | {
"resource": ""
} |
q260066 | morguefile | validation | def morguefile(query, n=10, top=10):
"""
Returns a list of colors drawn from a morgueFile image.
With the Web library installed,
downloads a thumbnail from morgueFile and retrieves pixel colors.
"""
from web import morguefile
images = morguefile.search(query)[:top]
path = choice(images... | python | {
"resource": ""
} |
q260067 | Color.str_to_rgb | validation | def str_to_rgb(self, str):
""" Returns RGB values based on a descriptive string.
If the given str is a named color, return its RGB values.
Otherwise, return a random named color that has str
in its name, or a random named color which name appears in str.
Specific suffixes (-is... | python | {
"resource": ""
} |
q260068 | Color.rotate_ryb | validation | def rotate_ryb(self, angle=180):
""" Returns a color rotated on the artistic RYB color wheel.
An artistic color wheel has slightly different opposites
(e.g. purple-yellow instead of purple-lime).
It is mathematically incorrect but generally assumed
to provide better complementa... | python | {
"resource": ""
} |
q260069 | Color.nearest_hue | validation | def nearest_hue(self, primary=False):
""" Returns the name of the nearest named hue.
For example,
if you supply an indigo color (a color between blue and violet),
the return value is "violet". If primary is set to True,
the return value is "purple".
Primary colors lea... | python | {
"resource": ""
} |
q260070 | Color.blend | validation | def blend(self, clr, factor=0.5):
"""
Returns a mix of two colors.
"""
r = self.r * (1 - factor) + clr.r * factor
g = self.g * (1 - factor) + clr.g * factor
b = self.b * (1 - factor) + clr.b * factor
a = self.a * (1 - factor) + clr.a * factor
return Color(... | python | {
"resource": ""
} |
q260071 | Color.swatch | validation | def swatch(self, x, y, w=35, h=35, roundness=0):
"""
Rectangle swatch for this color.
"""
_ctx.fill(self)
_ctx.rect(x, y, w, h, roundness) | python | {
"resource": ""
} |
q260072 | ColorList.image_to_rgb | validation | def image_to_rgb(self, path, n=10):
"""
Returns a list of colors based on pixel values in the image.
The Core Image library must be present to determine pixel colors.
F. Albers: http://nodebox.net/code/index.php/shared_2007-06-11-11-37-05
"""
from PIL import Image
... | python | {
"resource": ""
} |
q260073 | ColorList.context_to_rgb | validation | def context_to_rgb(self, str):
""" Returns the colors that have the given word in their context.
For example, the word "anger" appears
in black, orange and red contexts,
so the list will contain those three colors.
"""
matches = []
for clr in context:
... | python | {
"resource": ""
} |
q260074 | ColorList._context | validation | def _context(self):
"""
Returns the intersection of each color's context.
Get the nearest named hue of each color,
and finds overlapping tags in each hue's colors.
For example, a list containing yellow, deeppink and olive
yields: femininity, friendship, happiness, joy.
... | python | {
"resource": ""
} |
q260075 | ColorList.copy | validation | def copy(self):
""" Returns a deep copy of the list.
"""
return ColorList(
[color(clr.r, clr.g, clr.b, clr.a, mode="rgb") for clr in self],
name=self.name,
tags=self.tags
) | python | {
"resource": ""
} |
q260076 | ColorList._darkest | validation | def _darkest(self):
"""
Returns the darkest color from the list.
Knowing the contrast between a light and a dark swatch
can help us decide how to display readable typography.
"""
min, n = (1.0, 1.0, 1.0), 3.0
for clr in self:
if clr.r + clr.g + clr.b... | python | {
"resource": ""
} |
q260077 | ColorList._average | validation | def _average(self):
"""
Returns one average color for the colors in the list.
"""
r, g, b, a = 0, 0, 0, 0
for clr in self:
r += clr.r
g += clr.g
b += clr.b
a += clr.alpha
r /= len(self)
g /= len(self)
b /= l... | python | {
"resource": ""
} |
q260078 | ColorList.sort_by_distance | validation | def sort_by_distance(self, reversed=False):
"""
Returns a list with the smallest distance between two neighboring colors.
The algorithm has a factorial complexity so it may run slow.
"""
if len(self) == 0: return ColorList()
# Find the darkest color in the list.
... | python | {
"resource": ""
} |
q260079 | ColorList._sorted_copy | validation | def _sorted_copy(self, comparison, reversed=False):
"""
Returns a sorted copy with the colors arranged according to the given comparison.
"""
sorted = self.copy()
_list.sort(sorted, comparison)
if reversed:
_list.reverse(sorted)
return sorted | python | {
"resource": ""
} |
q260080 | ColorList.cluster_sort | validation | def cluster_sort(self, cmp1="hue", cmp2="brightness", reversed=False, n=12):
"""
Sorts the list by cmp1, then cuts it into n pieces which are sorted by cmp2.
If you want to cluster by hue, use n=12 (since there are 12 primary/secondary hues).
The resulting list will not contain n even s... | python | {
"resource": ""
} |
q260081 | ColorList.reverse | validation | def reverse(self):
"""
Returns a reversed copy of the list.
"""
colors = ColorList.copy(self)
_list.reverse(colors)
return colors | python | {
"resource": ""
} |
q260082 | ColorList.repeat | validation | def repeat(self, n=2, oscillate=False, callback=None):
"""
Returns a list that is a repetition of the given list.
When oscillate is True,
moves from the end back to the beginning,
and then from the beginning to the end, and so on.
"""
colorlist = ColorList()
... | python | {
"resource": ""
} |
q260083 | ColorList.swatch | validation | def swatch(self, x, y, w=35, h=35, padding=0, roundness=0):
"""
Rectangle swatches for all the colors in the list.
"""
for clr in self:
clr.swatch(x, y, w, h, roundness)
y += h + padding | python | {
"resource": ""
} |
q260084 | ColorList.swarm | validation | def swarm(self, x, y, r=100):
"""
Fancy random ovals for all the colors in the list.
"""
sc = _ctx.stroke(0, 0, 0, 0)
sw = _ctx.strokewidth(0)
_ctx.push()
_ctx.transform(_ctx.CORNER)
_ctx.translate(x, y)
for i in _range(r * 3):
clr = ... | python | {
"resource": ""
} |
q260085 | Gradient._interpolate | validation | def _interpolate(self, colors, n=100):
""" Returns intermediary colors for given list of colors.
"""
gradient = []
for i in _range(n):
l = len(colors) - 1
x = int(1.0 * i / n * l)
x = min(x + 0, l)
y = min(x + 1, l)
base = 1.... | python | {
"resource": ""
} |
q260086 | Gradient._cache | validation | def _cache(self):
"""
Populates the list with a number of gradient colors.
The list has Gradient.steps colors that interpolate between
the fixed base Gradient.colors.
The spread parameter controls the midpoint of the gradient,
you can shift it right and left. A separate... | python | {
"resource": ""
} |
q260087 | ColorRange.copy | validation | def copy(self, clr=None, d=0.0):
"""
Returns a copy of the range.
Optionally, supply a color to get a range copy
limited to the hue of that color.
"""
cr = ColorRange()
cr.name = self.name
cr.h = deepcopy(self.h)
cr.s = deepcopy(self.s)
c... | python | {
"resource": ""
} |
q260088 | ColorRange.color | validation | def color(self, clr=None, d=0.035):
"""
Returns a color with random values in the defined h, s b, a ranges.
If a color is given, use that color's hue and alpha,
and generate its saturation and brightness from the shade.
The hue is varied with the given d.
In this way yo... | python | {
"resource": ""
} |
q260089 | ColorRange.contains | validation | def contains(self, clr):
"""
Returns True if the given color is part of this color range.
Check whether each h, s, b, a component of the color
falls within the defined range for that component.
If the given color is grayscale,
checks against the definitions for black an... | python | {
"resource": ""
} |
q260090 | ColorTheme._xml | validation | def _xml(self):
"""
Returns the color information as XML.
The XML has the following structure:
<colors query="">
<color name="" weight="" />
<rgb r="" g="" b="" />
<shade name="" weight="" />
</color>
</colors>
Not... | python | {
"resource": ""
} |
q260091 | ColorTheme._save | validation | def _save(self):
"""
Saves the color information in the cache as XML.
"""
if not os.path.exists(self.cache):
os.makedirs(self.cache)
path = os.path.join(self.cache, self.name + ".xml")
f = open(path, "w")
f.write(self.xml)
f.close() | python | {
"resource": ""
} |
q260092 | ColorTheme._load | validation | def _load(self, top=5, blue="blue", archive=None, member=None):
"""
Loads a theme from aggregated web data.
The data must be old-style Prism XML: <color>s consisting of <shade>s.
Colors named "blue" will be overridden with the blue parameter.
archive can be a file like object (... | python | {
"resource": ""
} |
q260093 | ColorTheme.color | validation | def color(self, d=0.035):
"""
Returns a random color within the theme.
Fetches a random range (the weight is taken into account,
so ranges with a bigger weight have a higher chance of propagating)
and hues it with the associated color.
"""
s = sum([w for clr, rng... | python | {
"resource": ""
} |
q260094 | ColorTheme.colors | validation | def colors(self, n=10, d=0.035):
"""
Returns a number of random colors from the theme.
"""
s = sum([w for clr, rng, w in self.ranges])
colors = colorlist()
for i in _range(n):
r = random()
for clr, rng, weight in self.ranges:
if wei... | python | {
"resource": ""
} |
q260095 | ColorTheme.recombine | validation | def recombine(self, other, d=0.7):
"""
Genetic recombination of two themes using cut and splice technique.
"""
a, b = self, other
d1 = max(0, min(d, 1))
d2 = d1
c = ColorTheme(
name=a.name[:int(len(a.name) * d1)] +
b.name[int(len(b.na... | python | {
"resource": ""
} |
q260096 | ColorTheme.swatch | validation | def swatch(self, x, y, w=35, h=35, padding=4, roundness=0, n=12, d=0.035, grouped=None):
"""
Draws a weighted swatch with approximately n columns and rows.
When the grouped parameter is True, colors are grouped in blocks of the same hue
(also see the _weight_by_hue() method).
""... | python | {
"resource": ""
} |
q260097 | TuioProfile.fseq | validation | def fseq(self, client, message):
"""
fseq messages associate a unique frame id with a set of set
and alive messages
"""
client.last_frame = client.current_frame
client.current_frame = message[3] | python | {
"resource": ""
} |
q260098 | TuioProfile.objs | validation | def objs(self):
"""
Returns a generator list of tracked objects which are recognized with
this profile and are in the current session.
"""
for obj in self.objects.itervalues():
if obj.sessionid in self.sessions:
yield obj | python | {
"resource": ""
} |
q260099 | BezierPath._append_element | validation | def _append_element(self, render_func, pe):
'''
Append a render function and the parameters to pass
an equivilent PathElement, or the PathElement itself.
'''
self._render_funcs.append(render_func)
self._elements.append(pe) | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.