light_character package

Submodules

light_character.cli module

Console script for light_character.

light_character.cli.main()[source]

Console script for tartan.

light_character.light_character module

Main module.

light_character.light_character.cannot_have_period(pattern_type, groups)[source]
light_character.light_character.characteristic_to_light_states(description)[source]

Given a light characteristic, return a list of 2-tuples representing the state of light at any given time.

A fixed light is the given colour, permanently

>>> characteristic_to_light_states('F. R')
[('R', 1)]
light_character.light_character.collapse_states(states)[source]

Given a list of light states, collapse any adjacent entries that have the same state.

If there are no adjacent matching states, there is no change to the output

>>> collapse_states([('R',1), ('Y', 1), ('R', 1)])
[('R', 1), ('Y', 1), ('R', 1)]

Adjacent states are collapsed, summing their durations

>>> collapse_states([('R',1), ('R', 1), ('Y', 1)])
[('R', 2), ('Y', 1)]
>>> collapse_states([('R',1), ('R', 2), ('R', 3), ('Y', 1)])
[('R', 6), ('Y', 1)]
light_character.light_character.fixed(_groups, colour, _period)[source]

The Fixed pattern is simply an always-on light in the given colour. groups and period are irrelevant.

light_character.light_character.flash(groups, colour, period)[source]

A flash is a single colour displayed for a short period, followed by a longer period of darkness

A single flash of a given colour is a 1 second flash

>>> flash([1], 'R', 5000)
[('R', 1000), ('Off', 4000)]

Grouped flashes have a shorter duration

>>> flash([3], 'R', 10000)
[('R', 500), ('Off', 1000), ('R', 500), ('Off', 1000), ('R', 500), ('Off', 1000), ('Off', 5500)]

Composite groups are separated by an even period of darkness

>>> flash([3, 1], 'R', 10000)
[('R', 500), ('Off', 1000), ('R', 500), ('Off', 1000), ('R', 500), ('Off', 1000), ('Off', 2000), ('R', 500), ('Off', 1000), ('Off', 2000)]

The total duration of all states matches the requested period

>>> sum((state[1] for state in flash([1], 'R', 5000))) == 5000
True
light_character.light_character.get_colour_code(fragments)[source]
light_character.light_character.isophase(_groups, colour, period)[source]

isophase is a pattern with equal dark and light. There are no groups.

light_character.light_character.light_sequence(groups, colour1, colour2, total_period, colour1_period, colour2_period)[source]
light_character.light_character.load_base_images(base_img)[source]

Return the two base images needed to create a lighthouse animation. base_img is either

  • A full/relative path from the run context

  • The name of a directory under lighthouses here

light_character.light_character.long_flash(groups, colour, period)[source]

A Long flash is at least 2 seconds

light_character.light_character.must_have_period(pattern_type, groups)[source]
light_character.light_character.occulting(groups, colour, period)[source]

An occulting pattern is the opposite of a flash - dark with longer light

light_character.light_character.parse_pattern(pattern)[source]

Crack a pattern definition into its type and any grouping.

A pattern consists of the pattern type (e.g. flashing, occulting) and optionally a group designation in parentheses.

The pattern definition could just be the type

>>> parse_pattern('Fl')
('fl', [1])

It could have optional dots marking the abbreviation, these can be discarded

>>> parse_pattern('L.Fl.')
('lfl', [1])

It could have grouping information in parentheses

>>> parse_pattern('Fl(2)')
('fl', [2])

The group could be a composite group.

>>> parse_pattern('Oc(2+1)')
('oc', [2, 1])
light_character.light_character.parse_period(fragments)[source]

Given the split up characteristic, return the period in milliseconds

The period is specified in seconds

>>> parse_period(['2'])
2000

The letter ‘s’ to mark the units may be present

>>> parse_period(['3s'])
3000

It may be separated from the number by a space

>>> parse_period(['4','s'])
4000

A Quick flash can only have a period if it has groups

>>> parse_period(['3s'])
3000
light_character.light_character.quick(groups, colour, period)[source]

A Quick flash is more than 50 per minute.

light_character.light_character.save_characteristic_as_image(characteristic, size, write_buffer, base_img=None)[source]
light_character.light_character.single_flash(flash_count, colour1, colour2, period1, period2)[source]
light_character.light_character.states_to_frames(size, states, fg, off_img)[source]

Module contents

Top-level package for contactsheet.