Canvas
Module: terminaltexteffects.engine.terminal
Represents the canvas in the terminal. The canvas is the area defined by the dimensions of the input data, unless specified otherwise in the TerminalConfig.
This class provides methods for working with the canvas, such as checking if a coordinate is within the canvas, getting random coordinates within the canvas, and getting a random coordinate outside the canvas.
This class also provides attributes for the dimensions of the canvas, the extents of the text within the canvas, and the center of the canvas.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
top |
int
|
top row of the canvas |
required |
right |
int
|
right column of the canvas |
required |
Attributes:
Name | Type | Description |
---|---|---|
top |
int
|
top row of the canvas |
right |
int
|
right column of the canvas |
bottom |
int
|
bottom row of the canvas |
left |
int
|
left column of the canvas |
center_row |
int
|
row of the center of the canvas |
center_column |
int
|
column of the center of the canvas |
center |
Coord
|
coordinate of the center of the canvas |
width |
int
|
width of the canvas |
height |
int
|
height of the canvas |
text_left |
int
|
left column of the text within the canvas |
text_right |
int
|
right column of the text within the canvas |
text_top |
int
|
top row of the text within the canvas |
text_bottom |
int
|
bottom row of the text within the canvas |
text_width |
int
|
width of the text within the canvas |
text_height |
int
|
height of the text within the canvas |
text_center_row |
int
|
row of the center of the text within the canvas |
text_center_column |
int
|
column of the center of the text within the canvas |
Methods:
Name | Description |
---|---|
coord_is_in_canvas |
Coord) -> bool: Checks whether a coordinate is within the canvas. |
random_column |
Get a random column position within the canvas. |
random_row |
Get a random row position within the canvas. |
random_coord |
Get a random coordinate within or outside the canvas. |
Source code in terminaltexteffects/engine/terminal.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
bottom: int = 1
class-attribute
instance-attribute
int: bottom row of the canvas
left: int = 1
class-attribute
instance-attribute
int: left column of the canvas
right: int
instance-attribute
int: right column of the canvas
top: int
instance-attribute
int: top row of the canvas
coord_is_in_canvas(coord)
Checks whether a coordinate is within the canvas.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coord |
Coord
|
coordinate to check |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether the coordinate is within the canvas |
Source code in terminaltexteffects/engine/terminal.py
random_column()
Get a random column position. Position is within the canvas.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
a random column position (1 <= x <= canvas.right) |
random_coord(outside_scope=False)
Get a random coordinate. Coordinate is within the canvas unless outside_scope is True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outside_scope |
bool
|
whether the coordinate should fall outside the canvas. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Coord |
Coord
|
a random coordinate . Coordinate is within the canvas unless outside_scope is True. |
Source code in terminaltexteffects/engine/terminal.py
random_row()
Get a random row position. Position is within the canvas.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
a random row position (1 <= x <= terminal.canvas.top) |