graphics
Draw on the screen. The origin is the top-left corner: the CE screen is 320 by 240 pixels, and the classic screen is 96 by 64.
from ti84 import graphics
graphics.begin()
graphics.fill_screen(graphics.WHITE)
graphics.fill_circle(160, 120, 30, graphics.RED)
graphics.text("HELLO", 10, 10)
graphics.wait_key()
graphics.end()
Literal and runtime arguments
Arguments can be variables or expressions. When every argument is a constant, the compiler works out the drawing ahead of time. Otherwise it calls a routine at runtime, which clips to the screen. This means off-screen values behave differently:
With runtime values, whatever falls off the screen is clipped.
With literal values, an off-screen pixel, line, outline, or circle is a compile error, because it is almost certainly a mistake.
Colors
On CE, colors are 16-bit RGB565 values. On classic, a color is 0 for white, and
anything else is black. The constants below work on both targets, and on classic each
becomes 0 for WHITE and 1 for anything else.
Warning
The literal 0 is black on CE and white on classic. Use graphics.BLACK and
graphics.WHITE in programs that build for both targets.
Without a color argument, shapes and text are black. Every shape also accepts
color= as a keyword.
Text
text() takes pixel coordinates on every target,
including Flash Apps. With origin="center", the text is centered on the screen
using the font’s real width and height, and x and y move it from the center:
from ti84 import graphics
graphics.begin()
graphics.clear()
graphics.text("Hello world!", 0, 0, origin="center")
graphics.wait_key()
graphics.end()
On CE, clear() clears the whole screen, status bar
included, and end() brings back the home screen and
its status bar.
Scrolling
On CE, scroll() moves the pixels already on the
screen instead of redrawing them. It moves a rectangle up by dy rows, or down
when dy is negative, and fills the strip it uncovers with fill; the default
of -1 leaves that strip as it was. Whole rows move at once, and a full-width area
moves in a single copy, so it is much faster than clearing and drawing again, and
it does not flicker.
from ti84 import graphics
# A log from y = 20 to the bottom: make room for one 10-pixel line at the bottom.
graphics.scroll(0, 20, 320, 220, 10, graphics.WHITE)
The screen is not double-buffered: everything draws straight to the visible screen.
Redraw only what changes, and use scroll() to
move the rest.
Screen size
- width
Screen width in pixels: 320 on CE, and 96 on classic.
- height
Screen height in pixels: 240 on CE, and 64 on classic.
Methods
- begin()
Prepare the screen for drawing.
- Targets:
CE, Classic, Flash App
graphics.begin()
- end()
Restore the OS screen state.
- Targets:
CE, Classic, Flash App
graphics.end()
- clear()
Clear the whole screen to white, status bar included.
- Targets:
CE, Classic, Flash App
graphics.clear()
- fill_screen(color=WHITE)
Fill the whole screen with a color.
- Targets:
CE, Classic, Flash App
graphics.fill_screen(graphics.WHITE)
- pixel(x, y, color=BLACK)
Set one pixel; off-screen runtime positions are clipped.
- Targets:
CE, Classic, Flash App
graphics.pixel(x, y, graphics.RED)
- get_pixel(x, y) int
Read a pixel’s RGB565 color.
- Targets:
CE, Flash App
- Note:
Reading pixels needs the CE target.
z = graphics.get_pixel(x, y)
- line(x1, y1, x2, y2, color=BLACK)
Draw a line.
- Targets:
CE, Classic, Flash App
graphics.line(x, y, 5, 5, graphics.RED)
- rect(x, y, width, height, color=BLACK)
Draw an outline covering x..x+width inclusive.
- Targets:
CE, Classic, Flash App
graphics.rect(x, y, 5, 5, graphics.RED)
- rectangle(x, y, width, height, color=BLACK)
Draw an outline exactly width by height pixels.
- Targets:
CE, Classic, Flash App
graphics.rectangle(x, y, 5, 5, graphics.RED)
- fill_rect(x, y, width, height, color=BLACK)
Draw a filled rectangle, clipped to the screen.
- Targets:
CE, Classic, Flash App
graphics.fill_rect(x, y, 5, 5, graphics.RED)
- fill_rectangle(x, y, width, height, color=BLACK)
Same as fill_rect.
- Targets:
CE, Classic, Flash App
graphics.fill_rectangle(x, y, 5, 5, graphics.RED)
- triangle(x1, y1, x2, y2, x3, y3, color=BLACK)
Draw a filled triangle.
- Targets:
CE, Classic, Flash App
graphics.triangle(x, y, 9, 0, 0, 9, graphics.RED)
- circle(x, y, radius, color=BLACK)
Draw a circle outline.
- Targets:
CE, Classic, Flash App
graphics.circle(x, y, 5, graphics.RED)
- fill_circle(x, y, radius, color=BLACK)
Draw a filled circle.
- Targets:
CE, Classic, Flash App
graphics.fill_circle(x, y, 5, graphics.RED)
- horiz_line(x, y, length, color=BLACK)
Draw a fast horizontal line.
- Targets:
CE, Classic, Flash App
graphics.horiz_line(x, y, 5, graphics.RED)
- vert_line(x, y, length, color=BLACK)
Draw a fast vertical line.
- Targets:
CE, Classic, Flash App
graphics.vert_line(x, y, 5, graphics.RED)
- text(string, x, y, color=BLACK, *, origin='top_left')
Draw a string at pixel x, y. origin=’center’ centers it, and x, y then offset it. Runtime coordinates need the CE target.
- Targets:
CE, Classic, Flash App
- Flash App form:
text(string, x, y, origin)
graphics.text('HI', 0, 0, origin='center')
- char(code, x, y, color=BLACK, background=WHITE)
Draw one character from its code, such as 65 for A, at pixel x, y in the OS font.
- Targets:
CE, Flash App
- Note:
The classic target draws literal text only; use graphics.text.
graphics.char(x, y, 20, graphics.RED)
- scroll(x, y, width, height, dy, fill=-1)
Move a rectangle’s pixels up by dy rows (down when dy is negative), then fill the uncovered strip with fill unless it is -1. Fast: whole rows move at once.
- Targets:
CE, Flash App
- Note:
The classic screen cannot scroll yet.
graphics.scroll(0, 20, 320, 200, 10, graphics.WHITE)
- text_int(value, x, y, color=BLACK)
Draw an integer, such as a score.
- Targets:
CE, Flash App
- Flash App form:
text_int(value, x, y)- Note:
The classic target draws text from literal coordinates; use graphics.text with constants.
graphics.text_int(score, x, y)
- sprite(pixels, x, y)
Draw literal RGB565 rows; None is transparent.
- Targets:
CE, Classic
graphics.sprite(((1, 2), (3, None)), x, y)
- delay(count)
Busy-wait for a count from 1 to 65535.
- Targets:
CE, Classic, Flash App
graphics.delay(x)
- wait_key()
Wait for a key press.
- Targets:
CE, Classic, Flash App
graphics.wait_key()
- set_color(color) int
Set the Flash App’s current color.
- Targets:
Flash App
- Note:
Pass the color to each drawing call instead.
- save_cursor(x, y)
Save the 12 by 16 pixel screen area at x, y, so a cursor can be drawn over it.
- Targets:
Flash App
- Note:
Redraw what a cursor covered yourself.
- restore_cursor()
Put back the area saved by save_cursor().
- Targets:
Flash App
- Note:
Redraw what a cursor covered yourself.
Color constants
Constant |
RGB565 value |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|