POVray


Home 


Light & media

Utilisation de la lumière et éléments optiques: sites.google.com/site/povraylightandmedia/


Graphiques

Code pour générer des graphiques avec Povray (www.povray.org). Exemples de graphiques créés avec ce modèle sur l'article: Utilisation domestique de l'énergie


///////////////////////////////////////////////////////////////////////////////////
//
//
//      LINE CHARTS
//      RP MARS 2008
//
//
///////////////////////////////////////////////////////////////////////////////////


/*  READ

Save the data to be plotted in a .csv file (coma separated values) made of two columns:

Column 1: "labels"
Column 2: values  

Example:

  "Label 1";16;
  "Label 2";5;
  "Label 3";34;
  "Label 4";26;

Then ajust the "Parameters" just bellow.
*/ 



#include "colors.inc"
#include "textures.inc"
#include "glass.inc"
#include "finish.inc"


// PARAMETERS /////////////////////////////////////////////////////////////////////

// data ----------------------------
#declare data = "consommationGlobale.csv" ;  // Name of the csv file
#declare max_values = 100;            // nombre maximum de valeurs lues 

// graph style --------------------- 
#declare d = 0.5;                    // size of the bars  
#declare bar_texture = Silver1;       // silver to be applied to the bars   

// text values ----------------------
#declare text_values = 1;            // 0 means without text values, 1 means with text values  
#declare text_size = 0.08;            // size of the text values      
#declare text_shift = 0.2;           // shift of text values
#declare text_color = Black;         // text color 
#declare text_precision = 0;         // How many numers after the comma 

// labels --------------------------
#declare labels = 1;                  // 0 means without lables, 1 means with labels     
#declare labels_size = 0.12;           // size of the labels     
#declare labels_shift = 0.1;          // position of labels away from the bars
#declare labels_adjust = - 0.03;         // to adjust the label with the bars
#declare labels_color = Gray10;       // color of the labels
        
// walls ---------------------------
#declare gridType = 2;                // chose 1 for vertical grid plane, 2 for horizontal grid plane, 0 to remove grids
#declare fondL = 1.5;                   // base size
#declare gridSize = 0.25;             // grid size
#declare gridcolor = LightBlue;            // grid color

// background ----------------------
#declare bg_color = White;            // background color 
#declare skybkg = 0;                  // 0 means without sky background, 1 means with sky background
#declare topcolor = Blue;             // top sky color
#declare horizoncolor = White;        // horizon color

// coordinate system ---------------
#declare coord_color = MediumSpringGreen;             // axes color



// LIGHT ////////////////////////////////////////////////////////////////////////// 

light_source { <0, 100, -50> color 1.2*White shadowless}  
light_source { <0, 5, -5> color 0.5*White spotlight radius 2 falloff 10 tightness 10 point_at <0.5, 0, 0> }
 

// CAMERA /////////////////////////////////////////////////////////////////////////

camera {location <-0.5, 1, -2> look_at  <0.5, 0.5, 0> angle 60} 





///////////////////////////////////////////////////////////////////////////////////
//
// DO NOT EDIT UNDER THIS LINE
//
///////////////////////////////////////////////////////////////////////////////////

        
// BAR CHARTS ///////////////////////////////////////////////////////////////////// 

#declare myData = array[max_values];
#declare myLabels = array[max_values];
#local maximum = 0;
#local i = 0;
#fopen MyFile data read
  #while (defined(MyFile))
    #read (MyFile,label,valeur)
    //cylinder {<shiftx+k*d*i,0,0> <shiftx+k*d*i,valeur,0> d texture{bar_texture}} 
    #local myData[i] = valeur;
    #local myLabels[i] = label;
    #if (valeur > maximum) #local maximum = valeur; #end
    #local i = i + 1;
  #end     

#local i = i-1;
#declare step = 1/i;

#declare j = 0;
#while (j<i)
  #local norm_value =  myData[j]/maximum;
  cylinder {<(j + 1/2)*step,0,0> <(j + 1/2)*step,norm_value,0> d*step/2 texture{bar_texture}}
  #if (text_values = 1) text {ttf "arial.ttf" str(myData[j],0,text_precision) 1, 0 pigment {text_color} finish{Luminous} scale <text_size,text_size,0.001> rotate <0,0,90> translate <(j + 1/2 + text_shift)*step,norm_value + 0.04,0>} #end
  #if (labels = 1) text {ttf "timrom.ttf" myLabels[j] 1, 0 pigment {labels_color} finish{Luminous} scale <labels_size,labels_size,0.01> rotate <90,90,0> translate <(j + 1/2)*step + labels_adjust,0.005,-labels_shift>} #end

  #local j = j + 1;
  #end 


// COORDINATES ////////////////////////////////////////////////////////////////////       

#declare axesL = 1;
#declare axesR = 0.015;
#declare coneL = 0.15;
#declare syst_coord = union{
  cylinder {<0,0,0> <axesL-coneL,0,0> axesR }
  cylinder {<0,0,0> <0,axesL-coneL,0> axesR }
  //cylinder {<0,0,0> <0,0,-axesL+coneL> axesR }
  cone { <axesL-coneL,0,0>, 2.5*axesR <axesL,0,0>, 0}
  cone { <0,axesL-coneL,0>, 2.5*axesR <0,axesL,0>, 0}
  //cone { <0,0,-axesL+coneL>, 2.5*axesR <0,0,-axesL>, 0}
  }
object {syst_coord pigment {coord_color} finish {Shiny}}


// PLANS //////////////////////////////////////////////////////////////////////////

#if (gridType = 2) box { <-fondL/2,-0.01,-fondL/2> <fondL/2,0,1+fondL/2> pigment {brick gridcolor, White brick_size <gridSize,gridSize,gridSize> mortar 0.01} translate <0.5,0,-0.5>} #end
#if (gridType = 1) box { <-fondL/2,-fondL/2,-0.01> <fondL/2,1+fondL/2,0> pigment {brick gridcolor, White brick_size <gridSize,gridSize,gridSize> mortar 0.01} translate <0,0.5,0>} #end


// BACKGROUND /////////////////////////////////////////////////////////////////////

background{bg_color}
#if (skybkg = 1) sky_sphere { pigment { gradient y color_map {[0 color horizoncolor] [1 color topcolor]} scale 2 translate -1}} #end