POV-Ray : Newsgroups : povray.text.scene-files : Stepped function offset (attempt #2) : Re: Stepped function offset (attempt #2) Server Time
23 Sep 2021 01:28:42 EDT (-0400)
  Re: Stepped function offset (attempt #2)  
From: Tor Olav Kristensen
Date: 25 Jan 2020 13:40:00
Message: <web.5e2c8a8ada480183f86f6e3a0@news.povray.org>
Mike Horvath <mik### [at] gmailcom> wrote:
> I have created the attached scene.
>
> It works well, except the pigment function needs to be offset at the
> beginning and end of the gradients "CSolid_HSLSphere_Saturation" and
> "CSolid_HSLSphere_Lightness". The end result is supposed to look like this:
>
> https://commons.wikimedia.org/wiki/File:HSLSphere.svg
>
> Can someone clue me in on how to do this? Thanks.

Hi Mike

Perhaps the code below will help you advance.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.7;

global_settings { assumed_gamma 1.0 }

#include "functions.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare AngleFn = function { f_th(x, 0, z) + pi };


#declare D = 2*pi/6;
#declare H = D/2;

#declare SectorFn =
    function(s) {
        0
        + select(s - (0*D    ), 0, select(s - (1*D - H), 0, 0))
        + select(s - (1*D - H), 0, select(s - (2*D - H), 1, 0))
        + select(s - (2*D - H), 0, select(s - (3*D - H), 2, 0))
        + select(s - (3*D - H), 0, select(s - (4*D - H), 3, 0))
        + select(s - (4*D - H), 0, select(s - (5*D - H), 4, 0))
        + select(s - (5*D - H), 0, select(s - (6*D - H), 5, 0))
        + select(s - (6*D - H), 0, select(s - (6*D    ), 6, 0))
    }
;


#declare Colors =
    array[7] {
        color rgb <1, 0, 0>,  // Rd
        color rgb <1, 0, 1>,  // Mg
        color rgb <0, 0, 1>,  // Bu
        color rgb <0, 1, 1>,  // Cy
        color rgb <0, 1, 0>,  // Gn
        color rgb <1, 1, 0>,  // Ye
        color rgb <1, 0, 0>   // Rd
    }
;


#declare C = 1/6;
#declare G = C/2;

#declare SectorPigment =
    pigment {
        function { SectorFn(AngleFn(x, y, z))*C }
        color_map {
            [ 0*C     Colors[0] ]
            [ 1*C - G Colors[0] ]
            [ 1*C - G Colors[1] ]
            [ 2*C - G Colors[1] ]
            [ 2*C - G Colors[2] ]
            [ 3*C - G Colors[2] ]
            [ 3*C - G Colors[3] ]
            [ 4*C - G Colors[3] ]
            [ 4*C - G Colors[4] ]
            [ 5*C - G Colors[4] ]
            [ 5*C - G Colors[5] ]
            [ 6*C - G Colors[5] ]
            [ 6*C - G Colors[6] ]
            [ 6*C     Colors[6] ]
        }
    }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare Rmaj = 9;
#declare Rmin = 1;

torus {
    Rmaj, Rmin
    pigment { SectorPigment }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare R = 7;

#declare RND = seed(7352);

#for (N, 0, 1000)
    #declare X = R*(1 - 2*rand(RND));
    #declare Z = R*(1 - 2*rand(RND));
    #if (f_r(X, 0, Z) < R)
        #declare Angle = AngleFn(X, 0, Z);
        #declare Sector = SectorFn(Angle);
        sphere {
            <X, 0, Z>, 0.2
            pigment { Colors[Sector] }
        }
    #end // if
#end // for

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

camera {
    location 24*y
    look_at 0*y
}

light_source {
    100*<-1, 3, 2>
    color rgb <1, 1, 1>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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