smoke simulation using shepards distortion
Posted: 2011-07-13T08:49:50-07:00
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.
smoke.sh calls distort.pl to generate the distort file:
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 &
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);
}