Canvas
Module: terminaltexteffects.engine.terminal
Represent 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 |
bottom
|
int
|
bottom row of the canvas. Defaults to 1. |
1
|
left
|
int
|
left column of the canvas. Defaults to 1. |
1
|
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 |
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
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
bottom = 1
class-attribute
instance-attribute
int: bottom row of the canvas
left = 1
class-attribute
instance-attribute
int: left column of the canvas
right
instance-attribute
int: right column of the canvas
top
instance-attribute
int: top row of the canvas
__post_init__()
After initialization, calculate the center, width, height, and text dimensions of the canvas.
Source code in terminaltexteffects/engine/terminal.py
coord_is_in_canvas(coord)
Check 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) |