smokesim


Namesmokesim JSON
Version 0.0.21 PyPI version JSON
download
home_pagehttps://github.com/q-viper/SmokeSim
SummaryA package for doing smoke simulation.
upload_time2025-01-05 00:21:50
maintainerNone
docs_urlNone
authorRamkrishna Acharya(QViper)
requires_pythonNone
licenseNone
keywords smoke simulation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Smoke Simulation: Experiments in Generating and Augmenting Smoke
![Dependabot Status](https://img.shields.io/badge/dependabot-active-brightgreen)
![GitHub License](https://img.shields.io/github/license/q-viper/SmokeSim)
![commit activity](https://img.shields.io/github/commit-activity/w/q-viper/SmokeSim/master)
![code size in bytes](https://img.shields.io/github/languages/code-size/q-viper/SmokeSim)
![Tests](https://github.com/q-viper/SmokeSim/actions/workflows/test-on-push.yml/badge.svg)
![Code Formatting](https://github.com/q-viper/SmokeSim/actions/workflows/black-formatter.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/q-viper/SmokeSim/badge.svg?branch=master)](https://coveralls.io/github/q-viper/SmokeSim?branch=master)


This project showcases my experiments in simulating smoke effects using both **JavaScript** and **Python**. The project utilizes and extends two open-source libraries to demonstrate smoke generation in various contexts, including interactive demos, image augmentation, and video processing. For playground, please visit [here](https://q-viper.github.io/SmokeSim/js_demo/).

## Disclaimer
This project is an educational exploration, and I am not an expert in JavaScript. The implementation builds on the following two projects, which have been modified to suit the goals of this project:

- [`pages/scripts/smoke.js`](pages/scripts/smoke.js): Adapted from [bijection/smoke.js](https://github.com/bijection/smoke.js)
- [`pages/scripts/processor.js`](pages/scripts/processor.js): Based on [processor.js](https://github.com/mdn/dom-examples/blob/main/canvas/chroma-keying/processor.js)

**Credits:** A huge thanks to the original authors for their incredible work.


## Why am I doing this?

<details>
  <summary>Click to expand</summary>
  
  ### **Short Answer**  
  For fun!

  ### **Long Answer**  
  As an engineer working on computer vision applications, I frequently need to train models in diverse environments. One challenging scenario is generating realistic smoky environments, which are difficult to replicate in real-time, especially when high-quality, dynamic simulations are needed for training. 

  To solve this problem, I created this tool to simulate smoke effects and integrate them into various projects—whether for training models or enhancing visual effects. This solution allows for more control, flexibility, and realism when simulating smoke, and it's fun to build and experiment with!

</details>

## Use Cases

<details>
  <summary>Click to expand</summary>

  ### **Smoke Overlaying**  
  For the vision applications running in smokey environment, this tool can generate smokey frames on demand by overlaying smoke on a single clean image. 

  ### **Smoke Segmentation**  
  This might not be that important but I was trying to build a model that could reconstruct a clean image from a smokey one and I used the segmentation mask and history generated from this tool in that project.
</details>

## Installation
### Developing
1. `git clone https://github.com/q-viper/SmokeSim.git`
2. `cd SmokeSim`
2. `pip install .`

### PyPi
`pip install smokesim`

Please make an issue if it failed.

---

## Demos 
### JavaScript Version

Playground is available [here](https://q-viper.github.io/SmokeSim/js_demo/).

This demo showcases real-time smoke effects on a web-based canvas:
- **Interaction:** Hover and click on the rightmost canvas to observe smoke movement.
- **Customization:** UI elements allow tweaking of smoke parameters.

#### How to Run:
1. Clone this repository.
2. Start a local HTTP server in the project directory to avoid CORS errors. For example:
   ```bash
   python examples/server.py
   ```
(This uses [`examples/server.py`](examples/server.py) adapted from this [gist](https://gist.github.com/acdha/925e9ffc3d74ad59c3ea#file-simple_cors_server-py).) 

3. Navigate to http://localhost:8003/js_demo/index.html.

#### Preview:
![](assets/js_demo.png)


### PyGame Version

This demo uses PyGame to simulate smoke effects with interactive mouse controls:
- **Left Click:** Add new smoke particles.
- **Right Click:** Clear the canvas and add new smoke.
- **Hover:** Apply wind effects to influence smoke direction.

#### Preview:
![PyGame Demo](assets/py_demo.png)

#### How to Run:
1. Execute the following command:
```bash
   python particle.py
```

## Using this for Image Augmentation
This project also supports generating smoke effects for use in image augmentation. The `smokesim` Python module allows for realistic smoke overlays on static images.

### Example:

```python
from smokesim.augmentation import Augmentation

import numpy as np
from pathlib import Path

if __name__ == "__main__":
    np.random.seed(100)
    WIDTH, HEIGHT = 700, 500
    augmentation = Augmentation(image_path=None, screen_dim=(WIDTH, HEIGHT))
    smoke_machine = augmentation.smoke_machine
    augmentation.add_smoke(dict(particle_count=15, sprite_size=25, origin=(250, 500)))
    augmentation.add_smoke(dict(particle_count=15, sprite_size=25, origin=(450, 500)))

    augmentation.augment(steps=90,history_path=Path('media/smoke_history.mp4'))
    for i in range(5):
        augmentation.add_smoke(
            dict(
                color=smoke_machine.color,
                particle_count=1,
                origin=(np.random.randint(100, WIDTH), np.random.randint(100, HEIGHT)),
                lifetime=200,
                particle_args={
                    "min_lifetime": 200,
                    "max_lifetime": 500,
                    "min_scale": 10,
                    "max_scale": 50,
                    "fade_speed": 50,
                    "scale": 50,
                    "smoke_sprite_size": 50,
                    "color": smoke_machine.color,
                },
            )
        )
    augmentation.augment(steps=1)
    augmentation.save_as('assets/augmented_smoke_image.jpg')
    augmentation.end()

```

* A better example is at [`examples/image_augmentation.py`](examples/image_augmentation.py). 
* Now `augment` method also accepts image where we want to put smoke. It should be NumPy array. And returns same image after augmenting it. And we can store the smoke history as well. 
* A sample can be seen at [media/smoke_history.mp4](https://q-viper.github.io/SmokeSim/media/smoke_history.mp4).

### Preview
![](assets/augmented_smoke.png)


## Using this With Video
* [`examples/video_augmentation.py`](examples/video_augmentation.py) contains a cool project with MediaPipe (installation is required first: `pip install mediapipe==0.10.14`). Where smoke is generated on the forefinger's position. 
* Demo is at [media/smoke_video.mp4](https://q-viper.github.io/SmokeSim/media/smoke_video.mp4).



## To do
* Add collision effect between particles.
* Add wind effect.
* Try to add smoother transition.

## Collaborating
If you find this project to be interesting and want to add changes, please add your changes and make the push request. Or you can make an issue for that.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/q-viper/SmokeSim",
    "name": "smokesim",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "smoke, simulation",
    "author": "Ramkrishna Acharya(QViper)",
    "author_email": "qramkrishna@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5b/01/75116ca735ec27aebc11bee0086ab571f7d02a0e0217a37f3888d7445275/smokesim-0.0.21.tar.gz",
    "platform": null,
    "description": "# Smoke Simulation: Experiments in Generating and Augmenting Smoke\n![Dependabot Status](https://img.shields.io/badge/dependabot-active-brightgreen)\n![GitHub License](https://img.shields.io/github/license/q-viper/SmokeSim)\n![commit activity](https://img.shields.io/github/commit-activity/w/q-viper/SmokeSim/master)\n![code size in bytes](https://img.shields.io/github/languages/code-size/q-viper/SmokeSim)\n![Tests](https://github.com/q-viper/SmokeSim/actions/workflows/test-on-push.yml/badge.svg)\n![Code Formatting](https://github.com/q-viper/SmokeSim/actions/workflows/black-formatter.yml/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/q-viper/SmokeSim/badge.svg?branch=master)](https://coveralls.io/github/q-viper/SmokeSim?branch=master)\n\n\nThis project showcases my experiments in simulating smoke effects using both **JavaScript** and **Python**. The project utilizes and extends two open-source libraries to demonstrate smoke generation in various contexts, including interactive demos, image augmentation, and video processing. For playground, please visit [here](https://q-viper.github.io/SmokeSim/js_demo/).\n\n## Disclaimer\nThis project is an educational exploration, and I am not an expert in JavaScript. The implementation builds on the following two projects, which have been modified to suit the goals of this project:\n\n- [`pages/scripts/smoke.js`](pages/scripts/smoke.js): Adapted from [bijection/smoke.js](https://github.com/bijection/smoke.js)\n- [`pages/scripts/processor.js`](pages/scripts/processor.js): Based on [processor.js](https://github.com/mdn/dom-examples/blob/main/canvas/chroma-keying/processor.js)\n\n**Credits:** A huge thanks to the original authors for their incredible work.\n\n\n## Why am I doing this?\n\n<details>\n  <summary>Click to expand</summary>\n  \n  ### **Short Answer**  \n  For fun!\n\n  ### **Long Answer**  \n  As an engineer working on computer vision applications, I frequently need to train models in diverse environments. One challenging scenario is generating realistic smoky environments, which are difficult to replicate in real-time, especially when high-quality, dynamic simulations are needed for training. \n\n  To solve this problem, I created this tool to simulate smoke effects and integrate them into various projects\u2014whether for training models or enhancing visual effects. This solution allows for more control, flexibility, and realism when simulating smoke, and it's fun to build and experiment with!\n\n</details>\n\n## Use Cases\n\n<details>\n  <summary>Click to expand</summary>\n\n  ### **Smoke Overlaying**  \n  For the vision applications running in smokey environment, this tool can generate smokey frames on demand by overlaying smoke on a single clean image. \n\n  ### **Smoke Segmentation**  \n  This might not be that important but I was trying to build a model that could reconstruct a clean image from a smokey one and I used the segmentation mask and history generated from this tool in that project.\n</details>\n\n## Installation\n### Developing\n1. `git clone https://github.com/q-viper/SmokeSim.git`\n2. `cd SmokeSim`\n2. `pip install .`\n\n### PyPi\n`pip install smokesim`\n\nPlease make an issue if it failed.\n\n---\n\n## Demos \n### JavaScript Version\n\nPlayground is available [here](https://q-viper.github.io/SmokeSim/js_demo/).\n\nThis demo showcases real-time smoke effects on a web-based canvas:\n- **Interaction:** Hover and click on the rightmost canvas to observe smoke movement.\n- **Customization:** UI elements allow tweaking of smoke parameters.\n\n#### How to Run:\n1. Clone this repository.\n2. Start a local HTTP server in the project directory to avoid CORS errors. For example:\n   ```bash\n   python examples/server.py\n   ```\n(This uses [`examples/server.py`](examples/server.py) adapted from this [gist](https://gist.github.com/acdha/925e9ffc3d74ad59c3ea#file-simple_cors_server-py).) \n\n3. Navigate to http://localhost:8003/js_demo/index.html.\n\n#### Preview:\n![](assets/js_demo.png)\n\n\n### PyGame Version\n\nThis demo uses PyGame to simulate smoke effects with interactive mouse controls:\n- **Left Click:** Add new smoke particles.\n- **Right Click:** Clear the canvas and add new smoke.\n- **Hover:** Apply wind effects to influence smoke direction.\n\n#### Preview:\n![PyGame Demo](assets/py_demo.png)\n\n#### How to Run:\n1. Execute the following command:\n```bash\n   python particle.py\n```\n\n## Using this for Image Augmentation\nThis project also supports generating smoke effects for use in image augmentation. The `smokesim` Python module allows for realistic smoke overlays on static images.\n\n### Example:\n\n```python\nfrom smokesim.augmentation import Augmentation\n\nimport numpy as np\nfrom pathlib import Path\n\nif __name__ == \"__main__\":\n    np.random.seed(100)\n    WIDTH, HEIGHT = 700, 500\n    augmentation = Augmentation(image_path=None, screen_dim=(WIDTH, HEIGHT))\n    smoke_machine = augmentation.smoke_machine\n    augmentation.add_smoke(dict(particle_count=15, sprite_size=25, origin=(250, 500)))\n    augmentation.add_smoke(dict(particle_count=15, sprite_size=25, origin=(450, 500)))\n\n    augmentation.augment(steps=90,history_path=Path('media/smoke_history.mp4'))\n    for i in range(5):\n        augmentation.add_smoke(\n            dict(\n                color=smoke_machine.color,\n                particle_count=1,\n                origin=(np.random.randint(100, WIDTH), np.random.randint(100, HEIGHT)),\n                lifetime=200,\n                particle_args={\n                    \"min_lifetime\": 200,\n                    \"max_lifetime\": 500,\n                    \"min_scale\": 10,\n                    \"max_scale\": 50,\n                    \"fade_speed\": 50,\n                    \"scale\": 50,\n                    \"smoke_sprite_size\": 50,\n                    \"color\": smoke_machine.color,\n                },\n            )\n        )\n    augmentation.augment(steps=1)\n    augmentation.save_as('assets/augmented_smoke_image.jpg')\n    augmentation.end()\n\n```\n\n* A better example is at [`examples/image_augmentation.py`](examples/image_augmentation.py). \n* Now `augment` method also accepts image where we want to put smoke. It should be NumPy array. And returns same image after augmenting it. And we can store the smoke history as well. \n* A sample can be seen at [media/smoke_history.mp4](https://q-viper.github.io/SmokeSim/media/smoke_history.mp4).\n\n### Preview\n![](assets/augmented_smoke.png)\n\n\n## Using this With Video\n* [`examples/video_augmentation.py`](examples/video_augmentation.py) contains a cool project with MediaPipe (installation is required first: `pip install mediapipe==0.10.14`). Where smoke is generated on the forefinger's position. \n* Demo is at [media/smoke_video.mp4](https://q-viper.github.io/SmokeSim/media/smoke_video.mp4).\n\n\n\n## To do\n* Add collision effect between particles.\n* Add wind effect.\n* Try to add smoother transition.\n\n## Collaborating\nIf you find this project to be interesting and want to add changes, please add your changes and make the push request. Or you can make an issue for that.",
    "bugtrack_url": null,
    "license": null,
    "summary": "A package for doing smoke simulation.",
    "version": "0.0.21",
    "project_urls": {
        "Download": "https://github.com/q-viper/SmokeSim/archive/refs/tags/v0.0.2.tar.gz",
        "Homepage": "https://github.com/q-viper/SmokeSim"
    },
    "split_keywords": [
        "smoke",
        " simulation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b0175116ca735ec27aebc11bee0086ab571f7d02a0e0217a37f3888d7445275",
                "md5": "d781c59b79f12c10f34d430213cd1e53",
                "sha256": "bc417749d9e964a6a235d720fe66cee126dfc7f8f0ceeb7ceab81bf30e0a4bc7"
            },
            "downloads": -1,
            "filename": "smokesim-0.0.21.tar.gz",
            "has_sig": false,
            "md5_digest": "d781c59b79f12c10f34d430213cd1e53",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19010,
            "upload_time": "2025-01-05T00:21:50",
            "upload_time_iso_8601": "2025-01-05T00:21:50.059526Z",
            "url": "https://files.pythonhosted.org/packages/5b/01/75116ca735ec27aebc11bee0086ab571f7d02a0e0217a37f3888d7445275/smokesim-0.0.21.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-05 00:21:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "q-viper",
    "github_project": "SmokeSim",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "smokesim"
}
        
Elapsed time: 0.42989s