POV-Ray : Newsgroups : povray.text.scene-files : The Plasma macro Server Time
26 Dec 2024 12:11:21 EST (-0500)
  The Plasma macro (Message 1 to 4 of 4)  
From: Nieminen Mika
Subject: The Plasma macro
Date: 13 Mar 1999 22:05:36
Message: <36eb2780.0@news.povray.org>
Start fractint (if you don't have it you surely should download it
right now! http://spanky.triumf.ca/www/fractint/fractint.html) and draw
the plasma fractal. Cool, eh?
  How about a macro that calculates this same thing?
  Well, this is your lucky day, because here it is.
  Why in the heaven should you want this kind of macro? Those plasmas make
very cool heightfields but you don't need a macro for them. You just save
the image calculated by fractint and use it as heightfield in povray.
  But that's the only thing you can do with them (besides using them as
image maps, which is very boring).
  How about making that kind of heightfield with spheres or other objects?
Or arranging the heightfield in other structures, like spherical etc?
  This macro has also another good feature: It calculates tileable, ie.
seamless plasmas (fractint can't do this).

  You have two ways for using the macros:
  1) Make your own macro called PlasmaObject which takes three parameters,
e.g:

#macro PlasmaObject(XCoord,YCoord,ZCoord) ... #end

and then call the macro CreatePlasma, which takes four arguments: The
dimensions of the plasma, a roughness value and a seed. The syntax is:

CreatePlasma(XSize,YSize,Roughness,Seed)

  The macro will call PlasmaObject() XSize*YSize times giving the
appropriate parameters to it. The first two parameters will be the
coordinates of the plasma and the third parameter will be the height at
that coordinates.
  This is best explained with an example:

--8<----8<----8<----8<---

#include "Plasma.inc"
 
camera { location y*8-z*12 look_at 0 angle 45 }
light_source { <100,150,-100> 1 }
 
#macro PlasmaObject(PosX,PosY,Height)
  sphere
  { <(PosX-.5)*10,Height*3,(PosY-.5)*10>,.1
    pigment { rgb <1,Height,0> }
    finish { specular .5 }
  }
#end
 
CreatePlasma(100,100,1,0)

--8<----8<----8<----8<---

  Render this with the plasma include file at the end of the article to
see what it does (be prepared for a long parsing time...).
  First we define the PlasmaObject macro. It takes three coordinates
(PosX, PosY and Height). We place a sphere in the xz-plane with the first
two coordinates and raise it in the y-coordinate with the third parameter.
  Then we call the CreatePlasma macro. We tell it to make a 100x100 plasma
with roughness 1 and seed 0. We will end with 100x100 (ie. 10000) spheres.
  The three parameters to PlasmaObject change always from 0 to 1, so if we
don't scale the parameters in any way, our spheres will be located in a
box from <0,0,0> to <1,1,1>.

  The first two parameters to CreatePlasma define the dimensions of the
plasma.
  The third value is a roughness value, which should be positive. Larger
values will make the plasma smoother while smaller values will make it
rougher. Good values go from 0.5 (quite rough) to 2 (quite smooth).
  The fourth value is the initial seed value used by the rand() function.
Change it to get different plasmas.

  This is the easiest (?) way to use the macro. Sometimes it's not enough:

  2) You can also get an array of values if you want. The syntax is:

CreatePlasmaArray(XSize,YSize,MaxVal,Seed)

  The CreatePlasma macro actually calls this macro with the appropriate
values and then performs two nested #while-loops and calls the PlasmaObject
macro.
  The CreatePlasmaArray creates a 2-dimensional array of size [XSize][YSize]
called PCoord which contains the plasma values. The MaxVal parameter
specifies the maximum value of the plasma, ie. the PCoord array will contain
values between 0 and MaxVal. The Seed parameter is exactly the same as
with the CreatePlasma macro.
  The best example of using this macro is the CreatePlasma macro itself.
You can find it at the end of the include file.
  With the array created by the CreatePlasmaArray macro you can make things
which are not possible with the CreatePlasma macro. Usually the latter
macro should be enough, though.

  Confusing?
  Ask me if you have any questions.

  And the include file itself:

--8<----8<----8<----8<----8<----8<----8<----8<---

/************************************************************************\
|* Plasma macro include file    by Warp                                 *|
|* -------------------------                                            *|
\************************************************************************/
 
// Random number generator. Returns value from Mid-Var/2 to Mid+Var/2
#macro Random(Seed,Mid,Var)
  #local r=rand(Seed);
  #local lo=Mid-Var/2;
  #local hi=lo+Var;
  #if(lo<0) #local lo=0; #end
  #if(hi>MaxVal) #local hi=MaxVal; #end
  lo+r*(hi-lo)
#end
 
// Create PCoord array of plasma values
#macro CreatePlasmaArray(XSize,YSize,MaxVal,Seed)
  #declare PCoord=array[XSize][YSize]
  #local R=seed(Seed);
  #local Div=2;
  #declare PCoord[0][0]=Random(R,MaxVal/2,MaxVal);
  #while(Div/2<=XSize | Div/2<=YSize)
    #local j=0;
    #while(j<Div)
      #local X=div(XSize*j,Div);
      #local Y=div(YSize*j,Div);
      #local i=1;
      #while(i<Div)
        #local X1=div(XSize*(i-1),Div);
        #local X2=div(XSize*(i+1),Div);
        #if(X2>X1+1)
          #local Xm=div(XSize*i,Div);
          #local C1=PCoord[X1][Y];
          #local C2=PCoord[mod(X2,XSize)][Y];
          #declare PCoord[Xm][Y]=Random(R,(C1+C2)/2,X2-X1);
        #end
        #local Y1=div(YSize*(i-1),Div);
        #local Y2=div(YSize*(i+1),Div);
        #if(Y2>Y1+1)
          #local Ym=div(YSize*i,Div);
          #local C1=PCoord[X][Y1];
          #local C2=PCoord[X][mod(Y2,YSize)];
          #declare PCoord[X][Ym]=Random(R,(C1+C2)/2,Y2-Y1);
        #end
        #local i=i+2;
      #end
      #local j=j+2;    
    #end
    #local j=1;
    #while(j<Div)
      #local Y=div(YSize*j,Div);
      #local Y1=div(YSize*(j-1),Div);
      #local Y2=div(YSize*(j+1),Div);
      #if(Y2>Y1+1)
        #local i=1;
        #while(i<Div)
          #local X=div(XSize*i,Div);
          #local X1=div(XSize*(i-1),Div);
          #local X2=div(XSize*(i+1),Div);
          #if(X2>X1+1)
            #local C1=PCoord[X1][Y]+PCoord[mod(X2,XSize)][Y]+
                      PCoord[X][Y1]+PCoord[X][mod(Y2,YSize)];
            #declare PCoord[X][Y]=Random(R,C1/4,(X2-X1+Y2-Y1)/2);
          #end
          #local i=i+2;
        #end
      #end
      #local j=j+2;
    #end
    #local Div=Div*2;
  #end
#end
 
// Create group of objects with plasma values
#macro CreatePlasma(XSize,YSize,Roughness,Seed)
  #if(XSize<=1 | YSize<=1)
    #error "XSize and YSize must be greater than 1"
  #end
  #if(Roughness<0)
    #warning "Roughness should be greater than 0\n"
  #end
  #local MaxVal=Roughness*(XSize+YSize)/2;
  CreatePlasmaArray(XSize,YSize,MaxVal,Seed)
  #local IndY=0;
  #while(IndY<YSize)
    #local IndX=0;
    #while(IndX<XSize)
      PlasmaObject(IndX/(XSize-1),IndY/(YSize-1),PCoord[IndX][IndY]/MaxVal)
      #local IndX=IndX+1;
    #end
    #local IndY=IndY+1;
  #end
#end


Post a reply to this message

From: Spider
Subject: Re: The Plasma macro
Date: 13 Mar 1999 22:11:07
Message: <36EB2738.7463EA0@bahnhof.se>
Neat..
I was thinking of doing this with the old Burn demo. Prehaps after a peek at
this and I'll try.. or perhaps not... :-)


-- 
//Spider 
( spi### [at] bahnhofse ) [ http://www.bahnhof.se/~spider/ ]
#declare life = rand(seed(42))*sqrt(-1);


Post a reply to this message

From: Bob Hughes
Subject: Re: The Plasma macro
Date: 14 Mar 1999 08:09:55
Message: <36EBB4E1.738C1D84@aol.com>
Will all these macros end up in a large collection? Remember the
Macroscope at www.twysted.net? I fear many will get passed by in the
newsgroups especially once they expire. And hopefully the Macroscope
collection (now over 3 dozen) will continue to grow.


Nieminen Mika wrote:
> 
>   Start fractint (if you don't have it you surely should download it
> right now! http://spanky.triumf.ca/www/fractint/fractint.html) and draw
> the plasma fractal. Cool, eh?
>   How about a macro that calculates this same thing?
>   Well, this is your lucky day, because here it is.

-- 
 omniVERSE: beyond the universe
  http://members.aol.com/inversez/POVring.htm
 mailto:inv### [at] aolcom?PoV


Post a reply to this message

From: Nieminen Mika
Subject: Re: The Plasma macro
Date: 14 Mar 1999 11:29:20
Message: <36ebe3e0.0@news.povray.org>
Bob Hughes <inv### [at] aolcom> wrote:
: Will all these macros end up in a large collection? Remember the
: Macroscope at www.twysted.net? I fear many will get passed by in the
: newsgroups especially once they expire. And hopefully the Macroscope
: collection (now over 3 dozen) will continue to grow.

  I can send the macro there.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

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