Track

With the track module, you can create, import, edit, save, and export tracks.

class track.Track(tiles, orient, name='track')

Bases: object

Representation of a track. An instance of the Track class is composed of three fields:

  • tiles: array which contains the number of each tile of the track

  • orient: array which indicates the orientation of each tile

  • name: name of the track

static read(file, name='track')

Read a text file representing a track and return the track associated.

Parameters:
  • file (str) – filename

  • name (str) – name of the track

Returns:

the track associated to the file

Return type:

Track

Raises:
static zeros(nrow, ncol, name='track')

Create an empty track.

Parameters:
  • nrow (int) – number of rows

  • ncol (int) – number of columns

  • name (str) – name of the track

Returns:

empty track (only zeros)

Return type:

Track

static max_shape(width, height)

Return the maximum number of rows and columns of a track limited by a width and a height in mm.

Parameters:
  • width (int) – width in mm

  • height (int) – height in mm

Returns:

number of rows and columns

Return type:

tuple of int

__init__(tiles, orient, name='track')

Init a track. The arguments tiles and orient must be numpy arrays. For example:

import numpy as np
from line_track_designer.track import Track

tiles = np.array([
    [3, 2, 3],
    [2, 11, 2],
    [3, 2, 3]
])
orient = np.array([
    [1, 1, 0],
    [0, 0, 0],
    [2, 1, 3]
])

track = Track(tiles, orient, 'my track')
Parameters:
  • tiles (numpy.array) – array of tiles

  • orient (numpy.array) – array of orientations

  • name (str) – name of the track

Raises:
property tiles

Get the array of tiles.

property orient

Get the array of orientations.

property name

Get the name of the track.

__str__()

Make the string format of the track. The tiles and orient matrix are superposed in one matrix. Each couple of values is separated by a semicolon.

With the last example, we obtain:

3;1 2;1 3;0
2;0 11;0 2;0
3;2 2;1 3;3
__repr__()

Make the repr format of the track. It’s the same than the string format.

add_col()

Add a column to the track. This column is filled with 0.

add_row()

Add a row to the track. This row is filled with 0.

del_col(col)

Delete a column from the track.

Parameters:

col (int) – index of the column to delete

del_row(row)

Delete a row from the track.

Parameters:

row (int) – index of the row to delete

set_tile(row, col, tile, orient)

Set a tile of the track.

Parameters:
  • row (int) – index of the row of the tile

  • col (int) – index of the column of the tile

  • tile (int) – number of the tile

  • orient (int) – orientation of the tile

Raises:

LineTrackDesignerError – invalid tile/orient value

rotate(k=1)

Rotate the track. The argument k is the number of times the array is rotated by 90 degrees.

Parameters:

k (int) – number of rotations (default: 1)

dimensions()

Return the dimensions in mm of the track.

Returns:

width and height in mm

Return type:

tuple of int

occurences()

Return the occurences of each tile used by the track. It returns a dictionary. The keys corresponds to the number of a tile and the values are the number of occurences.

Returns:

occurences

Return type:

dict

print_track()

Ask the printer to print the tiles to build the track.

export_img()

Export the track to image. It uses the PIL library.

Returns:

image of the track

Return type:

Image

show()

Displays the track with the PIL library. The image is in PNG format.

save_img(file)

Save the track as an image.

Parameters:

file (str) – filename

Raises:

LineTrackDesignerError – bad filename extension: use .png

save_txt(file)

Save the track as a text file. The content of the text file corresponds to the string format of the track.

Parameters:

file (str) – filename

Raises:

LineTrackDesignerError – bad filename extension: use .txt

save_md(file, description='')

Save the track as a markdown file. It also creates the PNG image associated to the track. The md file contains the following informtions:

  • name of the track

  • PNG image of the track

  • description of the track (optionnal)

  • dimensions (in mm)

  • tiles required to build the track

Parameters:
  • file (str) – filename (markdown file)

  • description (str) – description of the track

Raises:

LineTrackDesignerError – bad extension file: use .md