POV-Ray : Newsgroups : povray.binaries.images : vororock : vororock Server Time
20 Apr 2024 00:29:19 EDT (-0400)
  vororock  
From: ingo
Date: 13 Feb 2019 07:43:13
Message: <XnsA9F58B9255DFEseed7@news.povray.org>
"Cipped" away about half of 9000 cells. Increasing chance on a "grain" 
along y axis, so the lower ones will be bigger.

---%<------%<------%<---
#version 3.7;
global_settings{assumed_gamma 1.0}
#default{finish{ambient 0.1 diffuse 0.9}}
#include "math.inc"
#include "transforms.inc"
#include "rand.inc" 

// run: scene
// run: voro++pov.py -c "%i %q %w %p %s %t %l" -o -v -1 40 -1 40 -1 40 
vorobox.txt
// run: scene


camera{
  perspective angle 50
  location  <0,30,-100>
  look_at   <0,-5,0>
}
light_source{< -500,300,-500> rgb <0.3,0.3,0.6>}
light_source{<1500,3000,-30> rgb 1}

#macro VoroPolygons(Normals, FaceIndex, Vertices)
  /*==
  Creates a single voronoi cell from data generated by Voro++ by 
constructing
  a polygon per face.
  
  Normals   (arr, vec) : an array of normals
  FaceIndex (arr, int) : an array with indices that points to vertices
  Vertices  (arr, vec) : an array with vertices of the cell faces
  */
  #local Length = dimension_size(FaceIndex,1);
  #local Voro = union{
    #for(Face,0,Length-1,1)
      #local VertexIndices = FaceIndex[Face];
      #local Normal = Normals[Face];
      #local Distance = vdot(Normal,Vertices[VertexIndices[0]]);
      #local Transform = transform{translate Normal*Distance};//*scale 
      #local VILength = dimension_size(VertexIndices,1);
      polygon{
        VILength+1,
        #for(VertexIndex,0,VILength-1,1)
          #local Index = VertexIndices[VertexIndex];
          #local Vertex = Vertices[Index];
          #local Vertex = VProject_Plane(Vertex, Normal);
          #local Vertex = vtransform(Vertex, Transform);
          #if (VertexIndex = 0)
            #local P0 = Vertex;
          #end 
          Vertex
        #end
        P0
      }
    #end
  }
  object{Voro}
#end

#macro Id2Coord(Id, Xn, Yn)
  #local Zi = floor(Id/(Xn*Yn));
  #local Yi = floor((Id-Zi*Xn*Yn)/Xn);
  #local Xi = Id-(Zi*Xn*Yn)-(Yi*Xn);
  (<Xi,Yi,Zi>)
#end 

#macro Coord2Id(Coord, Xn, Yn)
  (Coord.x+Xn*Coord.y+Xn*Yn*Coord.z)
#end

#declare OutFile = "vorobox.txt";
#declare IncFile = "vorobox.inc";
#declare Stream = seed(7);
#declare N = 40;
#declare N3 = pow(N,3);
#declare arrGrid = array[N3];

// first run
#if(!file_exists(OutFile))
  #fopen Voro OutFile write
  #for(I,0,N3,1) 
    #declare Coord = Id2Coord(I,N,N);
    #declare Probability = pow(10, 3*(Coord.y+1)/N)/1000;
    #if(Prob(Probability, Stream))
      #declare Point = VRand(Stream) + Coord;
      #write(Voro,I," ",Point.x," ",Point.y," ",Point.z,"\n")
    #end
  #end
#end

// second run
#if(file_exists(IncFile))
  #include IncFile
  #debug concat(IncFile,"\n")
  #declare Length = dimension_size(Labels,1);
  union{
    #for(I,0,Length-1,1)
      #declare Label = Labels[I];
      #declare Coord = Id2Coord(Label, N, N);
      #if(Coord.y<Coord.x+5)
        #declare Point = Points[I];
        #declare Normals = FaceNormal[I];
        #declare FaceIndex = FaceVerticesIndex[I];
        #declare Vertices = RelVertices[I];
        object{VoroPolygons(Normals, FaceIndex, Vertices) scale 0.9 
translate Point pigment{rgb 1}}
      #end
    #end
    translate <-N/2,-N/2,-N/2>
    rotate <0,-45,0>
  }
#end


Post a reply to this message


Attachments:
Download 'vororocks.jpg' (151 KB)

Preview of image 'vororocks.jpg'
vororocks.jpg


 

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