PHPackages                             aashan/phpanim - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aashan/phpanim

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aashan/phpanim
==============

v1.0.0(5mo ago)00C

Since Dec 1Pushed 5mo agoCompare

[ Source](https://github.com/aashan10/phpanim)[ Packagist](https://packagist.org/packages/aashan/phpanim)[ RSS](/packages/aashan-phpanim/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

PHPAnim: A Creative Coding Framework for PHP
============================================

[](#phpanim-a-creative-coding-framework-for-php)

[![Latest Version](https://camo.githubusercontent.com/9990e85422e7a7228014a563ddc601d74f9ed38c7f94c8267e6e3ccbc865d91f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61617368616e2f706870616e696d2e737667)](https://packagist.org/packages/aashan/phpanim)[![License](https://camo.githubusercontent.com/840bde3278118312f873dac8737440db1fa7b4b01838ec1a09a83c80fbe50201/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61617368616e2f706870616e696d2e737667)](https://github.com/aashan/phpanim/blob/main/LICENSE.txt)

**PHPAnim** is a creative coding framework for PHP that makes it possible to create 2D animations and interactive applications. It bridges the gap between the high-level, expressive power of PHP and the high-performance graphics capabilities of the [Raylib](https://www.raylib.com/) C library.

This is achieved using PHP's **FFI (Foreign Function Interface)**, which allows PHP code to call functions and use data structures from native, pre-compiled C libraries. What was once a simple library has evolved into a complete animation engine with a command-line interface, a plugin-based architecture, and a powerful animation scheduler.

What is PHPAnim for?
--------------------

[](#what-is-phpanim-for)

- **Creative Coding &amp; Algorithmic Art**: Generate visuals from algorithms, create mathematical visualizations, or experiment with generative art, all within your favorite language.
- **Prototyping Simple Games**: The simple, immediate-mode-like API is great for quickly prototyping 2D game mechanics.
- **Educational Tools**: Build interactive tools and simulations for educational purposes.
- **Pushing PHP to its Limits**: If you're curious about what PHP is capable of beyond web development, PHPAnim is a great way to explore its potential.

Core Features
-------------

[](#core-features)

- **Command-Line Interface**: A Symfony Console-based CLI for running and scaffolding your creations.
- **Scene-Based Architecture**: Organize your application's logic into self-contained `Scenes`.
- **Extensible via Plugins**: A simple yet powerful plugin system allows you to organize your code and extend the core functionality.
- **Powerful Animation Scheduler**: A unique scheduler built on top of PHP **Fibers**. It allows you to write complex, non-blocking, and sequential animations with a clean, readable, and fluent API.
- **High-Level Components**: PHPAnim includes built-in, high-level "Visualizations" like `XYGrid` and `Curve` that make it easy to create complex drawings with minimal code.
- **Direct Raylib Access**: Provides a thin, object-oriented wrapper around the native Raylib library. You can call Raylib functions as if they were native PHP methods.

Getting Started
---------------

[](#getting-started)

### Prerequisites

[](#prerequisites)

1. **PHP &gt;= 8.0**: PHPAnim relies on features introduced in PHP 8, such as Fibers.
2. **FFI Extension**: PHP's Foreign Function Interface extension must be enabled. Check by running `php -m | grep FFI`.
3. **Composer**: The project uses Composer to manage PHP dependencies.
4. **Raylib Shared Library**: You need a compiled Raylib shared library (`.so` on Linux, `.dylib` on macOS, `.dll` on Windows).

### Installation and Setup

[](#installation-and-setup)

1. **Create a Project**:

    ```
    mkdir my-animation
    cd my-animation
    composer init
    ```
2. **Install PHPAnim**:

    ```
    composer require aashan/phpanim
    ```
3. **Get the Raylib Library**: Download the Raylib shared library from the [Raylib releases page](https://github.com/raysan5/raylib/releases). Create a `lib` folder in your project root and copy the library file into it (e.g., `lib/libraylib.dylib`).

Basic Usage
-----------

[](#basic-usage)

PHPAnim is designed around **Scenes** and **Plugins**.

### 1. Create a Scene

[](#1-create-a-scene)

A scene contains the logic for one part of your application. Create a file `MyFirstScene.php`:

```
