Just some experiments while I am learning about smoke generation and simulating things. Demo: pages/index.html. Just move cursor on Right canvas to see smoke effect. Video might not play on demo server. But smoke does :)
I am no expert in JS and this project uses modified version of following two projects:
Huuuuuuuuuuge credit goes to original authors.
- On rightmost panel where video is being re-played, we can perform hover, click action to see smoke movement.
- Tweaking UI elements also works.
- Clone this.
- Start a localhost server (on this dir) to avoid CORS Errors. I am using server.py taken from here.
- Open http://localhost:8003/js_demo/index.html and see it for yourself.
- Left click to add new smoke.
- Right click to clear and write new smoke.
- Hover to see wind effect.
- Run
particle.py
and TADAAAAAAAAAA!
- Make use of
smokesim/examples/image_augmentation.py
.
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()
- 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.
smokesim/examples/video_augmentation.py
contains a cool project with MediaPipe. Where smoke is generated on the forefinger's position.- Demo is at media/smoke_video.mp4.
- Add collision effect.
- Add wind effect.
- Make it smooth.