Base Class for Character-Based Art¶
This is the common base class for
sage.typeset.ascii_art.AsciiArt
and
sage.typeset.unicode_art.UnicodeArt
. They implement simple
graphics by placing characters on a rectangular grid, in other words,
using monospace fonts. The difference is that one is restricted to
7-bit ascii, the other uses all unicode code points.
- class sage.typeset.character_art.CharacterArt(lines=[], breakpoints=[], baseline=None)¶
Bases:
sage.structure.sage_object.SageObject
Abstract base class for character art
INPUT:
lines
– the list of lines of the representation of the character art objectbreakpoints
– the list of points where the representation can be splitbaseline
– the reference line (from the bottom)
Instead of just integers,
breakpoints
may also contain tuples consisting of an offset and the breakpoints of a nested substring at that offset. This is used to prioritize the breakpoints, as line breaks inside the substring will be avoided if possible.EXAMPLES:
sage: i = var('i') sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) pi*x e
- classmethod empty()¶
Return the empty character art object
EXAMPLES:
sage: from sage.typeset.ascii_art import AsciiArt sage: AsciiArt.empty()
- get_baseline()¶
Return the line where the baseline is, for example:
5 4 14*x + 5*x
the baseline has at line \(0\) and
{ o } { \ : 4 } { o }
has at line \(1\).
- get_breakpoints()¶
Return an iterator of breakpoints where the object can be split.
This method is deprecated, as its output is an implementation detail. The mere breakpoints of a character art element do not reflect the best way to split it if nested structures are involved. For details, see trac ticket #29204.
For example the expression:
5 4 14x + 5x
can be split on position 4 (on the
+
).EXAMPLES:
sage: from sage.typeset.ascii_art import AsciiArt sage: p3 = AsciiArt([" * ", "***"]) sage: p5 = AsciiArt([" * ", " * * ", "*****"]) sage: aa = ascii_art([p3, p5]) sage: aa.get_breakpoints() doctest:...: DeprecationWarning: get_breakpoints() is deprecated See https://trac.sagemath.org/29204 for details. [6]
- height()¶
Return the height of the ASCII art object.
OUTPUT:
Integer. The number of lines.
- split(pos)¶
Split the representation at the position
pos
.EXAMPLES:
sage: from sage.typeset.ascii_art import AsciiArt sage: p3 = AsciiArt([" * ", "***"]) sage: p5 = AsciiArt([" * ", " * * ", "*****"]) sage: aa = ascii_art([p3, p5]) sage: a,b= aa.split(6) sage: a [ [ * [ ***, sage: b * ] * * ] ***** ]
- width()¶
Return the length (width) of the ASCII art object.
OUTPUT:
Integer. The number of characters in each line.