Base Class for Character-Based Art¶
This is the common base class for
sage.typeset.ascii_art.AsciiArt
and
sage.typeset.ascii_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, atomic=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)
EXAMPLES:
sage: i = var('i') sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) pi*x e
TESTS:
sage: from sage.typeset.ascii_art import AsciiArt sage: aao = AsciiArt() sage: aao <BLANKLINE> sage: aa = AsciiArt([" * ", " * * ", "*****"]); aa * * * *****
-
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\).
TESTS:
sage: from sage.typeset.ascii_art import AsciiArt sage: aa = AsciiArt([" * ", " * * ", " * * ", "*******"], baseline=1);aa * * * * * ******* sage: aa.get_baseline() 1 sage: b = AsciiArt(["<-"]) sage: aa+b * * * * * <- *******
-
get_breakpoints
()¶ Return an iterator of breakpoints where the object can be split.
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() [6]
-
height
()¶ Return the height of the ASCII art object.
OUTPUT:
Integer. The number of lines.
TESTS:
sage: from sage.typeset.ascii_art import AsciiArt sage: p3 = AsciiArt([" * ", "***"]) sage: p3.height() 2 sage: p5 = AsciiArt([" * ", " * * ", "*****"]) sage: p5.height() 3
-
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.
TESTS:
sage: from sage.typeset.ascii_art import AsciiArt sage: p3 = AsciiArt([" * ", "***"]) sage: len(p3), p3.width(), p3.height() (3, 3, 2) sage: p5 = AsciiArt([" * ", " * * ", "*****"]) sage: len(p5), p5.width(), p5.height() (5, 5, 3)