_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q24100 | make_function | train | def make_function(function, name, arity):
"""Make a function node, a representation of a mathematical relationship.
This factory function creates a function node, one of the core nodes in any
program. The resulting object is able to be called with NumPy vectorized
arguments and return a resulting vecto... | python | {
"resource": ""
} |
q24101 | _generate_segments | train | def _generate_segments(im_orig, scale, sigma, min_size):
"""
segment smallest regions by the algorithm of Felzenswalb and
Huttenlocher
"""
# open the Image
im_mask = skimage.segmentation.felzenszwalb(
| python | {
"resource": ""
} |
q24102 | _sim_colour | train | def _sim_colour(r1, r2):
"""
calculate the sum of histogram intersection of colour
"""
| python | {
"resource": ""
} |
q24103 | _sim_texture | train | def _sim_texture(r1, r2):
"""
calculate the sum of histogram intersection of texture
"""
| python | {
"resource": ""
} |
q24104 | _sim_fill | train | def _sim_fill(r1, r2, imsize):
"""
calculate the fill similarity over the image
"""
bbsize = (
(max(r1["max_x"], r2["max_x"]) | python | {
"resource": ""
} |
q24105 | _calc_colour_hist | train | def _calc_colour_hist(img):
"""
calculate colour histogram for each region
the size of output histogram will be BINS * COLOUR_CHANNELS(3)
number of bins is 25 as same as [uijlings_ijcv2013_draft.pdf]
extract HSV
"""
| python | {
"resource": ""
} |
q24106 | _calc_texture_gradient | train | def _calc_texture_gradient(img):
"""
calculate texture gradient for entire image
The original SelectiveSearch algorithm proposed Gaussian derivative
for 8 orientations, but we use LBP instead. | python | {
"resource": ""
} |
q24107 | _calc_texture_hist | train | def _calc_texture_hist(img):
"""
calculate texture histogram for each region
calculate the histogram of gradient for each colours
the size of output histogram will be
BINS * ORIENTATIONS * COLOUR_CHANNELS(3)
"""
BINS = 10
hist = numpy.array([])
for colour_chann... | python | {
"resource": ""
} |
q24108 | Scene.reset | train | def reset(self, old_scene=None, screen=None):
"""
Reset the scene ready for playing.
:param old_scene: The previous version of this Scene that was running before the
application reset - e.g. due to a screen resize.
:param screen: New screen to use if old_scene is not None.
... | python | {
"resource": ""
} |
q24109 | Scene.add_effect | train | def add_effect(self, effect, reset=True):
"""
Add an effect to the Scene.
This method can be called at any time - even when playing the Scene. The default logic
assumes that the Effect needs to be reset before being displayed. This can be overridden
using the `reset` parameter... | python | {
"resource": ""
} |
q24110 | Scene.process_event | train | def process_event(self, event):
"""
Process a new input event.
This method will pass the event on to any Effects in reverse Z order so that the
top-most Effect has priority.
:param event: The Event that has been triggered.
:returns: None if the Scene processed the event... | python | {
"resource": ""
} |
q24111 | _spline | train | def _spline(t, p0, p1, p2, p3):
"""
Catmull-Rom cubic spline to interpolate 4 given points.
:param t: Time index through the spline (must be 0-1).
:param p0: The previous point in the curve (for continuity).
:param p1: The first point to interpolate.
:param p2: The second point to interpolate.
... | python | {
"resource": ""
} |
q24112 | Path._add_step | train | def _add_step(self, pos):
"""
Add a step to the end of the current recorded path.
:param pos: The position tuple (x, y) to add to the list.
| python | {
"resource": ""
} |
q24113 | Path.wait | train | def wait(self, delay):
"""
Wait at the current location for the specified number of iterations.
| python | {
"resource": ""
} |
q24114 | Path.move_straight_to | train | def move_straight_to(self, x, y, steps):
"""
Move straight to the newly specified location - i.e. create a straight
line Path from the current location to the specified point.
:param x: X coord for the end position.
| python | {
"resource": ""
} |
q24115 | Path.move_round_to | train | def move_round_to(self, points, steps):
"""
Follow a path pre-defined by a set of at least 4 points. This Path will
interpolate the points into a curve and follow that curve.
:param points: The list of points that defines the path.
:param steps: The number of steps to take to f... | python | {
"resource": ""
} |
q24116 | DynamicPath.reset | train | def reset(self):
"""
Reset the Path for use next time.
"""
| python | {
"resource": ""
} |
q24117 | _enforce_width | train | def _enforce_width(text, width, unicode_aware=True):
"""
Enforce a displayed piece of text to be a certain number of cells wide. This takes into
account double-width characters used in CJK languages.
:param text: The text to be truncated
:param width: The screen cell width to enforce
:return: ... | python | {
"resource": ""
} |
q24118 | _find_min_start | train | def _find_min_start(text, max_width, unicode_aware=True, at_end=False):
"""
Find the starting point in the string that will reduce it to be less than or equal to the
specified width when displayed on screen.
:param text: The text to analyze.
:param max_width: The required maximum width
:param a... | python | {
"resource": ""
} |
q24119 | _split_text | train | def _split_text(text, width, height, unicode_aware=True):
"""
Split text to required dimensions.
This will first try to split the text into multiple lines, then put a "..." on the last
3 characters of the last line if this still doesn't fit.
:param text: The text to split.
:param width: The ma... | python | {
"resource": ""
} |
q24120 | Frame.add_layout | train | def add_layout(self, layout):
"""
Add a Layout to the Frame.
:param layout: The Layout to be added.
""" | python | {
"resource": ""
} |
q24121 | Frame.add_effect | train | def add_effect(self, effect):
"""
Add an Effect to the Frame.
:param effect: The Effect to be added.
"""
| python | {
"resource": ""
} |
q24122 | Frame.fix | train | def fix(self):
"""
Fix the layouts and calculate the locations of all the widgets.
This function should be called once all Layouts have been added to the Frame and all
widgets added to the Layouts.
"""
# Do up to 2 passes in case we have a variable height Layout.
... | python | {
"resource": ""
} |
q24123 | Frame._clear | train | def _clear(self):
"""
Clear the current canvas.
"""
# It's orders of magnitude faster to reset with a print like this
# instead of recreating the | python | {
"resource": ""
} |
q24124 | Frame.set_theme | train | def set_theme(self, theme):
"""
Pick a palette from the list of supported THEMES.
:param theme: The name of the theme to set.
"""
if theme in THEMES:
self.palette = THEMES[theme] | python | {
"resource": ""
} |
q24125 | Frame.focussed_widget | train | def focussed_widget(self):
"""
The widget that currently has the focus within this Frame.
"""
# If the frame has no focus, it can't have a focussed widget.
if not self._has_focus:
return None
try:
| python | {
"resource": ""
} |
q24126 | Frame.frame_update_count | train | def frame_update_count(self):
"""
The number of frames before this Effect should be updated.
"""
result = 1000000
for layout in self._layouts:
if layout.frame_update_count > 0:
result = min(result, layout.frame_update_count)
| python | {
"resource": ""
} |
q24127 | Frame.clone | train | def clone(self, _, scene):
"""
Create a clone of this Frame into a new Screen.
:param _: ignored.
:param scene: The new Scene object to clone into.
"""
# Assume that the application creates a new set of Frames and so we need to match up the
# data from the old ob... | python | {
"resource": ""
} |
q24128 | Frame.switch_focus | train | def switch_focus(self, layout, column, widget):
"""
Switch focus to the specified widget.
:param layout: The layout that owns the widget.
:param column: The column the widget is in.
:param widget: The index of the widget to take the focus.
"""
# Find the layout t... | python | {
"resource": ""
} |
q24129 | Frame.move_to | train | def move_to(self, x, y, h):
"""
Make the specified location visible. This is typically used by a widget to scroll the
canvas such that it is visible.
:param x: The x location to make visible.
:param y: The y location to make visible.
:param h: The height of the location... | python | {
"resource": ""
} |
q24130 | Frame.rebase_event | train | def rebase_event(self, event):
"""
Rebase the coordinates of the passed event to frame-relative coordinates.
:param event: The event to be rebased.
:returns: A new event object appropriately re-based.
"""
new_event = copy(event)
if isinstance(new_event, MouseEven... | python | {
"resource": ""
} |
q24131 | Layout.frame_update_count | train | def frame_update_count(self):
"""
The number of frames before this Layout should be updated.
"""
result = 1000000
for column in self._columns:
for widget in column:
| python | {
"resource": ""
} |
q24132 | Layout.add_widget | train | def add_widget(self, widget, column=0):
"""
Add a widget to this Layout.
If you are adding this Widget to the Layout dynamically after starting to play the Scene,
don't forget to ensure that the value is explicitly set before the next update.
:param widget: The widget to be add... | python | {
"resource": ""
} |
q24133 | Layout.focus | train | def focus(self, force_first=False, force_last=False, force_column=None,
force_widget=None):
"""
Call this to give this Layout the input focus.
:param force_first: Optional parameter to force focus to first widget.
:param force_last: Optional parameter to force focus to las... | python | {
"resource": ""
} |
q24134 | Layout.blur | train | def blur(self):
"""
Call this to take the input focus from this Layout.
"""
self._has_focus = False
| python | {
"resource": ""
} |
q24135 | Layout.fix | train | def fix(self, start_x, start_y, max_width, max_height):
"""
Fix the location and size of all the Widgets in this Layout.
:param start_x: The start column for the Layout.
:param start_y: The start line for the Layout.
:param max_width: Max width to allow this layout.
:par... | python | {
"resource": ""
} |
q24136 | Layout.update | train | def update(self, frame_no):
"""
Redraw the widgets inside this Layout.
:param frame_no: The current frame to be drawn.
"""
| python | {
"resource": ""
} |
q24137 | Layout.update_widgets | train | def update_widgets(self, new_frame=None):
"""
Reset the values for any Widgets in this Layout based on the current Frame data store.
:param new_frame: optional old Frame - used when cloning scenes.
"""
for column in self._columns:
for widget in column:
... | python | {
"resource": ""
} |
q24138 | Layout.reset | train | def reset(self):
"""
Reset this Layout and the Widgets it contains.
"""
# Ensure that the widgets are using the right values.
self.update_widgets()
# Reset all the widgets.
for column in self._columns:
| python | {
"resource": ""
} |
q24139 | Widget.set_layout | train | def set_layout(self, x, y, offset, w, h):
"""
Set the size and position of the Widget.
This should not be called directly. It is used by the :py:obj:`.Layout` class to arrange
all widgets within the Frame.
:param x: The x position of the widget.
:param y: The y positio... | python | {
"resource": ""
} |
q24140 | Widget.get_location | train | def get_location(self):
"""
Return the absolute location of this widget on the Screen, taking into account the
current state of the Frame that is displaying it and any label offsets of the Widget.
:returns: A tuple of the form (<X coordinate>, <Y coordinate>).
"""
| python | {
"resource": ""
} |
q24141 | Widget.focus | train | def focus(self):
"""
Call this to give this Widget the input focus.
"""
| python | {
"resource": ""
} |
q24142 | Widget.is_mouse_over | train | def is_mouse_over(self, event, include_label=True, width_modifier=0):
"""
Check if the specified mouse event is over this widget.
:param event: The MouseEvent to check.
:param include_label: Include space reserved for the label when checking.
:param width_modifier: Adjustement t... | python | {
"resource": ""
} |
q24143 | Widget._draw_label | train | def _draw_label(self):
"""
Draw the label for this widget if needed.
"""
if self._label is not None:
# Break the label up as required.
if self._display_label is None:
# noinspection PyTypeChecker
| python | {
"resource": ""
} |
q24144 | Widget._draw_cursor | train | def _draw_cursor(self, char, frame_no, x, y):
"""
Draw a flashing cursor for this widget.
:param char: The character to use for the cursor (when not a block)
:param frame_no: The current frame number.
:param x: The x coordinate for the cursor.
:param y: The y coordinate ... | python | {
"resource": ""
} |
q24145 | TextBox._reflowed_text | train | def _reflowed_text(self):
"""
The text as should be formatted on the screen.
This is an array of tuples of the form (text, value line, value column offset) where
the line and column offsets are indeces into the value (not displayed glyph coordinates).
"""
if self._reflow... | python | {
"resource": ""
} |
q24146 | _BaseListBox._add_or_remove_scrollbar | train | def _add_or_remove_scrollbar(self, width, height, dy):
"""
Add or remove a scrollbar from this listbox based on height and available options.
:param width: Width of the Listbox
:param height: Height of the Listbox.
:param dy: Vertical offset from top of widget.
"""
... | python | {
"resource": ""
} |
q24147 | MultiColumnListBox._get_width | train | def _get_width(self, width, max_width):
"""
Helper function to figure out the actual column width from the various options.
:param width: The size of column requested
:param max_width: The maximum width allowed for this widget.
| python | {
"resource": ""
} |
q24148 | FileBrowser._on_selection | train | def _on_selection(self):
"""
Internal function to handle directory traversal or bubble notifications up to user of the
Widget as needed.
"""
if self.value and os.path.isdir(self.value):
| python | {
"resource": ""
} |
q24149 | FileBrowser._populate_list | train | def _populate_list(self, value):
"""
Populate the current multi-column list with the contents of the selected directory.
:param value: The new value to use.
"""
# Nothing to do if the value is rubbish.
if value is None:
return
# Stop any recursion - ... | python | {
"resource": ""
} |
q24150 | PopUpDialog.clone | train | def clone(self, screen, scene):
"""
Create a clone of this Dialog into a new Screen.
:param screen: The new Screen object to clone into.
:param scene: The new Scene object to clone into.
"""
# Only clone the object if the function is safe to do | python | {
"resource": ""
} |
q24151 | _TempPopup.close | train | def close(self, cancelled=False):
"""
Close this temporary pop-up.
:param cancelled: Whether | python | {
"resource": ""
} |
q24152 | _ScrollBar.update | train | def update(self):
"""
Draw the scroll bar.
"""
# Sort out chars
cursor = u"█" if self._canvas.unicode_aware else "O"
back = u"░" if self._canvas.unicode_aware else "|"
# Now draw...
try:
sb_pos = self._get_pos()
sb_pos = min(1, max... | python | {
"resource": ""
} |
q24153 | _ScrollBar.is_mouse_over | train | def is_mouse_over(self, event):
"""
Check whether a MouseEvent is over thus scroll bar.
:param event: The MouseEvent to check.
:returns: True if the mouse | python | {
"resource": ""
} |
q24154 | _ScrollBar.process_event | train | def process_event(self, event):
"""
Handle input on the scroll bar.
:param event: the event to be processed.
:returns: True if the scroll bar handled the event.
"""
# Convert into absolute coordinates if needed.
new_event = event
if self._absolute:
... | python | {
"resource": ""
} |
q24155 | StaticRenderer._convert_images | train | def _convert_images(self):
"""
Convert any images into a more Screen-friendly format.
"""
self._plain_images = []
self._colour_map = []
for image in self._images:
colour_map = []
new_image = []
for line in image.split("\n"):
... | python | {
"resource": ""
} |
q24156 | DynamicRenderer._clear | train | def _clear(self):
"""
Clear the current image.
"""
self._plain_image = [" " * self._width for | python | {
"resource": ""
} |
q24157 | DynamicRenderer._write | train | def _write(self, text, x, y, colour=Screen.COLOUR_WHITE,
attr=Screen.A_NORMAL, bg=Screen.COLOUR_BLACK):
"""
Write some text to the specified location in the current image.
:param text: The text to be added.
:param x: The X coordinate in the image.
:param y: The Y ... | python | {
"resource": ""
} |
q24158 | Effect.update | train | def update(self, frame_no):
"""
Process the animation effect for the specified frame number.
:param frame_no: The index of | python | {
"resource": ""
} |
q24159 | _Star._respawn | train | def _respawn(self):
"""
Pick a random location for the star making sure it does
not overwrite an existing piece of text.
"""
self._cycle = randint(0, len(self._star_chars))
(height, width) = self._screen.dimensions
while True:
self._x = | python | {
"resource": ""
} |
q24160 | _Star.update | train | def update(self):
"""
Draw the star.
"""
if not self._screen.is_visible(self._x, self._y):
self._respawn()
cur_char, _, _, _ = self._screen.get_from(self._x, self._y)
if cur_char not in (ord(self._old_char), 32):
| python | {
"resource": ""
} |
q24161 | _Trail._maybe_reseed | train | def _maybe_reseed(self, normal):
"""
Randomly create a new column once this one is finished.
"""
self._y += self._rate
self._life -= 1
if self._life <= 0:
self._clear = not self._clear if normal else True
self._rate = randint(1, 2)
if s... | python | {
"resource": ""
} |
q24162 | _Trail.update | train | def update(self, reseed):
"""
Update that trail!
:param reseed: Whether we are in the normal reseed cycle or not.
"""
if self._clear:
for i in range(0, 3):
self._screen.print_at(" ",
self._x,
... | python | {
"resource": ""
} |
q24163 | Sprite.overlaps | train | def overlaps(self, other, use_new_pos=False):
"""
Check whether this Sprite overlaps another.
:param other: The other Sprite to check for an overlap.
:param use_new_pos: Whether to use latest position (due to recent
update). Defaults to False.
:returns: True if the ... | python | {
"resource": ""
} |
q24164 | _Flake._reseed | train | def _reseed(self):
"""
Randomly create a new snowflake once this one is finished.
"""
self._char = choice(self._snow_chars)
self._rate = randint(1, 3)
| python | {
"resource": ""
} |
q24165 | _Flake.update | train | def update(self, reseed):
"""
Update that snowflake!
:param reseed: Whether we are in the normal reseed cycle or not.
"""
self._screen.print_at(" ", self._x, self._y)
cell = None
for _ in range(self._rate):
self._y += 1
cell = self._screen... | python | {
"resource": ""
} |
q24166 | _DoubleBuffer.clear | train | def clear(self, fg, attr, bg):
"""
Clear the double-buffer.
This does not clear the screen buffer and so the next call to deltas will still show all changes.
:param fg: The foreground colour to use for the new buffer.
:param attr: The attribute value to use for the new buffer.
... | python | {
"resource": ""
} |
q24167 | _DoubleBuffer.set | train | def set(self, x, y, value):
"""
Set the cell value from the specified location
:param x: The column (x coord) of the character.
| python | {
"resource": ""
} |
q24168 | _DoubleBuffer.scroll | train | def scroll(self, lines):
"""
Scroll the window up or down.
:param lines: Number of lines to scroll. Negative numbers move the buffer up.
"""
line = [(ord(u" "), Screen.COLOUR_WHITE, 0, 0, 1) for _ in range(self._width)]
if lines > 0:
# Limit to buffer size -... | python | {
"resource": ""
} |
q24169 | _DoubleBuffer.block_transfer | train | def block_transfer(self, buffer, x, y):
"""
Copy a buffer entirely to this double buffer.
:param buffer: The double buffer to copy
:param x: The X origin for where to place it in this buffer
:param y: The Y origin for where to place it in this buffer
"""
# Just c... | python | {
"resource": ""
} |
q24170 | _DoubleBuffer.slice | train | def slice(self, x, y, width):
"""
Provide a slice of data from the buffer at the specified location
:param x: The X origin
:param y: The Y origin
:param width: The width of slice required
| python | {
"resource": ""
} |
q24171 | _AbstractCanvas.clear_buffer | train | def clear_buffer(self, fg, attr, bg):
"""
Clear the current double-buffer used by this object.
:param fg: The foreground colour to use | python | {
"resource": ""
} |
q24172 | _AbstractCanvas.reset | train | def reset(self):
"""
Reset the internal buffers for the abstract canvas.
"""
# Reset our screen | python | {
"resource": ""
} |
q24173 | _AbstractCanvas.scroll_to | train | def scroll_to(self, line):
"""
Scroll the abstract canvas to make a specific line.
| python | {
"resource": ""
} |
q24174 | _AbstractCanvas.get_from | train | def get_from(self, x, y):
"""
Get the character at the specified location.
:param x: The column (x coord) of the character.
:param y: The row (y coord) of the character.
:return: A 4-tuple of (ascii code, foreground, attributes, background) | python | {
"resource": ""
} |
q24175 | _AbstractCanvas.print_at | train | def print_at(self, text, x, y, colour=7, attr=0, bg=0, transparent=False):
"""
Print the text at the specified location using the specified colour and attributes.
:param text: The (single line) text to be printed.
:param x: The column (x coord) for the start of the text.
:param ... | python | {
"resource": ""
} |
q24176 | _AbstractCanvas.block_transfer | train | def block_transfer(self, buffer, x, y):
"""
Copy a buffer to the screen double buffer at a specified location.
:param buffer: The double | python | {
"resource": ""
} |
q24177 | _AbstractCanvas.paint | train | def paint(self, text, x, y, colour=7, attr=0, bg=0, transparent=False,
colour_map=None):
"""
Paint multi-colour text at the defined location.
:param text: The (single line) text to be printed.
:param x: The column (x coord) for the start of the text.
:param y: The ... | python | {
"resource": ""
} |
q24178 | _AbstractCanvas._blend | train | def _blend(self, new, old, ratio):
"""
Blend the new colour with the old according to the ratio.
:param new: The new colour (or None if not required).
:param old: The old colour.
:param ratio: The ratio to blend new and old
:returns: the new colour index to use for the r... | python | {
"resource": ""
} |
q24179 | _AbstractCanvas.highlight | train | def highlight(self, x, y, w, h, fg=None, bg=None, blend=100):
"""
Highlight a specified section of the screen.
:param x: The column (x coord) for the start of the highlight.
:param y: The line (y coord) for the start of the highlight.
:param w: The width of the highlight (in cha... | python | {
"resource": ""
} |
q24180 | _AbstractCanvas.is_visible | train | def is_visible(self, x, y):
"""
Return whether the specified location is on the visible screen.
:param x: The column (x coord) for the location to check.
:param y: The line (y coord) for the location to check.
"""
| python | {
"resource": ""
} |
q24181 | _AbstractCanvas.move | train | def move(self, x, y):
"""
Move the drawing cursor to the specified position.
:param x: The column (x coord) for the location to check.
:param y: The line | python | {
"resource": ""
} |
q24182 | Canvas.refresh | train | def refresh(self):
"""
Flush the canvas content to the underlying screen.
"""
| python | {
"resource": ""
} |
q24183 | Screen.wrapper | train | def wrapper(cls, func, height=None, catch_interrupt=False, arguments=None,
unicode_aware=None):
"""
Construct a new Screen for any platform. This will initialize the
Screen, call the specified function and then tidy up the system as
required when the function exits.
... | python | {
"resource": ""
} |
q24184 | Screen._reset | train | def _reset(self):
"""
Reset the Screen.
"""
self._last_start_line = 0 | python | {
"resource": ""
} |
q24185 | Screen.refresh | train | def refresh(self):
"""
Refresh the screen.
"""
# Scroll the screen now - we've already sorted the double-buffer to reflect this change.
if self._last_start_line != self._start_line:
self._scroll(self._start_line - self._last_start_line)
self._last_start_li... | python | {
"resource": ""
} |
q24186 | Screen.clear | train | def clear(self):
"""
Clear the Screen of all content.
Note that this will instantly clear the Screen and reset all buffers to the default state,
without waiting for you to call :py:meth:`~.Screen.refresh`.
"""
# Clear | python | {
"resource": ""
} |
q24187 | Screen._unhandled_event_default | train | def _unhandled_event_default(event):
"""
Default unhandled event handler for handling simple scene navigation.
"""
if isinstance(event, KeyboardEvent):
c = event.key_code
if c in (ord("X"), ord("x"), ord("Q"), ord("q")):
| python | {
"resource": ""
} |
q24188 | Screen.play | train | def play(self, scenes, stop_on_resize=False, unhandled_input=None,
start_scene=None, repeat=True, allow_int=False):
"""
Play a set of scenes.
This is effectively a helper function to wrap :py:meth:`.set_scenes` and
:py:meth:`.draw_next_frame` to simplify animation for most ... | python | {
"resource": ""
} |
q24189 | Particle._default_next_char | train | def _default_next_char(particle):
"""
Default next character implementation - linear progression through
each character.
| python | {
"resource": ""
} |
q24190 | Particle._default_next_colour | train | def _default_next_colour(particle):
"""
Default next colour implementation - linear progression through
each colour tuple.
| python | {
"resource": ""
} |
q24191 | Particle.next | train | def next(self):
"""
The set of attributes for this particle for the next frame to be
rendered.
:returns: A tuple of (character, x, y, fg, attribute, bg)
"""
# Get next particle details
x, y = self._move(self)
colour = self._next_colour(self)
char ... | python | {
"resource": ""
} |
q24192 | ParticleEmitter._find_colour | train | def _find_colour(particle, start_index, screen_data):
"""
Helper function to find an existing colour in the particle palette.
"""
| python | {
"resource": ""
} |
q24193 | ParticleEmitter.update | train | def update(self):
"""
The function to draw a new frame for the particle system.
"""
# Spawn new particles if required
if self.time_left > 0:
self.time_left -= 1
for _ in range(self._count):
new_particle = self._new_particle()
... | python | {
"resource": ""
} |
q24194 | Map._scale_coords | train | def _scale_coords(self, x, y, extent, xo, yo):
"""Convert from tile coordinates to "pixels" - i.e. text characters."""
return xo + (x | python | {
"resource": ""
} |
q24195 | Map._convert_latitude | train | def _convert_latitude(self, latitude):
"""Convert from latitude to the y position in overall map."""
return int((180 - (180 / pi * log(tan(
| python | {
"resource": ""
} |
q24196 | Map._get_satellite_tile | train | def _get_satellite_tile(self, x_tile, y_tile, z_tile):
"""Load up a single satellite image tile."""
cache_file = "mapscache/{}.{}.{}.jpg".format(z_tile, x_tile, y_tile)
if cache_file not in self._tiles:
if not os.path.isfile(cache_file):
url = _IMAGE_URL.format(z_tile... | python | {
"resource": ""
} |
q24197 | Map._get_vector_tile | train | def _get_vector_tile(self, x_tile, y_tile, z_tile):
"""Load up a single vector tile."""
cache_file = "mapscache/{}.{}.{}.json".format(z_tile, x_tile, y_tile)
if cache_file not in self._tiles:
if os.path.isfile(cache_file):
with open(cache_file, 'rb') as f:
... | python | {
"resource": ""
} |
q24198 | Map._get_tiles | train | def _get_tiles(self):
"""Background thread to download map tiles as required."""
while self._running:
self._updated.wait()
self._updated.clear()
# Save off current view and find the nearest tile.
satellite = self._satellite
zoom = self._zoom
... | python | {
"resource": ""
} |
q24199 | Map._get_features | train | def _get_features(self):
"""Decide which layers to render based on current zoom level and view type."""
if self._satellite:
return [("water", [], [])]
elif self._zoom <= 2:
return [
("water", [], []),
("marine_label", [], [1]),
... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.