day22.lib package

Submodules

day22.lib.classes module

Classes for day22.

class day22.lib.classes.BoxData(name: str, start_pos: Vector3, end_pos: Vector3)[source]

Bases: object

A box in 3d space.

end_pos: Vector3
fall() None[source]

Move block down vertically.

hats: set[BoxData]
property height: float

Height according to vpython.

property length: float

Length according to vpython.

name: str
recursive_fall(already_falling: set[BoxData]) set[BoxData][source]

Returns all boxes above us that fall if we fall.

select() None[source]

Select a box by offsetting it to the side.

set_hats(hats: set[BoxData]) None[source]

Set the BoxData’s that we support.

set_supports(supports: set[BoxData]) None[source]

Set the BoxData’s that support us.

set_vbox(vbox: box) None[source]

Store a vpython box onto this boxdata.

start_pos: Vector3
supports: set[BoxData]
total_hats: set[BoxData]
unselect() None[source]

Unselect a box by putting it back.

vbox: box | None = None
property vpos: vector

Pos according to vpython.

property width: float

Width according to vpython.

property z_val_bot: int

Return lowest z value (self.start_pos.z).

property z_val_top: int

Return maximum z value(self.end_pos.z).

class day22.lib.classes.Matrix(z_height: int = 400, xy: int = 10)[source]

Bases: object

3d matrix.

can_fall_down(box: BoxData) bool[source]

Whether a given box can fall downwards.

Parameters:

box (BoxData) – box to test

Returns:

True if the box can fall.

Return type:

bool

can_fly_up(box: BoxData) bool[source]

Check cells above our block. If they’re clear we can fly up.

get_hats(box: BoxData) set[BoxData][source]

Return which boxes are resting on this box.

get_supports(box: BoxData) set[BoxData][source]

Return which boxes are supporting this box.

layers: list[list[list[BoxData | None]]]
register_box(box: BoxData) None[source]

Register box into matrix.

class day22.lib.classes.Vector3(x: int, y: int, z: int)[source]

Bases: object

Simple 3d vector.

x: int
y: int
z: int

day22.lib.parsers module

Parse vectors/boxes from string to class.

day22.lib.parsers.get_boxes(path: str) list[BoxData][source]

Returns a wellformed box from a string.

E.g. 1,2,3~1,2,4

day22.lib.parsers.parse_vector(string: str) Vector3[source]

Returns a wellformed vector from a string.

e.g. 1,2,3

day22.lib.vis module

Visualization classes.

day22.lib.vis.animate_part1(boxes: list[BoxData], matrix: Matrix) None[source]

Animates part1.

day22.lib.vis.animate_part2(boxes: list[BoxData]) None[source]

Animates part2.

day22.lib.vis.bind_keys(on_key_down: Any) None[source]

Bind keyboard events, so that enter calls the given callback.

day22.lib.vis.construct_box(box_data: BoxData, color: vector) box[source]

Constructs a vpython box from a box_data.

Parameters:
  • box_data (BoxData) – box data to mimic

  • color (vpython.vector) – color of box for vis.

Returns:

a vpython.box

Return type:

vpython.box

day22.lib.vis.follow_block(y: float, box: BoxData) None[source]

Force camera to follow a block.

day22.lib.vis.init_vis(boxes: list[BoxData]) None[source]

Initialize vis boxes. Only called if we’re visualizing.

day22.lib.vis.random_color() vector[source]

Returns a random color compatible with vpython.

Module contents

Library classes for day22.