smoke simulation using shepards distortion

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
leungs
Posts: 3
Joined: 2011-07-04T22:25:37-07:00
Authentication code: 8675308

smoke simulation using shepards distortion

Post by leungs »

I have created some interesting animation using shepards distortion.
Included are the csh script which in turn calls a perl script to generate the distortions.

Code: Select all

#!/bin/csh

set convert = "/usr/local/bin/convert"

$convert -size 200x300 -fill white -draw 'circle 98,3 102,3' xc:black tt.miff # initial smoke source
set N = 300     # number of frames
cp tt.miff tt_0.miff

set i = 0
while ( $i < $N )
  # add subsequent smoke source
  if (`echo $i|awk '$1%10==0&&$1<100'`) $convert tt.miff -fill white -draw 'circle 99,1 101,1' tt.miff
  # generate distortion file
  distort.pl > distort.txt
  # call convert
  $convert tt.miff -distort shepards '@distort.txt'  tt.miff
  @ i++
  printf "."
  if (`echo $i|awk '$1%2==0'`) cp tt.miff tt_$i.miff  # save frame
  if (`echo $i|awk '$1%10==0'`) echo " $i"
end

mv tt.miff tt_$N.miff   # save last frame

# make smoke.gif from individual frames
$convert -delay 8 `ls tt_*.miff | sed 's/[[a-z._]//g' | sort -n | sed 's/.*/tt_&.miff/'` \
  -flip -shave 10x10 smoke.gif

animate smoke.gif &

smoke.sh calls distort.pl to generate the distort file:

Code: Select all

#!/usr/bin/perl

($w,$h)=(200,300);

printf("0,0 0,0\n0,$h 0,$h\n$w,0 $w,0\n$w,$h $w,$h\n"); # anchor @ 4 corners
printf("%d,%d,%d,%d\n",$w/2,$h,$w/2,$h);   # anchor near the smoke source

foreach $i (1..200) {  # 400 pts of small random movement
   $x=rand()*$w;
   $y=rand()*$h;     # pick a random point (x,y)
   $a=6.283*rand();  # random angle
   $r=1*(rand()+1+($y>100));  # random distance from (x,y)
   $dx=cos($a)*$r;
   $dy=sin($a)*$r;   # a small perturbation (dx,dy)
   $dy+=2;           # preferential dy of +2
   $dx+=($x>=100)?($y/250):(-$y/250);  # lateral diffusion from centre
   printf("%d,%d %d,%d\n",$x,$y,$x+$dx,$y+$dy);
}

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: smoke simulation using shepards distortion

Post by fmw42 »

can you post a link to a short animation? others would be interested in seeing it.
leungs
Posts: 3
Joined: 2011-07-04T22:25:37-07:00
Authentication code: 8675308

Re: smoke simulation using shepards distortion

Post by leungs »

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: smoke simulation using shepards distortion

Post by fmw42 »


very impressive!
leungs
Posts: 3
Joined: 2011-07-04T22:25:37-07:00
Authentication code: 8675308

Re: smoke simulation using shepards distortion

Post by leungs »

This one seems to smoother, i.e. less jerky.

Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: smoke simulation using shepards distortion

Post by anthony »

Glad you took my suggestion to publish on the forum. And As I mentioned previously (via email) I myself am very impressed with the results you obtained.

The second image looks like you apply some morphing or other time handling to add extra intermediate frames.

The next step I think would be a move from a shepards distortion to using displacement maps that have some time wise order to them. This would help produce longer period effects like swirls, and reduce the sudden changes that are visible.
The effect would then devolve to generating a time sequence of 'air currents' to which you add rising smoke as a later step.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply