Glorious Gawk part I

It’s frequently helpful to eyeball a structure while going through iterations of ab initio, sometimes even building up animation for a dynamic calculation. One very simple way without going through a more intensive application is to parse a structure file with Gawk/Awk, to create input for POVray which is then easily rendered. Example follows, simply change expressions /foo/ and fields $ to suit your file…

ED: POVray uses a left-handed system


#script to write povray code from co-ordinates

BEGIN{print “\#include \”colors.inc\”\n \
\#include \”textures.inc\”\n \
\camera \{ \n \ location \<-2,18,-5\>\n \
look_at \<-2, 0,-5\>\n \ angle 45 \n \
\} \n \ plane \{ \n \
y, -100 \n \ texture \{ \n \
pigment \{ \n \ color rgb\<1, 1, 1\>\n \
\} \n \ finish \{ \n \
diffuse 0.4 \n \ ambient 2 \n \
phong 0 \n \ phong_size 0 \n \
reflection 0 \n \ \}\}\} \n \

\#declare a=8.7\; \n \ \#declare c=9.0\; \n \
\#declare Green = texture\{ \n \
pigment \{ color rgb\<0.2, 0.8, 0.2\>\} \n \
finish \{ambient 0.7 diffuse 0.5 reflection 0.01\} \n \
\} \n \
\#declare Blue = texture\{ \n \
pigment \{ color rgb\<0.2, 0.2, 0.8\>\} \n \
finish \{ambient 0.7 diffuse 0.5 reflection 0.01\} \n \
\} \n \
\#declare Yellow = texture\{ \n \
pigment \{ color Yellow\} \n \
finish \{ambient 0.7 diffuse 0.5 reflection 0.01\} \n \
\} \n \
\#declare Red = texture\{ \n \
pigment \{ color rgb\<0.8, 0.2, 0.2\>\} \n \
finish \{ambient 0.7 diffuse 0.5 reflection 0.01\} \n \
\}” > “scsul.pov”};

/S1/{print “\n sphere\{\< “$7” , “$9” , “$8″ \>, 0.15 \n \
texture \{Yellow\}\n \\}\n” > “scsul.pov”};

/Sc/{print “\n sphere\{\< “$7” , “$9” , “$8″ \>, 0.3 \n \
texture \{Green\}\n \
\}\n” > “scsul.pov”};

/O/{print “\n sphere\{\< “$7” , “$9” , “$8″ \>, 0.6 \n \
texture \{Red\}\n \
\}\n” > “scsul.pov”};

END{ print “light_source \{ \<5, 40, 5\> \n \
color White \}” > “scsul.pov”};

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s