Ember is a minimalistic Rust library for creating 2D graphics, games, and interactive visualizations with ease and simplicity.

Overview

Ember

Ember is a simple and fun 2D rendering library for Rust, allowing you to quickly create graphics and interactive applications with ease. It uses the minifb crate under the hood to handle window creation and input events.

Features

  • Easy-to-use API for drawing basic shapes, such as circles, lines, and rectangles
  • Support for drawing text with a built-in font
  • Efficient pixel buffer manipulation
  • Mouse and keyboard input handling

Examples

Basic Drawing Example

The following example demonstrates some of Ember's features:

use ember_rs::Ember;

fn main() {
    let (width, height, fps) = (800, 600, 144.0);
    let mut app = Ember::new("Ember - Simple Example", width, height, fps);

    while !app.should_close() {
        // clear the previous drawing
        app.clear();

        // draw text at the top-left of the screen at size 4
        app.draw_text("ember is awesome", 20, 20, 4, 0xFFAAAA);

        // draw a filled white circle at the bottom-right of the window
        app.draw_circle_fill(700, 500, 40, 0xFFFFFF);

        // draw a green-ish line going from the text to the circle
        app.draw_line(310, 70, 630, 430, 0xAAFFAA);

        // update the screen with the new drawing
        app.update();
    }
}

Mouse and Keyboard Input Example

The following example demonstrates mouse and keyboard input handling:

use ember_rs::{Ember, Key};

fn main() {
    let (width, height, fps) = (800, 600, 144.0);
    let mut app = Ember::new("Ember - Mouse and Keyboard Example", width, height, fps);

    let mut circle_x = width / 2;
    let mut circle_y = height / 2;
    let circle_radius = 40;

    while !app.should_close() {
        // clear the previous drawing
        app.clear();

        // handle keyboard input
        app.process_keys(|key| match key {
            Key::W => circle_y -= 5,
            Key::A => circle_x -= 5,
            Key::S => circle_y += 5,
            Key::D => circle_x += 5,
            _ => {}
        });

        // alternatively use app.get_keys() which returns a Vec<Key>

        // handle mouse input
        let mouse_info = app.get_mouse_info();
        if let Some((mouse_x, mouse_y)) = mouse_info.position {
            if mouse_info.left_button {
                circle_x = mouse_x as i32;
                circle_y = mouse_y as i32;
            }
        }

        // draw a filled circle at the current position
        app.draw_circle_fill(circle_x, circle_y, circle_radius, 0xFF0000);

        // update the screen with the new drawing
        app.update();
    }
}

Filled Shapes Example

The following example demonstrates drawing various filled shapes:

// this method is used under the hood for all the other methods
app.set_pixel(x, y, color);

// draw a line
app.draw_line(x1, y1, x2, y2, color);

// draw a line with a specific width
app.draw_line_width(x1, y1, x2, y2, width, color);

// draw a rectangle 
app.draw_rectangle(x, y, width, height, color);

// draw a filled rectangle
app.draw_rectangle_fill(x, y, width, height, color);

// draw a circle
app.draw_circle(x, y, radius, color);

// draw a filled circle
app.draw_circle_fill(x, y, radius, color);

Draw Text Example

The following example demonstrates how to draw text to the screen:

use ember_rs::{Ember, helper};

fn main() {
    let (width, height, fps) = (800, 600, 144.0);
    let mut app = Ember::new("Ember - Mouse and Keyboard Example", width, height, fps);

    while !app.should_close() {
        // clear the previous drawing
        app.clear();

        // draw text to the screen at position (20, 20), scaled 4 times
        app.draw_text("hello world", 50, 50, 4, 0xFFFFFF);

        // if you want to center the text, use one of the helper methods
        let text = format!("Width: {}", width);
        // this return the (x, y) needed to center the text
        let (x, y) = helper::center_text(&text, 400, 400, 4);
        // draw the centered text
        app.draw_text(&text, x, y, 4, 0xAAAAFF);

        // update the screen with the new drawing
        app.update();
    }
}

Color Example

The following example demonstrates ways to create colors:

use ember_rs::Color

// shortest way to write a color
let color = 0xFFFFFF;

// from RGB
let color = Color::from_rgb(255, 255, 255);

// from HSL
let color = Color::from_hsl(0.0, 0.0, 100.0);

// from hex string - results to FFFFFF if unable to parse
let color = Color::from_hex("FFFFFF");

Installation

To get started with Ember, type the following command inside of your project:

cargo add ember-rs
You might also like...
H2O Open Source Kubernetes operator and a command-line tool to ease deployment (and undeployment) of H2O open-source machine learning platform H2O-3 to Kubernetes.
H2O Open Source Kubernetes operator and a command-line tool to ease deployment (and undeployment) of H2O open-source machine learning platform H2O-3 to Kubernetes.

H2O Kubernetes Repository with official tools to aid the deployment of H2O Machine Learning platform to Kubernetes. There are two essential tools to b

Super-lightweight Immediate-mode Embedded GUI framework, based on the awesome embedded-graphics library. Written in Rust.

Kolibri - A GUI framework made to be as lightweight as its namesake What is Kolibri? Kolibri is an embedded Immediate Mode GUI mini-framework very str

Upkeep your websites and web applications with ease from the comfort of the command line.
Upkeep your websites and web applications with ease from the comfort of the command line.

Upkeep Upkeep your websites and web applications with ease from the comfort of the command line. Explore the docs ยป View Demo ยท Report Bug ยท Request F

Manage your dotfiles and packages with ease. Define your $HOME as Code  ๐Ÿ’ป ๐Ÿš€ โœจ
Manage your dotfiles and packages with ease. Define your $HOME as Code ๐Ÿ’ป ๐Ÿš€ โœจ

EnvHub is a simple tool to manage dotfiles and packages accross multiple machines. Written in Rust, internally it uses nix/homebrew/pkgx/devbox to man

Turn static CLI commands into TUIs with ease
Turn static CLI commands into TUIs with ease

lazycli Turn static CLI commands into TUIs with ease Demo: Usage Pick a command that spits out either a list or table of content, like ls, docker ps,

Calc: A fully-featured minimalistic configurable calculator written in Rust
Calc: A fully-featured minimalistic configurable calculator written in Rust

Calc Calc: A fully-featured minimalistic configurable rust calculator Install You can install the latest version from source git clone https://github.

A minimalistic blog/portfolio starter written in Rust. No database, bloat or JS.

rlog Rlog is a minimalistic blog/portfolio starter project intended to be used for a personal blog. The project is built using only Rust, HTML and CSS

A library for 3D grid coordinates: for games

Positioning rustdocs A library for manipulating coordinates on a 3D grid. This will contain code that I'll often end up repeating in games. Currently,

A cross platform minimalistic text user interface
A cross platform minimalistic text user interface

titik Titik is a crossplatform TUI widget library with the goal of being able to interact intuitively on these widgets. It uses crossterm as the under

Standard Graphics is a command-line tool for printing 2D graphics from any language to any screen.

2D graphics in any programming language with just print statements!

Caleb Winston 123 Nov 20, 2022
Revolutionize handheld gaming with adaptive game settings. Optimize graphics and gameplay experience based on real-time system metrics. Open-source project empowering developers to enhance games on portable devices

Welcome to the server-side application for the HarmonyLink project. This innovative software is developed with the Rust programming language and is ai

Jordon Brooks 5 Jun 28, 2023
A small program which makes a rofi game launcher menu possible by creating .desktop entries for games

rofi-games A small program which makes a `rofi` game launcher menu possible by creating `.desktop` entries for games Installation Manual Clone repo: g

Rolv Apneseth 20 May 4, 2023
Rust API Server: A versatile template for building RESTful interfaces, designed for simplicity in setup and configuration using the Rust programming language.

RUST API SERVER Introduction Welcome to the Rust API Server! This server provides a simple REST interface for your applications. This README will guid

Harry Nguyen 3 Feb 25, 2024
RustGPT is a ChatGPT UI built with Rust + HTMX: the power of Rust coupled with the simplicity of HTMX ๐Ÿ’š

RustGPT ??โœจ RustGPT.Blog.Post.mp4 Welcome to the RustGPT repository! Here, you'll find a web ChatGPT clone entirely crafted using Rust and HTMX, where

Bitswired 529 Dec 4, 2023
A high level DSL for Simplicity. This is a work in progress and is not yet ready for production use

A high level DSL for Simplicity. This is a work in progress and is not yet ready for production use. The language is designed to be simple and easy to use. It is inspired by rust syntax and is statically typed. The syntax will be extended in the future to support more features.

null 13 Oct 28, 2023
A web-based streaming service with improved privacy, performance, and simplicity.

Majiix Majiix is a web-based open-source streaming service. The backend that handles the core streaming logic is written in Rust and makes use of cutt

Majgix 3 Nov 21, 2023
YAML(ish) - Terminal UI framework based on templates focused on simplicity

A YAML(ish) based terminal GUI framework for- and by Rust, focussed on making it quick and easy to create a functional UI for an app or game. Based on Crossterm and inspired by Kivy.

null 27 Dec 18, 2022
A Rust library for building interactive prompts

inquire is a library for building interactive prompts on terminals. Demo Source Usage Put this line in your Cargo.toml, under [dependencies]. inquire

Mikael Mello 426 Dec 26, 2022
Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're working with files or directories, this tool simplifies common file operations with ease.

Rust FileOps Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're w

Harikesh Ranjan Sinha 5 May 2, 2024