POV-Ray : Newsgroups : povray.binaries.images : Calendar v2 [25kb] : Calendar v2 [25kb] Server Time
19 Nov 2024 18:18:31 EST (-0500)
  Calendar v2 [25kb]  
From: Tom Melly
Date: 23 Nov 2001 11:54:30
Message: <3bfe7f46@news.povray.org>
Okay, you can now specify an arbitary object which will be used at a particular
date - couldn't see how to implement a daily calendar though (at least not
without resorting to perl). POV is very fussy about what it'll read.... ;)

Here's the new calendar code...

#version 3.5;


// called by main macro
#macro MakeTOU(CalStr, XTrans, YTrans, CalFont, CalExt, CalSpace)
  text {
    ttf                   // font type (only TrueType format for now)
    CalFont,              // Microsoft Windows-format TrueType font file name
    CalStr,               // the string to create
    CalExt,               // the extrusion depth
    CalSpace              // inter-character spacing
    translate <XTrans,YTrans,0>
  }
#end

/*
Params for MakeCal:
Year = Gregorian Year [int]
Month = Gregorian Month [int 1 -12]
MarkDay = if not 0, unions CalObj with that day
CalXOff = space between dates [num]
CalYoff = space between rows [num]
CalFont = font to use [string]
CalExt = extrusion on text object [num]
CalSpace = inter-char spacing [num]
DayOff = day off-set, [num] 0=sunday, 1=monday, ... 6=saturday
CenterOff = x-adjust for month-year header [num] adjust for centering of heading
CalObj = object to use at Day
*/
#macro MakeCal(Year, Month, MarkDay, CalXOff, CalYOff, CalFont, CalExt,
CalSpace, DayOff, CenterOff, CalObj)
  #local YTrans = 0;
  #local XTrans = 0;

  //make month / year header
  #local Months = array[12]{
    "January","Febuary","March","April",
    "May","June","July","August",
    "September","October","November","December"
  };

  #local TempStr = concat(Months[Month-1], " ",str(Year,0,0))
  MakeTOU(TempStr,XTrans+CenterOff, YTrans, CalFont, CalExt, CalSpace)
  #local YTrans = YTrans - CalYOff;

  //make days of week
  #local Days = array[7]{"Su","Mo","Tu","We","Th","Fr","Sa"};
  #local Temp = 0;
  #while(Temp<7)
    #local TempStr=Days[mod(Temp+DayOff,7)]
    MakeTOU(TempStr, XTrans, YTrans, CalFont, CalExt, CalSpace)
    #local XTrans = XTrans + CalXOff;
    #local Temp = Temp+1;
  #end
  #local XTrans = 0;
  #local YTrans = YTrans - CalYOff;

  //get Julian day integer
  #local Day = 1;
  // easier for leap years
  #if (Month < 3)
    #local Month = Month + 12;
    #local Year=Year-1;
  #end
  #local JulDay = Day + int((153 * Month - 457) / 5) + 365 * Year + floor(Year /
4) -
    floor(Year / 100) + floor(Year / 400) + 1721118.5;
  #local JulDay = JulDay - 1;
  #local LastDay = -1;
  #local CalDay = 0;
  #local First = 1;

  //convert Jul day int to Gregorian cal date, output and inc Jul day
  #while(LastDay < CalDay)
    #local LastDay = CalDay;
    #local JulDay = JulDay + 1;
    #local ModDInt = floor(mod(JulDay + 2 - DayOff, 7));
    #local Z = floor(JulDay - 1721118.5);
    #local R = JulDay - 1721118.5 - Z;
    #local G = Z - 0.25;
    #local A = floor(G / 36524.25);
    #local B = A - floor(A / 4);
    #local CalYear = floor((B+G) / 365.25);
    #local C = B + Z - floor(365.25 * CalYear);
    #local CalMonth = int((5 * C + 456) / 153);
    #local CalDay = C - int((153 * CalMonth - 457) / 5) + R;
    #if (CalMonth > 12)
       #local CalYear = CalYear + 1;
       #local CalMonth = CalMonth - 12;
    #end

    #if(First | CalDay > 1)
      // pre-1st of month filler
      #if(First)
        #local First = 0;
        #local Temp = 0;
        #while (Temp < ModDInt)
          #local XTrans = XTrans + CalXOff;
          #local Temp = Temp + 1;
        #end
      #end
      //a date - add to tempstr and output
      #local TempStr = str(CalDay,2,0)
      MakeTOU(TempStr, XTrans, YTrans, CalFont, CalExt, CalSpace)
      #if (CalDay=MarkDay)
        object{CalObj translate<XTrans, YTrans, 0>}
      #end
      #local XTrans = XTrans + CalXOff;
      #if(ModDInt = 6)
        #local XTrans = 0;
        #local YTrans = YTrans - CalYOff;
      #end
    #end
  #end
#end

and a small sample scene...

#declare myObj=
sphere_sweep{
  b_spline 7,
  <-0.50,-0.95, 0>,0.01  <-0.30,-1.05, 0>,0.02  < 0.57,-0.50, 0>,0.03  < 0.00,
0.00, 0>,0.04
  <-0.50,-0.45, 0>,0.03  < 0.35,-1.00, 0>,0.02  < 0.53,-0.90, 0>,0.01
  scale 2.0  rotate z*15  translate <0.2,1.1,0>
  pigment{Green}
}

#include "cal.inc"
#declare MyCalendar =
union{
  MakeCal(2001,11,23,2.0,1.0,"c:/winnt/fonts/comi.ttf",1,0,6,2.6, myObj)
  translate x*-6.5
  translate y*4
  translate z*-0.001
}

object{MyCalendar pigment{Red}}



--
#macro G(D,E,F)#local I=array[3]{D,E,F}#local B=0;triangle{#while(
B<3)#while(I[B])A[mod(I[B],10)]+#local I[B]=div(I[B],10);#end<-5,-
2,9>#local B=B+1;#end}#end #local A=array[7]{x,x*2,x*4,y,y*2,y*4,z
}light_source{-x*6-z*9,1}mesh{G(105,10,146)G(105,246,10)G(105,56,
146)G(105,1256,246)G(1256,126,220)G(22156,2216,201)pigment{rgb 1}}//TM


Post a reply to this message


Attachments:
Download 'revised calender macro.jpg' (25 KB)

Preview of image 'revised calender macro.jpg'
revised calender macro.jpg


 

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