POV-Ray : Newsgroups : povray.binaries.animations : Animated Function Server Time
28 Mar 2024 09:00:29 EDT (-0400)
  Animated Function (Message 1 to 1 of 1)  
From: Dave Blandston
Subject: Animated Function
Date: 31 Jul 2022 23:15:00
Message: <web.62e744fddc0a875955d61561607c1b34@news.povray.org>
I know there are better ways of achieving the final result but my goal was to
write the code below. Trying different functions is lots of fun.

https://www.youtube.com/watch?v=apI3E4Pt8h8

Here's the scene file which generates height_field frames: (One row and one
column should be discarded to avoid crosshatching in the image. The proper
resolution will be displayed.)

#version 3.7;

global_settings {assumed_gamma 1}

#include "colors.inc"

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */
/* *
                                    * */
/* *
                                    * */
/* * SCENE SETTINGS
                                    * */
/* *
                                    * */
/* *
                                    * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */

#local AspectRatio = 1;

camera {
   orthographic
   location <0, 0, -1>
   right AspectRatio * x
   direction <0, 0, 1>
   look_at <0, 0, 0>
} //camera

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */
/* *
                                    * */
/* *
                                    * */
/* * TEXTURES
                                    * */
/* *
                                    * */
/* *
                                    * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */

#local Color0 = Black;
#local Color1 = White;

#local NColors = 65536;

#local BlockColor = array [NColors]

#for (I, 0, NColors - 1)
   #local BlockColor [I] = (I / (NColors - 1) * Color1) + (NColors - 1 - I) /
(NColors - 1) * Color0;
#end //#for

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */
/* *
                                    * */
/* *
                                    * */
/* * THE SCENE
                                    * */
/* *
                                    * */
/* *
                                    * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */

#local AxesLengths = 540;
#local StepX = 1/2; //Should be 1, 1/2, 1/3, 1/4, et cetera
#local StepY = 1/2; //Should be 1, 1/2, 1/3, 1/4, et cetera

#local MinX = -AxesLengths;
#local MaxX = AxesLengths;
#local MinY = -AxesLengths;
#local MaxY = AxesLengths;

#local NColumns = (MaxX - MinX) / StepX + 1;
#local NRows = (MaxY - MinY) / StepY + 1;

#debug concat ("\nImage resolution should be ", str (NColumns - 1, 0, 0), " x ",
str (NRows - 1, 0, 0), " pixels.\n")

#local Block = array [NColumns] [NRows]

#local AnimationFactor = (cos (radians (180 + clock * 90)) + 1) * 16;

#local I = 0;
#for (CurX, MinX, MaxX, StepX)
   #local J = 0;
   #for (CurY, MinY, MaxY, StepY)
      //#local F = CurY * sin (radians (CurX * CurX / 256)); //The function
(AxesLengths = 800; reduce the denominator for shorter AxesLengths)
      //#local F = cos (radians (CurX * .5)) * CurY; //The function
      //#local F = cos (radians (CurX / 2)) * sin (radians (CurY / 2)); //The
function (AxesLengths = 800; reduce the denominator for shorter AxesLengths)
      //#local F = pow (cos (radians (CurX)) + 2, cos (radians (CurY)) + 1);
//The function
      //#local F = pow (cos (radians (CurX)) + 2, cos (radians (CurX / (cos
(radians (CurY)) + 2))) + 1); //The function
      #local F = pow (cos (radians (CurX)) + 2, cos (radians (CurX * (cos
(radians (CurY)) + AnimationFactor))) + 1); //The function (Use AxesLengths =
540)
      #if (I = 0 & J = 0)
         #local Lowest = F;
         #local Highest = F;
      #else
         #if (F < Lowest)
            #local Lowest = F;
         #end //#if
         #if (F > Highest)
            #local Highest = F;
         #end //#if
      #end //#if
      #local Block [I] [J] = F;
      #local J = J + 1;
   #end //#for
   #local I = I + 1;
#end //#for

#local Highest = Highest - Lowest;
#local Denominator = Highest / (NColors - 1);

#for (I, 0, NColumns - 1)
   #for (J, 0, NRows - 1)
      #local Block [I] [J] = int ((Block [I] [J] - Lowest) / Denominator + .5);
      #if (Block [I] [J] < 0)
         #debug concat ("\n", str (Block [I] [J], 0, 18), "\n")
         #debug concat ("\n", str (Lowest, 0, 6), ", ", str (Highest, 0, 6),
"\n")
         #error "Oh darn."
      #end //#if
   #end //#for
#end //#for

#local Graph = object {
   union {
      #local I = 0;
      #for (CurX, MinX, MaxX, StepX)
         #local J = 0;
         #for (CurY, MinY, MaxY, StepY)
            box {<CurX - .5, CurY - .5, 0> <CurX + .5, CurY + .5, .1> texture
{pigment {color BlockColor [Block [I] [J]]}} finish {emission .9}}
            #local J = J + 1;
         #end //#for
         #local I = I + 1;
      #end //#for
   } //union
} //object

#local S = max (NColumns, NRows);

object {Graph scale <1 / S / StepX, 1 / S / StepY, 1>}


Post a reply to this message

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