| Title: | Tiny Graphics Engine for an R Frame Buffer |
|---|---|
| Description: | A cross-platform graphics device which offers simple update via pre-rendered images with keyboard and mouse feedback. |
| Authors: | Mike Cheng [aut, cre, cph], Erik Agsjo [aut] (Author of include 'tigr' library) |
| Maintainer: | Mike Cheng <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-07-06 23:16:33 UTC |
| Source: | https://github.com/coolbutuseless/tigerfb |
Capture the current window contents to a native raster image
fb_capture(window)fb_capture(window)
window |
window handle as created by |
A native raster image
Other capturing functions:
fb_save_png()
window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) nr <- fb_capture(window) Sys.sleep(3) fb_close(window) class(nr)window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) nr <- fb_capture(window) Sys.sleep(3) fb_close(window) class(nr)
This will reconnect to the specified window and prompt the user to close the window.
fb_close(window)fb_close(window)
window |
window handle as created by |
None
Other core window functions:
fb_open(),
fb_update()
window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) Sys.sleep(3) fb_close(window)window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) Sys.sleep(3) fb_close(window)
This demo generates an animation of an evolving bubble universe.
fb_demo(...)fb_demo(...)
... |
arguments passed to |
Press 'ESC' key to quit, and then close the window.
None
fb_demo(mode = 'fullscreen')fb_demo(mode = 'fullscreen')
Clear window
fb_fill(window, fill)fb_fill(window, fill)
window |
window handle as created by |
fill |
Fill color. Default: NA (transparent) |
None
Other drawing commands:
fb_line(),
fb_rect(),
fb_text()
window <- fb_open(100, 100) fb_fill(window, 'hotpink') fb_update(window) Sys.sleep(3) fb_close(window)window <- fb_open(100, 100) fb_fill(window, 'hotpink') fb_update(window) Sys.sleep(3) fb_close(window)
Check if a window is currently open and active
fb_is_open(window)fb_is_open(window)
window |
window handle as created by |
Logical value
window <- fb_open() fb_is_open(window) fb_close(window) fb_is_open(window)window <- fb_open() fb_is_open(window) fb_close(window) fb_is_open(window)
fb_state()
Get the list of key names which are returned by fb_state()
fb_key_names()fb_key_names()
character vector
Draw Line
fb_line(window, x1, y1, x2, y2, color = "black")fb_line(window, x1, y1, x2, y2, color = "black")
window |
window handle as created by |
x1, y1, x2, y2
|
line coordinates |
color |
Color. Default: 'black' |
None
Other drawing commands:
fb_fill(),
fb_rect(),
fb_text()
window <- fb_open(100, 100) fb_line(window, 0, 0, 50, 50, 'hotpink') fb_update(window) Sys.sleep(3) fb_close(window)window <- fb_open(100, 100) fb_line(window, 0, 0, 50, 50, 'hotpink') fb_update(window) Sys.sleep(3) fb_close(window)
Initialise an interactive window
fb_open( width = 150, height = 100, mode = "auto", expand = 2, cursor = TRUE, title = "R" )fb_open( width = 150, height = 100, mode = "auto", expand = 2, cursor = TRUE, title = "R" )
width, height
|
Initial window dimensions (in pixels) |
mode |
Window mode. Valid values:'auto', 'fixed', 'fullscreen'. Default: "auto" resizes the underlying image canvas when image is resized. "fixed" always keeps the same sized image canvas, but applies an integer scaling factor to maximize the display within the window. |
expand |
Integer value to expand pixel size. Only valid when |
cursor |
show the cursor? Default: TRUE |
title |
window title. Default: "R" |
Window handle
Other core window functions:
fb_close(),
fb_update()
window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) Sys.sleep(3) fb_close(window)window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) Sys.sleep(3) fb_close(window)
Draw rectangle
fb_rect(window, x, y, w, h, color = "black", fill = NA)fb_rect(window, x, y, w, h, color = "black", fill = NA)
window |
window handle as created by |
x, y, w, h
|
location and dimensions of rectangle |
color |
Outline color. Default: 'black' |
fill |
Fill color. Default: NA (transparent) |
None
Other drawing commands:
fb_fill(),
fb_line(),
fb_text()
window <- fb_open(100, 100) fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) Sys.sleep(3) fb_close(window)window <- fb_open(100, 100) fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) Sys.sleep(3) fb_close(window)
Capture the current window contents to a PNG file
fb_save_png(window, filename)fb_save_png(window, filename)
window |
window handle as created by |
filename |
PNG filename |
None
Other capturing functions:
fb_capture()
window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) png_file <- tempfile(fileext = ".png") fb_save_png(window, png_file) Sys.sleep(3) fb_close(window)window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) png_file <- tempfile(fileext = ".png") fb_save_png(window, png_file) Sys.sleep(3) fb_close(window)
Get the state of the current window i.e. keys and mouse
fb_state(window)fb_state(window)
window |
window handle as created by |
environment of 'mouse' and 'key' information
mouse$coordsinteger vector of (x,y) coordinates
mouse$buttonsinteger vector of the state of three mouse buttons.
Value represents the state of the button. See ?press_state for details
keynamed integer vector of all keycodes. Value represents
the state of the key. See ?press_state for details
window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) for (i in seq(30)) { fb_update(window) state <- fb_state(window) print(state$mouse$coords) Sys.sleep(0.1) } print(state) fb_close(window)window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) for (i in seq(30)) { fb_update(window) state <- fb_state(window) print(state$mouse$coords) Sys.sleep(0.1) } print(state) fb_close(window)
Draw Text using built-in font
fb_text(window, x, y, text, color = "white")fb_text(window, x, y, text, color = "white")
window |
window handle as created by |
x, y
|
position |
text |
string |
color |
Color. Default: 'white' |
None
Other drawing commands:
fb_fill(),
fb_line(),
fb_rect()
window <- fb_open(100, 100) fb_text(window, 6, 42, "Hello #RStats!") fb_update(window) Sys.sleep(3) fb_close(window)window <- fb_open(100, 100) fb_text(window, 6, 42, "Hello #RStats!") fb_update(window) Sys.sleep(3) fb_close(window)
Execute any queued drawing commands. User can also provide a new native raster image which will replace the current window contents
fb_update(window, nr = NULL)fb_update(window, nr = NULL)
window |
window handle as created by |
nr |
(optional) native raster image the same dimensions as the window. This will be rendered over the top of the current contents of the window. Default: NULL means to only process the drawing queue, and update the keyboard and mouse state. |
None
Other core window functions:
fb_close(),
fb_open()
window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) Sys.sleep(3) fb_close(window)window <- fb_open() fb_rect(window, 10, 10, 70, 30, 'hotpink', 'blue') fb_update(window) Sys.sleep(3) fb_close(window)
Keys and mouse buttons may be 4 different states - not pressed, held down, has just transitioned from not-pressed-to-pressed, and has just transitioned from pressed-to-not-pressed.
press_statepress_state
There 4 possible key states returned by fb_state(). For simple
keyboard/mouse scanning the user need only check if the state is non-zero to
indicate that the key or mouse button has been pressed.
For some complex handling, the user-interface may need to watch for a transition event i.e. from-pressed-to-not-pressed, or from-not-pressed-to-pressed (e.g. keyboard control in Doom)
0 = INACTIVEThe key/button is not pressed
1 = DOWNThe key/button has just now been pressed down
2 = HELDThe key/button is being held down
3 = UPThe key/button was being held but has just now been released
press_state[["INACTIVE"]] press_state[["DOWN"]] press_state[["HELD"]] press_state[["UP"]]press_state[["INACTIVE"]] press_state[["DOWN"]] press_state[["HELD"]] press_state[["UP"]]
More palatable printing of a 'state' environment
## S3 method for class 'tigerfb_state' print(x, ...)## S3 method for class 'tigerfb_state' print(x, ...)
x |
state object returned by |
... |
ignored |
original x