gloopy Package

gloopy Package

Gloopy’s top level package.

color Module

class gloopy.color.Color[source]

Bases: gloopy.color.__BaseColor

4-component named tuple: (r, g, b, a), with some methods.

Each component is an unsigned byte in the range 0 to 255. (Note this is likely to change in the future to using floats throughout. It seems that once geometry is pushed to a VBO, the performance gains of using ubytes diminish substantially).

__init__(r, g, b[, a=255])

r, g, b: red, green and blue

a: alpha (defaults to fully opaque)

All of r, g, b, a are ints from 0 to 255 (Color.MAX_CHANNEL.)

For example, to specify red color:

from gloopy.color import Color
red = Color(255, 0, 0)

Or semi-transparent blue:

red = Color(0, 0, 255, 127)

Some predefined instances of Color provide named colors. These named colors are defined as attributes of the Color class:

from gloopy.color import Color
print Color.RoyalPurple

The names and values are taken from the top 69 results of the xkcd color survey:

All = {'Blue': __BaseColor(r=3, g=67, b=223, a=255), 'Pink': __BaseColor(r=255, g=129, b=192, a=255), 'Peach': __BaseColor(r=255, g=176, b=124, a=255), 'Purple': __BaseColor(r=126, g=30, b=156, a=255), 'Rose': __BaseColor(r=207, g=98, b=117, a=255), 'LightBrown': __BaseColor(r=173, g=129, b=80, a=255), 'DarkRed': __BaseColor(r=132, g=0, b=0, a=255), 'Lavender': __BaseColor(r=199, g=159, b=239, a=255), 'NeonGreen': __BaseColor(r=12, g=255, b=12, a=255), 'Aquamarine': __BaseColor(r=4, g=216, b=178, a=255), 'YellowGreen': __BaseColor(r=192, g=251, b=45, a=255), 'Black': __BaseColor(r=0, g=0, b=0, a=255), 'DarkGrey': __BaseColor(r=64, g=64, b=64, a=255), 'Orange': __BaseColor(r=249, g=115, b=6, a=255), 'White': __BaseColor(r=255, g=255, b=255, a=255), 'Red': __BaseColor(r=229, g=0, b=0, a=255), 'PaleGreen': __BaseColor(r=199, g=253, b=181, a=255), 'Brown': __BaseColor(r=101, g=55, b=0, a=255), 'Turquoise': __BaseColor(r=6, g=194, b=172, a=255), 'Khaki': __BaseColor(r=170, g=166, b=98, a=255), 'DarkGreen': __BaseColor(r=3, g=53, b=0, a=255), 'Mustard': __BaseColor(r=206, g=179, b=1, a=255), 'DarkTeal': __BaseColor(r=1, g=77, b=78, a=255), 'LightPurple': __BaseColor(r=191, g=119, b=246, a=255), 'BrightBlue': __BaseColor(r=1, g=101, b=252, a=255), 'Salmon': __BaseColor(r=255, g=121, b=108, a=255), 'BabyBlue': __BaseColor(r=162, g=207, b=254, a=255), 'RoyalPurple': __BaseColor(r=75, g=0, b=110, a=255), 'BrickRed': __BaseColor(r=143, g=20, b=2, a=255), 'Magenta': __BaseColor(r=194, g=0, b=120, a=255), 'Olive': __BaseColor(r=110, g=117, b=14, a=255), 'Cyan': __BaseColor(r=0, g=255, b=255, a=255), 'Yellow': __BaseColor(r=255, g=255, b=20, a=255), 'MintGreen': __BaseColor(r=143, g=255, b=159, a=255), 'DarkPurple': __BaseColor(r=53, g=6, b=62, a=255), 'Plum': __BaseColor(r=88, g=15, b=65, a=255), 'Violet': __BaseColor(r=154, g=14, b=234, a=255), 'Aqua': __BaseColor(r=19, g=234, b=201, a=255), 'LightBlue': __BaseColor(r=149, g=208, b=252, a=255), 'OliveGreen': __BaseColor(r=103, g=122, b=4, a=255), 'DarkPink': __BaseColor(r=203, g=65, b=107, a=255), 'ForestGreen': __BaseColor(r=6, g=71, b=12, a=255), 'Green': __BaseColor(r=21, g=176, b=26, a=255), 'Beige': __BaseColor(r=230, g=218, b=166, a=255), 'Teal': __BaseColor(r=2, g=147, b=134, a=255), 'Indigo': __BaseColor(r=56, g=2, b=130, a=255), 'Burgundy': __BaseColor(r=97, g=0, b=35, a=255), 'LightGreen': __BaseColor(r=150, g=249, b=123, a=255), 'Tan': __BaseColor(r=209, g=178, b=111, a=255), 'BrightGreen': __BaseColor(r=1, g=255, b=7, a=255), 'SkyBlue': __BaseColor(r=117, g=187, b=253, a=255), 'PaleBlue': __BaseColor(r=208, g=254, b=254, a=255), 'Lilac': __BaseColor(r=206, g=162, b=253, a=255), 'HotPink': __BaseColor(r=255, g=2, b=141, a=255), 'DarkBlue': __BaseColor(r=0, g=3, b=91, a=255), 'LimeGreen': __BaseColor(r=137, g=254, b=5, a=255), 'SeaGreen': __BaseColor(r=83, g=252, b=161, a=255), 'RoyalBlue': __BaseColor(r=5, g=4, b=170, a=255), 'LightGrey': __BaseColor(r=192, g=192, b=192, a=255), 'Maroon': __BaseColor(r=101, g=0, b=33, a=255), 'NavyBlue': __BaseColor(r=0, g=17, b=70, a=255), 'LightPink': __BaseColor(r=255, g=209, b=223, a=255), 'BurntOrange': __BaseColor(r=192, g=78, b=1, a=255), 'BlueGreen': __BaseColor(r=19, g=126, b=109, a=255), 'Gold': __BaseColor(r=219, g=180, b=12, a=255), 'BrightPurple': __BaseColor(r=190, g=3, b=253, a=255), 'Mauve': __BaseColor(r=174, g=113, b=129, a=255), 'Navy': __BaseColor(r=1, g=21, b=62, a=255), 'Periwinkle': __BaseColor(r=142, g=130, b=254, a=255), 'Grey': __BaseColor(r=147, g=147, b=147, a=255), 'Lime': __BaseColor(r=170, g=255, b=50, a=255), 'GrassGreen': __BaseColor(r=63, g=155, b=11, a=255)}
Aqua = __BaseColor(r=19, g=234, b=201, a=255)
Aquamarine = __BaseColor(r=4, g=216, b=178, a=255)
BabyBlue = __BaseColor(r=162, g=207, b=254, a=255)
Beige = __BaseColor(r=230, g=218, b=166, a=255)
Black = __BaseColor(r=0, g=0, b=0, a=255)
Blue = __BaseColor(r=3, g=67, b=223, a=255)
BlueGreen = __BaseColor(r=19, g=126, b=109, a=255)
BrickRed = __BaseColor(r=143, g=20, b=2, a=255)
BrightBlue = __BaseColor(r=1, g=101, b=252, a=255)
BrightGreen = __BaseColor(r=1, g=255, b=7, a=255)
BrightPurple = __BaseColor(r=190, g=3, b=253, a=255)
Brown = __BaseColor(r=101, g=55, b=0, a=255)
Burgundy = __BaseColor(r=97, g=0, b=35, a=255)
BurntOrange = __BaseColor(r=192, g=78, b=1, a=255)
COMPONENTS = 4
Cyan = __BaseColor(r=0, g=255, b=255, a=255)
DarkBlue = __BaseColor(r=0, g=3, b=91, a=255)
DarkGreen = __BaseColor(r=3, g=53, b=0, a=255)
DarkGrey = __BaseColor(r=64, g=64, b=64, a=255)
DarkPink = __BaseColor(r=203, g=65, b=107, a=255)
DarkPurple = __BaseColor(r=53, g=6, b=62, a=255)
DarkRed = __BaseColor(r=132, g=0, b=0, a=255)
DarkTeal = __BaseColor(r=1, g=77, b=78, a=255)
ForestGreen = __BaseColor(r=6, g=71, b=12, a=255)
Gold = __BaseColor(r=219, g=180, b=12, a=255)
GrassGreen = __BaseColor(r=63, g=155, b=11, a=255)
Green = __BaseColor(r=21, g=176, b=26, a=255)
Grey = __BaseColor(r=147, g=147, b=147, a=255)
HotPink = __BaseColor(r=255, g=2, b=141, a=255)
Indigo = __BaseColor(r=56, g=2, b=130, a=255)
Khaki = __BaseColor(r=170, g=166, b=98, a=255)
Lavender = __BaseColor(r=199, g=159, b=239, a=255)
LightBlue = __BaseColor(r=149, g=208, b=252, a=255)
LightBrown = __BaseColor(r=173, g=129, b=80, a=255)
LightGreen = __BaseColor(r=150, g=249, b=123, a=255)
LightGrey = __BaseColor(r=192, g=192, b=192, a=255)
LightPink = __BaseColor(r=255, g=209, b=223, a=255)
LightPurple = __BaseColor(r=191, g=119, b=246, a=255)
Lilac = __BaseColor(r=206, g=162, b=253, a=255)
Lime = __BaseColor(r=170, g=255, b=50, a=255)
LimeGreen = __BaseColor(r=137, g=254, b=5, a=255)
MAX_CHANNEL = 255
Magenta = __BaseColor(r=194, g=0, b=120, a=255)
Maroon = __BaseColor(r=101, g=0, b=33, a=255)
Mauve = __BaseColor(r=174, g=113, b=129, a=255)
MintGreen = __BaseColor(r=143, g=255, b=159, a=255)
Mustard = __BaseColor(r=206, g=179, b=1, a=255)
Navy = __BaseColor(r=1, g=21, b=62, a=255)
NavyBlue = __BaseColor(r=0, g=17, b=70, a=255)
NeonGreen = __BaseColor(r=12, g=255, b=12, a=255)
Olive = __BaseColor(r=110, g=117, b=14, a=255)
OliveGreen = __BaseColor(r=103, g=122, b=4, a=255)
Orange = __BaseColor(r=249, g=115, b=6, a=255)
PaleBlue = __BaseColor(r=208, g=254, b=254, a=255)
PaleGreen = __BaseColor(r=199, g=253, b=181, a=255)
Peach = __BaseColor(r=255, g=176, b=124, a=255)
Periwinkle = __BaseColor(r=142, g=130, b=254, a=255)
Pink = __BaseColor(r=255, g=129, b=192, a=255)
Plum = __BaseColor(r=88, g=15, b=65, a=255)
Purple = __BaseColor(r=126, g=30, b=156, a=255)
static Random()[source]

Return a new random color

static Randoms()[source]

Generate an infinite sequence of random colors.

Red = __BaseColor(r=229, g=0, b=0, a=255)
Rose = __BaseColor(r=207, g=98, b=117, a=255)
RoyalBlue = __BaseColor(r=5, g=4, b=170, a=255)
RoyalPurple = __BaseColor(r=75, g=0, b=110, a=255)
Salmon = __BaseColor(r=255, g=121, b=108, a=255)
SeaGreen = __BaseColor(r=83, g=252, b=161, a=255)
SkyBlue = __BaseColor(r=117, g=187, b=253, a=255)
Tan = __BaseColor(r=209, g=178, b=111, a=255)
Teal = __BaseColor(r=2, g=147, b=134, a=255)
Turquoise = __BaseColor(r=6, g=194, b=172, a=255)
Violet = __BaseColor(r=154, g=14, b=234, a=255)
White = __BaseColor(r=255, g=255, b=255, a=255)
Yellow = __BaseColor(r=255, g=255, b=20, a=255)
YellowGreen = __BaseColor(r=192, g=251, b=45, a=255)
as_floats()[source]

Returns this color as a tuple of normalised floats, suitable for use with glSetClearColor. Note this method is likely to be deleted in a subsequent release, when colors change to being stored internally as floats.

inverted()[source]

Return a new color which is the complement of this one, i.e. if this color contains a lot of red, the return value will contain little red, and so on.

tinted(other, bias=0.5)[source]

Return a new color, interpolated between this color and other by an amount specified by bias, which normally ranges from 0.0 (entirely this color) to 1.0 (entirely other.)

variations(other=None)[source]

Generate an infinite sequence of colors which are tinted by random amounts towards other, which defaults to a darker version of this color.

gameitem Module

class gloopy.gameitem.GameItem(**kwargs)[source]

Bases: object

A dumb collection of attributes, representing a single item to be rendered.

__init__(**kwargs)[source]

kwargs: contains attributes which are attached to the returned instance, for example:

shape: specifies the appearance of the item, as an instance of Shape.

position: specified as a Vector.

orientation: specified as an Orientation.

update: a callable, of the signature:

update(self, time, dt)

This is called in between every render (unless it is None.)

You should feel free to pass in other attributes, which you might use in this item’s update method, for example .velocity, which you could use to move this item.

glyph: is used to store the shape converted into a VBO which OpenGL can render. If you update a GameItem shape, you must also update its glyph attribute using shape_to_glyph().

In addition, the attribute .id is assigned a unique integer.

gloopy.gameitem.position_or_gameitem(item)[source]

If item is a Vector, return it, otherwise assume it is a GameItem with a position attribute, and return that instead.

gloopy Module

class gloopy.gloopy.Gloopy[source]

Bases: object

__init__()[source]

Parses the command-line options, stores results in self.options

init(window=None)[source]

Initialise Gloopy. Must be called before calling run() to start the event loop. You may pass in a pyglet.window.Window instance, or if it is None, we will create a (non-visible) one, using self.options to determine its parameters.

on_key_press(symbol, modifiers)[source]

Handle key presses:

escape quit
f12 toggle fps display
f9 take screenshot
alt-enter toggle fullscreen
run()[source]

Schedules calls to self.update, makes window visible and starts the event loop by calling pyglet.app.run()

update(dt)[source]

Called before every screen refresh,

version Module

world Module

class gloopy.world.World[source]

Bases: object

A collection of all the GameItems to be updated and rendered. Supports iteration through all added items, and indexing by item.id to get a particular item.

Attributes:

self.items: a dict of all items that have been added, keyed by their
shape.id attribute.

self.item_added: event which is fired after an item is added.

self.item_removed: event which is fired after an item is removed.

self.update: event which is fired on every update. Items or
application code might want to register for this event if they want to do some work every frame that doesn’t fit well within the ‘update’ method of an item.

self.background_color: color used to clear the screen before render

add(item, position=None)[source]

add given item to the world. If position is not given, the item’s existing position attribute is used.

Fires the self.item_added event.

remove(item)[source]

remove the given item from the world.

Fires the self.item_removed event.

update_all(t, dt)[source]

Calls item.update() on each item that has a populated update attribute.

Fires the self.update event.

Table Of Contents

Previous topic

API Reference Modules

Next topic

geom Package

This Page