POV-Ray : Newsgroups : povray.text.scene-files : Newbies Grass Macro First Attempt Server Time
22 Dec 2024 14:13:31 EST (-0500)
  Newbies Grass Macro First Attempt (Message 1 to 1 of 1)  
From: Phil Cook
Subject: Newbies Grass Macro First Attempt
Date: 26 Nov 2003 10:03:59
Message: <opry82runcp4ukzs@news.povray.org>
I hope this is the right place for this, but I've been working on a simple 
grass macro for a couple of weeks and finally got to a point that I'm 
vaguely happy with.

I was wondering if I could optimize it in any way to run faster or as more 
likely if I've done somthing seriously stupid that's slowing it down.

Any comments are gratefully received.

--
Phil

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

//<code>
#declare RandBend=seed(321);
#declare RandTranslate1=seed(123);
#declare RandTranslate2=seed(321);
#declare RandGrassHeight=seed(867);
#declare RandBladeWidth=seed(786);
#declare GrassRotate=seed(87);
#declare SeedGrassColour=seed(54645);


#macro CreateBlade(BladeWidth, GrassMinHeight, GrassMaxHeight, GrassPatch)

#declare RandBend1=rand(RandBend)/10;
#declare RandBend2=rand(RandBend)/5;
#declare RandBend3=rand(RandBend)/1;

#declare TranslateBlade1=rand(RandTranslate1)*GrassPatch;
#declare TranslateBlade2=rand(RandTranslate2)*GrassPatch;

#declare BladeWidth1=BladeWidth-(rand(RandBladeWidth)*(BladeWidth*(3/5)));
#declare BladeWidth2=rand(RandBladeWidth)*(BladeWidth*(3/5));
#declare GrassHeight1= 
GrassMinHeight+(rand(RandGrassHeight)*((GrassMaxHeight-GrassMinHeight)));

#declare CurrentGrassRotate = rand(GrassRotate)*359;

#declare FirstPoint=vrotate(<TranslateBlade1,0,TranslateBlade2>, 
<0,CurrentGrassRotate,0>);
#declare 
SecondPoint=vrotate(<TranslateBlade1+BladeWidth,0,TranslateBlade2>, 
<0,CurrentGrassRotate,0>);
#declare 
ThirdPoint=vrotate(<TranslateBlade1+BladeWidth1,GrassHeight1/2,TranslateBlade2+RandBend1>,

<0,CurrentGrassRotate,0>);
#declare 
ForthPoint=vrotate(<TranslateBlade1+BladeWidth2,(GrassHeight1*2)/3,TranslateBlade2+RandBend1+RandBend2>,

<0,CurrentGrassRotate,0>);
#declare 
FifthPoint=vrotate(<TranslateBlade1+(BladeWidth/2),GrassHeight1,TranslateBlade2+RandBend1+RandBend2+RandBend3>,

<0,CurrentGrassRotate,0>);

triangle{FirstPoint,SecondPoint,ThirdPoint}
triangle{FirstPoint,ThirdPoint,ForthPoint}
triangle{ThirdPoint,ForthPoint,FifthPoint}

#end


#macro CreateLumpOfGrass(GrassCount, GrassDensity,BladeWidth, 
GrassMinHeight, GrassMaxHeight, GrassPatch)
mesh{
#while(GrassCount<GrassDensity)
CreateBlade(BladeWidth, GrassMinHeight, GrassMaxHeight, GrassPatch)
#declare GrassCount=GrassCount+1;
#end
}
#end


#macro DistributeGrass(NameOfGrass, EndCountX, EndCountZ, 
LumpOfGrassDistributionX, LumpOfGrassDistributionZ)
#declare XCount=0;
#declare ZCount=0;
#declare YCount=0;

#while (ZCount<EndCountZ)

#while(XCount <EndCountX)
#declare RandGrassColour=(80+(rand(SeedGrassColour)*10))/255;
#declare 
GrassColour=texture{pigment{rgb<RandGrassColour,1,RandGrassColour>}}
object{NameOfGrass rotate y*YCount translate <XCount, 0, ZCount> 
texture{GrassColour}}
#declare XCount=XCount+(LumpOfGrassDistributionX);
#declare YCount=YCount+90;
#end

#declare ZCount=ZCount+(LumpOfGrassDistributionZ);
#declare XCount=0;

#end
#end

//Use macros to create a scene
#declare LumpOfGrass1=CreateLumpOfGrass(0,10000,0.1,0.2,0.5, 25)
#declare LumpOfGrass2=CreateLumpOfGrass(0,100,0.1,5,10, 25)

DistributeGrass(LumpOfGrass1, 1000, 500, 25, 25)
DistributeGrass(LumpOfGrass2, 1000, 500, 100, 55)


light_source{<0,200,-100> rgb 1}

camera{
location <500,18,-25>
look_at <500,18,0>
}

plane{y, 0 pigment{rgb <142/255,97/255,88/255>}finish{ambient 0.6}}
//</code>


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.