Page 1 of 1

smoke simulation using shepards distortion

Posted: 2011-07-13T08:49:50-07:00
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);
}


Re: smoke simulation using shepards distortion

Posted: 2011-07-13T10:19:05-07:00
by fmw42
can you post a link to a short animation? others would be interested in seeing it.

Re: smoke simulation using shepards distortion

Posted: 2011-07-13T12:18:12-07:00
by leungs
Image

Re: smoke simulation using shepards distortion

Posted: 2011-07-13T12:55:05-07:00
by fmw42

very impressive!

Re: smoke simulation using shepards distortion

Posted: 2011-07-13T13:51:35-07:00
by leungs
This one seems to smoother, i.e. less jerky.

Image

Re: smoke simulation using shepards distortion

Posted: 2011-07-13T17:46:41-07:00
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.