EasyEngine


NameEasyEngine JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://t.me/ArcaneDevStudio
SummaryThis a simple SDL2 based 2d UI engine. Used for creating windows without borders. Can render jpg, png, gif and simple grafics on screen like python-turtle. Can be used like C/CPP header or python lib. Suppport async work
upload_time2025-01-19 19:40:11
maintainerNone
docs_urlNone
authorNamilsky
requires_python>=3.6
licenseNone
keywords graphics 2d
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1>Usage and info</h1>

__At the moment, this is my pet project and it is still in development. He will participate in other projects when he stops being a bit raw. But I don't think anyone is interested in this, so I'll go to the documentation.__ 

[![Telegram Channel](https://img.shields.io/badge/Telegram-Channel-blue?style=for-the-badge&logo=telegram)](https://t.me/ArcaneDevStudio)
[![Contact Me](https://img.shields.io/badge/Contact-Me-green?style=for-the-badge&logo=telegram)](https://t.me/Nam4ik)

**Multi-lang readme - [Russian](https://github.com/Nam4ik/EasyEngineLib/blob/main/READMERU.md)**



Opportunities
--------------
As it says in the description, it can render .gif, .jpg, and .png. The drawing takes place relative to the coordinates set in the function. It supports asynchronous operation and rendering of several images or GIFs at once. 
<h3>Functions</h3> 

- `initEngine` - **Initializes the engine, creates a window and a renderer.** Please add it to your code before using it.
```C
void initEngine(const char* title, int width, int height);
```
   - `title`: **Window title** (not used for a window without a frame). <br>
   - `width`: **The width of the window.** <br>
   - `height`: **The height of the window.** <br>
  <br>
  <br>

- `cleanupEngine` - Just **cleans up the memory and shuts down**, at the end of the code there should be
```C
void cleanupEngine();
```  
 <br>
 <br>

- `renderImage` - Renders an image on the screen
```C
void renderImage(const char* imagePath, int x, int y);
```
  - `ImagePath`: **The path to the image.**
  - `x`: **The X coordinate of the upper-left corner.**
  - `y`: **The Y coordinate of the upper-left corner.**
<br>
<br>

- `renderRectangle` - **Will draw a rectangle on the screen**, but why not
```C
void renderRectangle(int x, int y, int width, int height, unsigned int color);
```
   - `x`: **The X coordinate of the upper-left corner.**
   - `y`: **The Y coordinate of the upper-left corner.**
   - `width`: **The width of the rectangle.**
   - `height`: **The height of the rectangle is**.
   - `color`: **Color in ARGB** format (for example, 0xFF0000 for red).
 <br>
 <br>

 - `renderGIF` - **Displays a GIF on the screen, the same as with the image**
```C
void renderGIF(const char* gifPath, int x, int y);
```
  - `gifPath`: **The path to the GIF animation.**
  - `x`: **The X coordinate of the upper-left corner.**
  - `y`: **The Y coordinate of the upper-left corner.**
<br>
<br>

 - `startRenderingThread` - **Starts a stream for asynchronous rendering** of images and GIF animations.
```C
void startRenderingThread();
```
<br>
<br>

 - `stopRenderingThread` - Stops the stream for asynchronous rendering of images and GIF animations.
```C
void stopRenderingThread();
``` 
<br>
<br>

- `startRecordingThread` - Starts the program to record audio and convert it to text.
```C
void startRecordingThread();
```
<br>
<br>

 - `stopRecordingThread` -Stops the stream to record audio and convert it to text.
```C
void stopRecordingThread();
```
<br>
<br>

Usage examples 
------------

<h3>Synchronous Operation</h3> 
In this example, we will initialize the engine, render the image and GIF animation, and then shut down the engine.<br>
<br>


```C++
#include <SDL2/SDL.h>
#include "engine.h"
#include <stdio.h>

int main(int argc, char* argv[]) {
    initEngine("2D Character Engine", 800, 600);

    if (!window) {
        printf("Failed to initialize the game engine!\n");
        return -1;
    }

    // Clearing the screen in black
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
    SDL_RenderClear(renderer);

    // Draw an image in the center of the screen
    renderImage("character.jpg", 350, 250);

    // Drawing a cloud and GIF animation
renderImage("cloud.png", 300, 200);
    renderGIF("speaking.gif", 350, 250);

    // Updating the display
    SDL_RenderPresent(renderer);

    // Waiting for 5 seconds
    SDL_Delay(5000);

    cleanupEngine();
return 0;
}
```
**Compilation**
**For Lixux**
```shell
gcc sync_example.c -o sync_example -L. -lengine -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson -Wl,-rpath,.
```
**For windows**
```shell
gcc sync_example.c -o sync_example.exe -L. -lengine -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson
```
**Variation with Python**
```Python
import engine
import time

# Initializing the engine
engine.initEngine("2D Character Engine", 800, 600)

# Clearing the screen in black
engine.renderRectangle(0, 0, 800, 600, 0x000000)

# Draw an image in the center of the screen
engine.renderImage("character.jpg", 350, 250)

# Drawing a cloud and GIF animation
engine.renderImage("cloud.png", 300, 200)
engine.renderGIF("speaking.gif", 350, 250)

# Waiting for 5 seconds
of time.sleep(5)

# Clear the screen and shut down the engine
engine.cleanupEngine()

```
In general, everything is the same.

<br>
<h3>Asynchronous Operation</h3>

In this example, we will initialize the engine, run streams for asynchronous rendering and audio recording, and then shut down the engine. 

```C++
#include <SDL2/SDL.h>
#include "engine.h"
#include <stdio.h>

int main(int argc, char* argv[]) {
    initEngine("2D Character Engine", 800, 600);

    if (!window) {
        printf("Failed to initialize the game engine!\n");
        return -1;
    }

    SDL_Event event;
    int running = 1;
    while (running) {
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                running = 0;
            }
        }

        // Clearing the screen in black
        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
        SDL_RenderClear(renderer);

        // Checking for a response
        pthread_mutex_lock(&mutex);
        if (prompt) {
            printf("Prompt: %s\n", prompt);
            // Drawing a cloud and GIF animation
            renderImage("cloud.png", 300, 200);
            renderGIF("speaking.gif", 350, 250);
        }
        pthread_mutex_unlock(&mutex);

        // Draw an image in the center of the screen
        renderImage("character.jpg", 350, 250);

        // Updating the display
        SDL_RenderPresent(renderer);

        SDL_Delay(16); // Approximately 60 frames per second
    }

    cleanupEngine();
return 0;
}
```
**Compilation** <br>
It's the same as with the synchronous example.

**Variation with Python**
```Python
import engine
import time

# Initializing the engine
engine.initEngine("2D Character Engine", 800, 600)

# Running streams for rendering and recording audio
engine.startRenderingThread()
engine.startRecordingThread()

try:
    while True:
        # Clear the screen in black
        engine.renderRectangle(0, 0, 800, 600, 0x000000)

        # Draw an image in the center of the screen
        engine.renderImage("character.jpg", 350, 250)

        # Checking for a response
        if engine.prompt:
print(f"Prompt: {engine.prompt}")
# Draw a cloud and a GIF animation
            engine.renderImage("cloud.png", 300, 200)
            engine.renderGIF("speaking.gif", 350, 250)

        # Updating the display
        time.sleep(0.016) # Approximately 60 frames per second

except KeyboardInterrupt:
    pass

finally:
# Stop the threads and shut down the engine
    engine.stopRenderingThread()
    engine.stopRecordingThread()
    engine.cleanupEngine()
```



Dependencies
--------------
Dependencies include both standard headers and some additional ones.
```lst
engine.h # is included in the standard delivery
SDL2 - SDL.h, SDL_image.h, SDL2/SDL_gfxPrimitivies
Portaudio
cjson
stdlib
stdbool
string
pthread
```
<h3>Installation for Linux</h3>

**Debian-based distros**
```bash
sudo apt-get install libsdl2-dev libsdl2-image-dev libportaudio2 portaudio19-dev libjson-c-dev
```
**Arch-based distros**
```bash
sudo pacman -S sdl2 sdl2_image portaudio json-c base-devel
```
<h3>Installation for windows</h3> 
<br>

1. SDL2: Download the library from [SDL2](https://github.com/libsdl-org/SDL/releases ). <br>
2. SDL2_image: Download the library from [SDL_image](https://github.com/libsdl-org/SDL/releases ). <br>
3. PortAudio: Download the library from [PortAudio](https://www.portaudio.com/download.html ). <br>
4. cJSON: Download the library from [cJSON](https://github.com/DaveGamble/cJSON/releases/tag/v1.7.18 ). <br>

<h3>Cross-platform via vcpkg</h3>

<br>

```bash
vcpkg install sdl2 cjson portaudio
```

Building into a dynamic library
------------

<br>

**For Linux**
```shell
gcc -shared -o libengine.so engine.o -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson
```
<br>

**For Windows (using MinGW):** 
```shell
gcc -c engine.c -o engine.o -DENGINE_EXPORTS
gcc -shared -o engine.dll engine.o -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson
```


Variations of the provision
-----------

<h3>Python library</h3>

**Available on PyPI** - `pip install EasyEngineLib`


<h3>C/C++ header</h3>

**Copy the src** and add the compiler flag to the directory where engine.h is located. For example - 
`gcc -I~/include/engine example.c -o example.o `

Self-assembly of the Python library
----------------
If you're messing up and you don't like PyPI, build the library yourself.
```
python setup.py sdist bdist_wheel
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://t.me/ArcaneDevStudio",
    "name": "EasyEngine",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "Graphics 2d",
    "author": "Namilsky",
    "author_email": "alive6863@gmail.com",
    "download_url": null,
    "platform": null,
    "description": "<h1>Usage and info</h1>\n\n__At the moment, this is my pet project and it is still in development. He will participate in other projects when he stops being a bit raw. But I don't think anyone is interested in this, so I'll go to the documentation.__ \n\n[![Telegram Channel](https://img.shields.io/badge/Telegram-Channel-blue?style=for-the-badge&logo=telegram)](https://t.me/ArcaneDevStudio)\n[![Contact Me](https://img.shields.io/badge/Contact-Me-green?style=for-the-badge&logo=telegram)](https://t.me/Nam4ik)\n\n**Multi-lang readme - [Russian](https://github.com/Nam4ik/EasyEngineLib/blob/main/READMERU.md)**\n\n\n\nOpportunities\n--------------\nAs it says in the description, it can render .gif, .jpg, and .png. The drawing takes place relative to the coordinates set in the function. It supports asynchronous operation and rendering of several images or GIFs at once. \n<h3>Functions</h3> \n\n- `initEngine` - **Initializes the engine, creates a window and a renderer.** Please add it to your code before using it.\n```C\nvoid initEngine(const char* title, int width, int height);\n```\n   - `title`: **Window title** (not used for a window without a frame). <br>\n   - `width`: **The width of the window.** <br>\n   - `height`: **The height of the window.** <br>\n  <br>\n  <br>\n\n- `cleanupEngine` - Just **cleans up the memory and shuts down**, at the end of the code there should be\n```C\nvoid cleanupEngine();\n```  \n <br>\n <br>\n\n- `renderImage` - Renders an image on the screen\n```C\nvoid renderImage(const char* imagePath, int x, int y);\n```\n  - `ImagePath`: **The path to the image.**\n  - `x`: **The X coordinate of the upper-left corner.**\n  - `y`: **The Y coordinate of the upper-left corner.**\n<br>\n<br>\n\n- `renderRectangle` - **Will draw a rectangle on the screen**, but why not\n```C\nvoid renderRectangle(int x, int y, int width, int height, unsigned int color);\n```\n   - `x`: **The X coordinate of the upper-left corner.**\n   - `y`: **The Y coordinate of the upper-left corner.**\n   - `width`: **The width of the rectangle.**\n   - `height`: **The height of the rectangle is**.\n   - `color`: **Color in ARGB** format (for example, 0xFF0000 for red).\n <br>\n <br>\n\n - `renderGIF` - **Displays a GIF on the screen, the same as with the image**\n```C\nvoid renderGIF(const char* gifPath, int x, int y);\n```\n  - `gifPath`: **The path to the GIF animation.**\n  - `x`: **The X coordinate of the upper-left corner.**\n  - `y`: **The Y coordinate of the upper-left corner.**\n<br>\n<br>\n\n - `startRenderingThread` - **Starts a stream for asynchronous rendering** of images and GIF animations.\n```C\nvoid startRenderingThread();\n```\n<br>\n<br>\n\n - `stopRenderingThread` - Stops the stream for asynchronous rendering of images and GIF animations.\n```C\nvoid stopRenderingThread();\n``` \n<br>\n<br>\n\n- `startRecordingThread` - Starts the program to record audio and convert it to text.\n```C\nvoid startRecordingThread();\n```\n<br>\n<br>\n\n - `stopRecordingThread` -Stops the stream to record audio and convert it to text.\n```C\nvoid stopRecordingThread();\n```\n<br>\n<br>\n\nUsage examples \n------------\n\n<h3>Synchronous Operation</h3> \nIn this example, we will initialize the engine, render the image and GIF animation, and then shut down the engine.<br>\n<br>\n\n\n```C++\n#include <SDL2/SDL.h>\n#include \"engine.h\"\n#include <stdio.h>\n\nint main(int argc, char* argv[]) {\n    initEngine(\"2D Character Engine\", 800, 600);\n\n    if (!window) {\n        printf(\"Failed to initialize the game engine!\\n\");\n        return -1;\n    }\n\n    // Clearing the screen in black\n    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);\n    SDL_RenderClear(renderer);\n\n    // Draw an image in the center of the screen\n    renderImage(\"character.jpg\", 350, 250);\n\n    // Drawing a cloud and GIF animation\nrenderImage(\"cloud.png\", 300, 200);\n    renderGIF(\"speaking.gif\", 350, 250);\n\n    // Updating the display\n    SDL_RenderPresent(renderer);\n\n    // Waiting for 5 seconds\n    SDL_Delay(5000);\n\n    cleanupEngine();\nreturn 0;\n}\n```\n**Compilation**\n**For Lixux**\n```shell\ngcc sync_example.c -o sync_example -L. -lengine -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson -Wl,-rpath,.\n```\n**For windows**\n```shell\ngcc sync_example.c -o sync_example.exe -L. -lengine -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson\n```\n**Variation with Python**\n```Python\nimport engine\nimport time\n\n# Initializing the engine\nengine.initEngine(\"2D Character Engine\", 800, 600)\n\n# Clearing the screen in black\nengine.renderRectangle(0, 0, 800, 600, 0x000000)\n\n# Draw an image in the center of the screen\nengine.renderImage(\"character.jpg\", 350, 250)\n\n# Drawing a cloud and GIF animation\nengine.renderImage(\"cloud.png\", 300, 200)\nengine.renderGIF(\"speaking.gif\", 350, 250)\n\n# Waiting for 5 seconds\nof time.sleep(5)\n\n# Clear the screen and shut down the engine\nengine.cleanupEngine()\n\n```\nIn general, everything is the same.\n\n<br>\n<h3>Asynchronous Operation</h3>\n\nIn this example, we will initialize the engine, run streams for asynchronous rendering and audio recording, and then shut down the engine. \n\n```C++\n#include <SDL2/SDL.h>\n#include \"engine.h\"\n#include <stdio.h>\n\nint main(int argc, char* argv[]) {\n    initEngine(\"2D Character Engine\", 800, 600);\n\n    if (!window) {\n        printf(\"Failed to initialize the game engine!\\n\");\n        return -1;\n    }\n\n    SDL_Event event;\n    int running = 1;\n    while (running) {\n        while (SDL_PollEvent(&event)) {\n            if (event.type == SDL_QUIT) {\n                running = 0;\n            }\n        }\n\n        // Clearing the screen in black\n        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);\n        SDL_RenderClear(renderer);\n\n        // Checking for a response\n        pthread_mutex_lock(&mutex);\n        if (prompt) {\n            printf(\"Prompt: %s\\n\", prompt);\n            // Drawing a cloud and GIF animation\n            renderImage(\"cloud.png\", 300, 200);\n            renderGIF(\"speaking.gif\", 350, 250);\n        }\n        pthread_mutex_unlock(&mutex);\n\n        // Draw an image in the center of the screen\n        renderImage(\"character.jpg\", 350, 250);\n\n        // Updating the display\n        SDL_RenderPresent(renderer);\n\n        SDL_Delay(16); // Approximately 60 frames per second\n    }\n\n    cleanupEngine();\nreturn 0;\n}\n```\n**Compilation** <br>\nIt's the same as with the synchronous example.\n\n**Variation with Python**\n```Python\nimport engine\nimport time\n\n# Initializing the engine\nengine.initEngine(\"2D Character Engine\", 800, 600)\n\n# Running streams for rendering and recording audio\nengine.startRenderingThread()\nengine.startRecordingThread()\n\ntry:\n    while True:\n        # Clear the screen in black\n        engine.renderRectangle(0, 0, 800, 600, 0x000000)\n\n        # Draw an image in the center of the screen\n        engine.renderImage(\"character.jpg\", 350, 250)\n\n        # Checking for a response\n        if engine.prompt:\nprint(f\"Prompt: {engine.prompt}\")\n# Draw a cloud and a GIF animation\n            engine.renderImage(\"cloud.png\", 300, 200)\n            engine.renderGIF(\"speaking.gif\", 350, 250)\n\n        # Updating the display\n        time.sleep(0.016) # Approximately 60 frames per second\n\nexcept KeyboardInterrupt:\n    pass\n\nfinally:\n# Stop the threads and shut down the engine\n    engine.stopRenderingThread()\n    engine.stopRecordingThread()\n    engine.cleanupEngine()\n```\n\n\n\nDependencies\n--------------\nDependencies include both standard headers and some additional ones.\n```lst\nengine.h # is included in the standard delivery\nSDL2 - SDL.h, SDL_image.h, SDL2/SDL_gfxPrimitivies\nPortaudio\ncjson\nstdlib\nstdbool\nstring\npthread\n```\n<h3>Installation for Linux</h3>\n\n**Debian-based distros**\n```bash\nsudo apt-get install libsdl2-dev libsdl2-image-dev libportaudio2 portaudio19-dev libjson-c-dev\n```\n**Arch-based distros**\n```bash\nsudo pacman -S sdl2 sdl2_image portaudio json-c base-devel\n```\n<h3>Installation for windows</h3> \n<br>\n\n1. SDL2: Download the library from [SDL2](https://github.com/libsdl-org/SDL/releases ). <br>\n2. SDL2_image: Download the library from [SDL_image](https://github.com/libsdl-org/SDL/releases ). <br>\n3. PortAudio: Download the library from [PortAudio](https://www.portaudio.com/download.html ). <br>\n4. cJSON: Download the library from [cJSON](https://github.com/DaveGamble/cJSON/releases/tag/v1.7.18 ). <br>\n\n<h3>Cross-platform via vcpkg</h3>\n\n<br>\n\n```bash\nvcpkg install sdl2 cjson portaudio\n```\n\nBuilding into a dynamic library\n------------\n\n<br>\n\n**For Linux**\n```shell\ngcc -shared -o libengine.so engine.o -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson\n```\n<br>\n\n**For Windows (using MinGW):** \n```shell\ngcc -c engine.c -o engine.o -DENGINE_EXPORTS\ngcc -shared -o engine.dll engine.o -lSDL2 -lSDL2_image -lpthread -lportaudio -lcjson\n```\n\n\nVariations of the provision\n-----------\n\n<h3>Python library</h3>\n\n**Available on PyPI** - `pip install EasyEngineLib`\n\n\n<h3>C/C++ header</h3>\n\n**Copy the src** and add the compiler flag to the directory where engine.h is located. For example - \n`gcc -I~/include/engine example.c -o example.o `\n\nSelf-assembly of the Python library\n----------------\nIf you're messing up and you don't like PyPI, build the library yourself.\n```\npython setup.py sdist bdist_wheel\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "This a simple SDL2 based 2d UI engine. Used for creating windows without borders. Can render jpg, png, gif and simple grafics on screen like python-turtle. Can be used like C/CPP header or python lib. Suppport async work",
    "version": "0.2.1",
    "project_urls": {
        "GitHub": "https://GitHub.com/Nam4ik/EasyEngineLib",
        "Homepage": "https://t.me/ArcaneDevStudio"
    },
    "split_keywords": [
        "graphics",
        "2d"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f41bca1eb32078f2aa7987aaaa0d0b7feb09a99008897eb38c8b2be93b6b641",
                "md5": "9deacbd06b102ad81e8768ff8ee26971",
                "sha256": "3ef69375e147292742c14c37c4be87703545341a3ee4ab9f98b8b7af3778cdbd"
            },
            "downloads": -1,
            "filename": "EasyEngine-0.2.1-cp313-cp313-any.whl",
            "has_sig": false,
            "md5_digest": "9deacbd06b102ad81e8768ff8ee26971",
            "packagetype": "bdist_wheel",
            "python_version": "cp313",
            "requires_python": ">=3.6",
            "size": 36874,
            "upload_time": "2025-01-19T19:40:11",
            "upload_time_iso_8601": "2025-01-19T19:40:11.568010Z",
            "url": "https://files.pythonhosted.org/packages/7f/41/bca1eb32078f2aa7987aaaa0d0b7feb09a99008897eb38c8b2be93b6b641/EasyEngine-0.2.1-cp313-cp313-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-19 19:40:11",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "easyengine"
}
        
Elapsed time: 2.06905s