# Cuddly Calculator — Custom Embedded Calculator in C


A fully custom graphing calculator built entirely in C, designed to run on low-resolution embedded displays (128×64 pixels). The project includes a custom graphics engine, a mathematical expression parser, and a desktop LCD simulator for development and testing.

## Components

### Graphics Library

A pixel-based rendering engine built from scratch, featuring:

- **Pixel surface** abstraction for framebuffer manipulation
- **Software renderer** with font rendering, UI elements (scroll text, scroll lists, buttons), and texture support
- **Scene system** with input handling and update loops
- **Math primitives** — 2D/3D vectors, 3×3 matrices, and rectangles
- Two display backends: **SDL2** (graphical window) and **ncurses** (terminal)

### Math Interpreter

A recursive-descent expression parser that evaluates mathematical expressions with:

- Standard arithmetic operators with correct precedence (+, -, ×, ÷, ^)
- Built-in functions: `sin`, `cos`, `mod`, `pow`
- Constants: `pi`
- Variable support (`x`) for function graphing
- Previous answer reference (`ans`)

### Programs

- **Calculator** — Expression input with real-time function prediction and result display
- **2D Graph** — Plots mathematical functions with adjustable scale and pan controls
- **3D Graph** — Three-dimensional function visualization
- **Menu** — Navigation system between programs

### Tools

- **LCD Simulator** — Runs the calculator UI in a desktop window via SDL2, simulating the target embedded display
- **BMP to C** — Converts bitmap images into C header files with pixel arrays, used for embedding fonts and icons directly in the binary

## Tech Stack

| Component | Technology |
|---|---|
| Language | C (gnu11) |
| Build system | Make |
| Display backends | SDL2, ncurses |
| Target resolution | 128×64 pixels |

Code is available [HERE](https://github.com/rattata2me/cuddly-calculator)

