### Quick Start app with schema and config Source: https://tronbyt.com/pixlet/reference/schema/schema Adds get_schema() to the Hello World example. It defines a Text field and a Toggle field, and uses config.str and config.bool to customize the app. ```starlark load("render.star", "render") load("schema.star", "schema") DEFAULT_WHO = "World" def main(config): message = "Hello, %s!" % config.str("who", DEFAULT_WHO) if config.bool("small"): msg = render.Text(message, font = "CG-pixel-3x5-mono") else: msg = render.Text(message) return render.Root( child = msg, ) def get_schema(): return schema.Schema( version = "1", fields = [ schema.Text( id = "who", name = "Who?", desc = "Who to say hello to.", icon = "user", ), schema.Toggle( id = "small", name = "Display small text", desc = "A toggle to display smaller text.", icon = "compress", default = False, ), ], ) ``` -------------------------------- ### Install Tronbyt Server with Homebrew Source: https://tronbyt.com/getting-started Install and start the Tronbyt server service using Homebrew on macOS. ```bash brew install tronbyt-server brew services start tronbyt-server ``` -------------------------------- ### Test Docker installation Source: https://tronbyt.com/device-notes Tests the Docker installation. If successful, a message indicates Docker is running. ```bash docker run hello-world ``` -------------------------------- ### Install Docker on Raspberry Pi Source: https://tronbyt.com/device-notes Installs Docker using the official Docker script. Run after updating packages. ```bash curl -sSL https://get.docker.com | sh ``` -------------------------------- ### Run automatic Raspberry Pi setup script Source: https://tronbyt.com/device-notes Downloads and runs the automatic setup script for Tronbyt on a Raspberry Pi. Requires an internet connection and appropriate permissions. ```bash curl -fsSL https://raw.githubusercontent.com/tronbyt/server-docker-compose/main/rpi_setup.sh | bash ``` -------------------------------- ### Interactive pixlet create example Source: https://tronbyt.com/pixlet/publish/publishing-apps Example interactive session showing the prompts and sample answers for pixlet create. The Name can contain spaces but should not have numbers; Summary must be 27 characters or less; Description is a longer explanation. ```shell $ pixlet create Name (what do you want to call your app?): Tides Summary (what's the short and sweet of what this app does?): Tide charts Description (what's the long form of what this app does?): Daily tide charts for your location. Author (your name or your Github handle): Mark Spicer ``` -------------------------------- ### Push a graphic with an installation ID Source: https://tronbyt.com/pixlet/pushing-apps Pushes a graphic and creates an installation with the given installation ID, so the graphic enters the regular rotation of apps and becomes visible in the Tronbyt app. The graphic only changes when you push a new one. ```bash pixlet push --installation-id bitcoin "" examples/bitcoin.webp ``` -------------------------------- ### Hello World before adding schema Source: https://tronbyt.com/pixlet/reference/schema/schema Initial example that returns a simple render.Root with a text. It does not yet define a schema. ```starlark load("render.star", "render") def main(): return render.Root( child = render.Text("Hello, World!"), ) ``` -------------------------------- ### Run Pixlet in serve mode Source: https://tronbyt.com/pixlet/tutorials/crypto-tracker Starts a local development server with watch mode enabled for live updates. ```bash $ pixlet serve --watch examples/clock/clock.star ``` -------------------------------- ### Render Root Widget Source: https://tronbyt.com/pixlet/reference/modules Basic example of loading the render module and returning a Root widget containing a Box. ```starlark load("render.star", r="render") def main(): return r.Root(child=r.Box(width=12, height=14, color="#ff0")) ``` -------------------------------- ### Install Pixlet on macOS with Homebrew Source: https://tronbyt.com/pixlet/installing Run this command in your terminal after installing Homebrew to install the Pixlet CLI. ```bash brew install pixlet ``` -------------------------------- ### animation.Transformation example Source: https://tronbyt.com/pixlet/reference/animations A complete example of a Transformation widget animating a child circle using keyframes, rotation, and translation. ```python animation.Transformation( child = render.Box(render.Circle(diameter = 6, color = "#0f0")), duration = 100, delay = 0, origin = animation.Origin(0.5, 0.5), direction = "alternate", fill_mode = "forwards", keyframes = [ animation.Keyframe( percentage = 0.0, transforms = [animation.Rotate(0), animation.Translate(-10, 0), animation.Rotate(0)], curve = "ease_in_out", ), animation.Keyframe( percentage = 1.0, transforms = [animation.Rotate(360), animation.Translate(-10, 0), animation.Rotate(-360)], ), ], ), ``` -------------------------------- ### Deploy Tronbyt Server with Docker Compose Source: https://tronbyt.com/getting-started The recommended method for installing the Tronbyt server using Docker Compose. ```bash docker compose up -d ``` -------------------------------- ### Text Widget with Emojis App Example Source: https://tronbyt.com/pixlet/reference/emoji A complete Pixlet app example demonstrating how to include various emojis within a column layout. ```starlark load("render.star", "render") def main(): return render.Root( child = render.Column( children = [ render.Text("Weather: β˜€ 75Β°F", font="6x10"), render.Text("Status: βœ… Online", font="5x8"), render.Text("πŸŽ‰ Happy Birthday! πŸŽ‚", font="tb-8"), render.Text("πŸ‡ΊπŸ‡ΈπŸ‡¬πŸ‡§πŸ‡«πŸ‡·πŸ‡©πŸ‡ͺπŸ‡―πŸ‡΅", font="6x10"), ] ) ) ``` -------------------------------- ### Update Docker Installation Source: https://tronbyt.com/getting-started Pull the latest images and restart the containers for a Docker-based Tronbyt installation. ```bash docker compose pull && docker compose up -d ``` -------------------------------- ### Polygon widget example Source: https://tronbyt.com/pixlet/reference/widgets Creates a polygon widget with a list of (x, y) vertices, a fill color, stroke color, and stroke width. The vertices are required; all other attributes are optional. The example uses a blue fill and white stroke with a width of 1. ```python render.Polygon( vertices = [(0, 0), (20, 0), (20, 10), (0, 10)], fill_color = "#00f", stroke_color = "#fff", stroke_width = 1, ) ``` -------------------------------- ### Example Locale: locales/es.json Source: https://tronbyt.com/pixlet/reference/i18n A sample JSON file mapping message keys to Spanish translations using Go fmt.Sprintf verbs. ```json { "hello_user": "Hola, %s", "unread_count": "%d mensajes sin leer" } ``` -------------------------------- ### Stack widget example Source: https://tronbyt.com/pixlet/reference/widgets Draws children on top of each other, sized to fit all children. Requires the `children` attribute. ```python render.Stack( children=[ render.Box(width=50, height=25, color="#911"), render.Text("hello there"), render.Box(width=4, height=32, color="#119"), ], ) ``` -------------------------------- ### Install Pixlet on Linux from release archive Source: https://tronbyt.com/pixlet/installing Downloads the Pixlet binary archive, unpacks it, makes it executable, and moves it into the PATH. The version in the commands is v0.52.0. ```bash # Download the archive. curl -LO https://github.com/tronbyt/pixlet/releases/download/v0.52.0/pixlet_v0.52.0_linux_amd64.tar.gz # Unpack the archive. tar -xvf pixlet_0.22.4_linux_amd64.tar.gz # Ensure the binary is executable. chmod +x ./pixlet # Move the binary into your path. sudo mv pixlet /usr/local/bin/pixlet ``` -------------------------------- ### Column widget basic example Source: https://tronbyt.com/pixlet/reference/widgets Lays out child widgets vertically in a column. By default the column is as small as possible while holding all children, and its width equals the widest child. This example uses three boxes with different sizes. ```python render.Column( children=[ render.Box(width=10, height=8, color="#a00"), render.Box(width=14, height=6, color="#0a0"), render.Box(width=16, height=4, color="#00a"), ], ) ``` -------------------------------- ### Push a Pixlet app to a Tronbyt device Source: https://tronbyt.com/pixlet/getting-started This sequence shows the Pixlet CLI commands to render the bitcoin example, login to the Tronbyt account, list devices, and push the rendered WebP to a target device. The device ID can be obtained from 'pixlet devices'. Commands run on your computer; the device only receives the rendered WebP or GIF. ```bash # render the bitcoin example pixlet render examples/bitcoin.star # login to your Tronbyt account pixlet login # list available Tronbyt devices pixlet devices # push to your favorite Tronbyt pixlet push examples/bitcoin.webp ``` -------------------------------- ### Update Homebrew Installation Source: https://tronbyt.com/getting-started Upgrade the Tronbyt server package and restart the service via Homebrew. ```bash brew upgrade tronbyt-server && brew services restart tronbyt-server ``` -------------------------------- ### Sequence widget example Source: https://tronbyt.com/pixlet/reference/widgets Renders a list of child widgets in sequence, each for its frame count. Requires the `children` attribute. Useful for chaining animations. ```python render.Sequence( children = [ render.Box(width=10, height=10, color="#f00"), render.Box(width=10, height=10, color="#0f0"), render.Box(width=10, height=10, color="#00f"), ], ) ``` -------------------------------- ### Generate a QR code with qrcode.generate Source: https://tronbyt.com/pixlet/reference/modules This example demonstrates how to generate a QR code, cache it, and display it using the render.Image widget. Note that the amount of data for the URL is extremely limited due to the small QR code sizes. ```starlark load("cache.star", "cache") load("encoding/base64.star", "base64") load("render.star", "render") load("qrcode.star", "qrcode") def main(config): url = "https://tronbyt.com?utm_source=pixlet_example" data = cache.get(url) if data == None: code = qrcode.generate( url = url, size = "large", color = "#fff", background = "#000", ) cache.set(url, base64.encode(code), ttl_seconds = 3600) else: code = base64.decode(data) return render.Root( child = render.Padding( child = render.Image(src = code), pad = 1, ), ) ``` -------------------------------- ### Plot widget example Source: https://tronbyt.com/pixlet/reference/widgets Draws a line plot with a data series of 2-tuples. The example sets width, height, line color, inverted color for negative values, axis limits, and enables fill. ```python render.Plot( data = [ (0, 3.35), (1, 2.15), (2, 2.37), (3, -0.31), (4, -3.53), (5, 1.31), (6, -1.3), (7, 4.60), (8, 3.33), (9, 5.92), ], width = 64, height = 32, color = "#0f0", color_inverted = "#f00", x_lim = (0, 9), y_lim = (-5, 7), fill = True, ) ``` -------------------------------- ### Column widget expanded alignment example Source: https://tronbyt.com/pixlet/reference/widgets Creates a column that expands to fill available vertical space, with children spaced evenly along the main axis and centered along the cross axis. The example uses three boxes with different sizes. ```python render.Column( expanded=True, main_align="space_around", cross_align="center", children=[ render.Box(width=10, height=8, color="#a00"), render.Box(width=14, height=6, color="#0a0"), render.Box(width=16, height=4, color="#00a"), ], ) ``` -------------------------------- ### Location config output format Source: https://tronbyt.com/pixlet/reference/schema/schema Example output of config.get("location") for a Location field. Shows the format of the returned location data. ```json { "lat": "40.6781784", "lng": "-73.9441579", "description": "Brooklyn, NY, USA", "locality": "Brooklyn", "place_id": "ChIJCSF8lBZEwokRhngABHRcdoI", "timezone": "America/New_York" } ``` -------------------------------- ### Providing a default config value Source: https://tronbyt.com/pixlet/authoring-apps Ensures the app always renders even if a config value is not provided by supplying a default. This example guarantees a value for 'who' using config.get() with a default. ```starlark DEFAULT_WHO = "world" def main(config): who = config.get("who", DEFAULT_WHO) print("Hello, %s" % who) ``` -------------------------------- ### Decode YAML with yaml.decode Source: https://tronbyt.com/pixlet/reference/modules This example shows how to use the yaml.decode function to parse a YAML-formatted string into a dictionary for use in a Pixlet app. ```starlark load("encoding/yaml.star", "yaml") load("render.star", "render") EXAMPLE_YAML = "message: Hello, world!" def main(config): data = yaml.decode(EXAMPLE_YAML) return render.Root(render.Text(data["message"])) ``` -------------------------------- ### File object reading Source: https://tronbyt.com/pixlet/reference/modules Example of reading binary and text files using the File object to render content in a Pixlet app. ```starlark load("render.star", "render") load("icon.png", icon_file = "file") load("message.txt", message_file = "file") ICON = icon_file.readall("rb") MESSAGE = message_file.readall() def main(): return render.Root( child = render.Row( children = [ render.Image(src=ICON), render.Text(MESSAGE), ], ), ) ``` -------------------------------- ### Update Raspberry Pi packages Source: https://tronbyt.com/device-notes Updates the package list and upgrades all existing packages on the Raspberry Pi. Run before installing Docker. ```bash sudo apt update sudo apt upgrade -y ``` -------------------------------- ### Create an animation with render.Animation Source: https://tronbyt.com/pixlet/reference/widgets Creates an animation by passing a list of children as frames. Each child is rendered as a separate frame. The example uses five boxes of increasing size and color. ```python render.Animation( children=[ render.Box(width=10, height=10, color="#300"), render.Box(width=12, height=12, color="#500"), render.Box(width=14, height=14, color="#700"), render.Box(width=16, height=16, color="#900"), render.Box(width=18, height=18, color="#b00"), ], ) ``` -------------------------------- ### PieChart widget example Source: https://tronbyt.com/pixlet/reference/widgets Creates a circular pie chart with parallel lists of colors and weights. The diameter attribute sets the circle size, and the weights determine the relative size of each color segment. ```python render.PieChart( colors = [ "#fff", "#0f0", "#00f" ], weights = [ 180, 135, 45 ], diameter = 30, ) ``` -------------------------------- ### Serve the Pixlet applet with pixlet serve Source: https://tronbyt.com/pixlet/getting-started Runs the hello world applet locally with 'pixlet serve'. The result can be viewed at http://localhost:8080. ```bash pixlet serve hello_world.star ``` -------------------------------- ### Build and Run Tronbyt Server from Source Source: https://tronbyt.com/getting-started Compile the server from source code and execute the resulting binary. ```bash go build -o tronbyt-server ./cmd/server ./tronbyt-server ``` -------------------------------- ### Circle widget example Source: https://tronbyt.com/pixlet/reference/widgets Draws a circle with a given diameter and fill color. The optional child widget is centered inside the circle. The example uses a nested circle as the child. ```python render.Circle( color="#666", diameter=30, child=render.Circle(color="#0ff", diameter=10), ) ``` -------------------------------- ### Basic main() with config.get Source: https://tronbyt.com/pixlet/authoring-apps Shows the basic structure of a Pixlet app's main() function, receiving a config object and using config.get() to retrieve a value. The config values can be set via URL query parameters with pixlet serve or command-line arguments with pixlet render. ```starlark def main(config): who = config.get("who") print("Hello, %s" % who) ``` -------------------------------- ### FlipVertical filter example Source: https://tronbyt.com/pixlet/reference/filters Flips the child widget vertically. Requires a child widget. ```unknown filter.FlipVertical( child = render.Image(src="...", width=64, height=64), ) ``` -------------------------------- ### FlipHorizontal filter example Source: https://tronbyt.com/pixlet/reference/filters Flips the child widget horizontally. Requires a child widget. ```unknown filter.FlipHorizontal( child = render.Image(src="...", width=64, height=64), ) ``` -------------------------------- ### Preview app with pixlet serve Source: https://tronbyt.com/pixlet/publish/publishing-apps Run from the local clone of the Tronbyt apps repo to preview your app in the browser at http://localhost:8080/. ```shell pixlet serve apps/{{appname}}/{{app_name}}.star ``` -------------------------------- ### Pad strings with strings.pad Source: https://tronbyt.com/pixlet/reference/modules Demonstrates how to pad a string to a minimum length using the strings.pad function, with options for alignment and padding character. ```starlark load("strings.star", "strings") def main(): print(strings.pad("foo", 5)) # Output: "foo " print(strings.pad("foo", 5, "end")) # Output: " foo" ``` -------------------------------- ### Emboss filter example Source: https://tronbyt.com/pixlet/reference/filters Applies an emboss filter to a child widget. Requires a child widget. ```unknown filter.Emboss( child = render.Image(src="...", width=64, height=64), ) ``` -------------------------------- ### Hello World Starlark applet Source: https://tronbyt.com/pixlet/tutorials/crypto-tracker A basic Pixlet applet that displays text on the screen using the render library. ```python load("render.star", "render") def main(): return render.Root( child = render.Text("Hello, World!") ) ``` -------------------------------- ### Hello World Pixlet applet in Starlark Source: https://tronbyt.com/pixlet/getting-started Starlark applet for Tronbyt using Pixlet. Loads the render module and defines a main function that returns a render.Root with a render.Text child. Save and run with 'pixlet serve hello_world.star'. ```starlark load("render.star", "render") def main(): return render.Root( child = render.Text("Hello, World!") ) ``` -------------------------------- ### Render a Pixlet app to webp Source: https://tronbyt.com/pixlet/pushing-apps Renders a Pixlet app (e.g., examples/bitcoin.star) to a webp image. Run this before pushing the graphic to your Tronbyt. ```bash pixlet render examples/bitcoin.star ``` -------------------------------- ### Render and serve at 2x with pixlet -2 flag Source: https://tronbyt.com/pixlet/reference/2x-apps Renders and serves an app at 2x resolution (128x64). The render command automatically adds a @2x suffix to the output filename if none is specified. ```shell pixlet render -2 my_app.star pixlet serve -2 my_app.star ``` -------------------------------- ### Generate a new app with pixlet create Source: https://tronbyt.com/pixlet/publish/publishing-apps Run from the local clone of the Tronbyt apps repo to generate the required files and folders for a new app. You will be prompted for the app's name, summary, description, and author. ```shell pixlet create ``` -------------------------------- ### Basic Emoji Usage in render.Text Source: https://tronbyt.com/pixlet/reference/emoji Examples of using emojis within render.Text widgets, including mixed content and multiple emojis. ```starlark # Basic usage render.Text("Hello World!", font="6x10") # Multiple emojis render.Text("πŸŽ‰πŸŽŠπŸŽˆπŸŽ", font="5x8") # Mixed content render.Text("Weather: β˜€οΈ 75Β°F", font="tb-8") ``` -------------------------------- ### Translating strings in Starlark Source: https://tronbyt.com/pixlet/reference/i18n Example of loading the i18n.star module and using the tr helper to localize text within a main function. ```starlark load("i18n.star", "tr") load("render.star", "render") def main(config): user = config.get("user", "Tronbyt") return render.Root( child = render.Text( content = tr("hello_user", user), ), ) ``` -------------------------------- ### File module asset loading Source: https://tronbyt.com/pixlet/reference/modules Shows how to load a local file as an asset by aliasing the file identifier. ```starlark load("my_image.png", img = "file") ``` -------------------------------- ### Config type conversion helpers Source: https://tronbyt.com/pixlet/authoring-apps Shows config.str() and config.bool() helpers that convert config values to specific types, returning None if not found. ```starlark config.str("foo") # returns a string, or None if not found config.bool("foo") # returns a boolean (True or False), or None if not found ``` -------------------------------- ### schema.Color with palette Source: https://tronbyt.com/pixlet/reference/schema/schema Defines a schema with a Color field that includes an optional palette parameter to guide users towards reasonable color options. ```python def get_schema(): return schema.Schema( version = "1", fields = [ schema.Color( id = "color", name = "Color", desc = "Color of the screen.", icon = "brush", default = "#7AB0FF", palette = [ "#7AB0FF", "#BFEDC4", "#78DECC", "#DBB5FF", ], ), ], ) ``` -------------------------------- ### EdgeDetection filter example Source: https://tronbyt.com/pixlet/reference/filters Applies an edge detection filter to a child widget. Requires a child widget and a radius value for the edge detection kernel. ```unknown filter.EdgeDetection( child = render.Image(src="...", width=64, height=64), radius = 2.0, ) ``` -------------------------------- ### Text widget example Source: https://tronbyt.com/pixlet/reference/widgets Draws a string of text on a single line. Defaults to the "tb-8" font; `height` and `offset` fine-tune vertical layout. ```python render.Text(content="Tronbyt!", color="#099") ``` -------------------------------- ### Run Pixlet CLI render Source: https://tronbyt.com/pixlet/tutorials/crypto-tracker Executes the Pixlet CLI to render a Starlark file into a WebP image. ```bash $ pixlet render examples/clock/clock.star ``` -------------------------------- ### Enable 2x support in manifest with supports2x: true Source: https://tronbyt.com/pixlet/reference/2x-apps Manifest file that enables 2x support by setting supports2x to true. This flag is read by pixlet to indicate the app is designed for 2x resolutions. ```yaml id: my-app name: My App summary: An example app desc: This is a longer description. author: Your Name supports2x: true ``` -------------------------------- ### Gamma filter example Source: https://tronbyt.com/pixlet/reference/filters Applies gamma correction to a child widget. Requires a child widget and a gamma value; 1.0 is no change, < 1.0 darkens, > 1.0 lightens. ```unknown filter.Gamma( child = render.Image(src="...", width=64, height=64), gamma = 0.5, ) ``` -------------------------------- ### Verify rendered file Source: https://tronbyt.com/pixlet/tutorials/crypto-tracker Uses the file command to verify the output format of the generated WebP image. ```bash $ file examples/clock/clock.webp examples/clock/clock.webp: RIFF (little-endian) data, Web/P image ``` -------------------------------- ### Load assets from local files Source: https://tronbyt.com/pixlet/tutorials/crypto-tracker Alternative method to load an image asset directly from the application directory instead of using base64 encoding. ```starlark # Load Bitcoin icon from file load("img/tutorial_bitcoin.png", btc_icon_file = "file") BTC_ICON = btc_icon_file.readall() ``` -------------------------------- ### SSH into Raspberry Pi Source: https://tronbyt.com/device-notes Connects to the Raspberry Pi over SSH using the username and hostname configured during OS setup. Run from a command prompt on Windows 10/11, macOS, or Linux. ```bash ssh username@hostname ``` -------------------------------- ### render.Arc: Draw an arc Source: https://tronbyt.com/pixlet/reference/widgets Draws an arc centered at (x, y) with the given radius, start and end angles in radians, stroke width, and color. The antialias attribute is optional and defaults to false. ```python render.Arc( x = 10, y = 10, radius = 10, start_angle = 0, end_angle = 3.14 * 1.5, width = 3, color = "#0ff", ) ```