[Snippet] Rainbow effect

monday

Well-Known Member
Joined
Jun 23, 2014
Messages
921
Likes
4
Points
68
#1
A set of functions that make it easy to loop through colors and create rainbow effect. After copying all the functions from the snippet below the user can implement 2 simple function calls that will take care of the complex process behind it. These functions are:
1. "ShiftColorHue" which changes the color with variable speed, it has the following parameters:
    [email protected] - speed_step - how fast the color change occurs (from 1 to ~30)
    [email protected] - direction (1-rgb order, 2-reversed order)
    [email protected] - hue variable which needs to be dedicated for this snippet (from 1 to 359, it's actually the only variable that is required in external code for this snippet)

2. "GetCLRfromHSV" which converts Hue (the actual color of the color ;p), Saturation, and Value into 3 values between 0-255 (that could be later used as RGB). It has the following parameters:
    [email protected] - Hue (0 - 360 int)
    [email protected] - Saturation  (0.0 - 1.0 float)
    [email protected] - Value (0.0 - 1.0 float)

There's also a function which can be used to make the colors more aesthetic called "RYB_to_RGB". Using it will result in the colors shown on the right wheel from this image based on Red-Yellow-Blue. I guess most programmers use RGB distribution so using that function would make the rainbow effect somewhat unique. The function takes 3 integers between 0-255 and returns also 3 integers between 0-255. It's based on the work of Nathan Gossett and Baoquan Chen.


Full code example tested with Cleo 4.1, Samp 0.3.7 and Sampfuncs 5.3.1
Code:
{$CLEO}
0000: NOP
repeat
    wait 50
until 0AFA:  is_samp_available

[email protected] = 0  // hue 0 - 359 (variable required to keep track of the colour)   

while true
wait 0

    call @ShiftColorHue 3 speed_step 1 direction 1 hue_var [email protected] _returned_hue_var [email protected] // it increases/decreases [email protected] variable between 0-359
    call @GetCLRfromHSV 3 hue [email protected] saturation 1.0 value 1.0 _returnedColor [email protected] [email protected] [email protected]  
    
    // Holding enter presents what "RYB_to_RGB" function does, RGB distribution has too much green/blue from my point of view
    // It appears too bright if the saturation isn't lowered. RYB seems to be more aesthetic to me but lacks bright colors like cyan or magenta.(check google for better comparison)
    if key_down 13
    then
        call @RYB_to_RGB 3 RYB [email protected] [email protected] [email protected] _RGB [email protected] [email protected] [email protected]  // idk how it will behave if you change "Saturation" and "Value" to something other than 1.0
        printf "That's right my nigga:)" 1000
    else
    printf "Hold ENTER for ~R~Red~W~-Yellow-~B~Blue~W~ instead of ~R~Red~W~-~G~Green~W~-~B~Blue" 1000
    end
     
    // Drawing
    0B67: render a 255 r [email protected] g [email protected] b [email protected] to_argb [email protected]
    call @Draw 1 [email protected] 
end









//
// FUNCTIONS
//

:Draw
0B5A: get_screen_resolution [email protected] [email protected]
[email protected]/=2
[email protected]/=3
0085: [email protected] = [email protected] // (int)
[email protected]/=2
0B70: render draw_polygon_pos [email protected] [email protected] size [email protected] [email protected] corners 8 rotation 0.0 color [email protected] //[email protected], [email protected] [int] [email protected], [email protected] [int], [email protected] [int], [email protected] [float], [email protected] [int]
ret 0


:RYB_to_RGB_GetSingleClr
{
    [email protected] - R
    [email protected] - Y
    [email protected] - B
    
    [email protected] - front_up_left : [1, 1, 0],
    [email protected] - front_up_right: [1, 0.5, 0],
    [email protected] - "front_down_left": [1, 1, 1], 
    [email protected] - "front_down_right": [1, 0, 0],
    [email protected] - "back_up_left": [0, 0.66, 0.2],
    [email protected] - "back_up_right": [0.2, 0.094, 0], 
    [email protected] - "back_down_left": [0.163, 0.373, 0.6], 
    [email protected] - "back_down_right": [0.5, 0.0, 0.5], 
}

/*
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
*/
//chatmsg "%.2f %.2f %.2f" -1 [email protected] [email protected] [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 front_up_left [email protected] front_up_right [email protected] _side_front_up [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 front_down_left [email protected] front_down_right [email protected] _side_front_down [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 back_up_left [email protected] back_up_right [email protected] _side_back_up [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 back_down_left [email protected] back_down_right [email protected] _side_back_down [email protected]

//chatmsg "%.2f %.2f %.2f %.2f" -1 [email protected] [email protected] [email protected] [email protected]

call @Interpolate 5 val [email protected] range 0.0 255.0 side_front_down [email protected] side_front_up [email protected] _side_vert_front [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 side_back_down [email protected] side_back_up [email protected] _side_vert_back [email protected]

call @Interpolate 5 val [email protected] range 0.0 255.0 side_vert_front [email protected] side_vert_back [email protected] _returnedValue [email protected]

/*
sideways_front_up = Interpolate(r, [0,1], [
    RYB_RGB_cube["front_up_left"][i],
    RYB_RGB_cube["front_up_right"][i]
    ])

sideways_front_down = Interpolate(r, [0,1], [
    RYB_RGB_cube["front_down_left"][i],
    RYB_RGB_cube["front_down_right"][i]
    ])

sideways_back_up = Interpolate(r, [0,1], [
    RYB_RGB_cube["back_up_left"][i],
    RYB_RGB_cube["back_up_right"][i]
    ])

sideways_back_down = Interpolate(r, [0,1], [
    RYB_RGB_cube["back_down_left"][i],
    RYB_RGB_cube["back_down_right"][i]
    ])
*/

//[email protected] *= 255.0
0092: [email protected] = float [email protected] to_integer
ret 1 [email protected]

:RYB_to_RGB
{
    [email protected] [email protected] [email protected] - Red, Yellow, Blue (integers 0-255)
    More info and python example: https://github.com/michalmonday/RGB_rainbowLoop/blob/master/RYB_RGB_conversion_rainbowLoop.py
}
0093: [email protected] = integer [email protected] to_float
0093: [email protected] = integer [email protected] to_float
0093: [email protected] = integer [email protected] to_float

call @RYB_to_RGB_GetSingleClr 11 RYB [email protected] [email protected] [email protected] interpolation_cube_corners 255.0 255.0 255.0 255.0 0.0 51.0 41.565 127.5 _returnedRed [email protected]
call @RYB_to_RGB_GetSingleClr 11 RYB [email protected] [email protected] [email protected] interpolation_cube_corners 255.0 127.5 255.0 0.0 168.3 23.97 95.115 0.0 _returnedGreen [email protected]
call @RYB_to_RGB_GetSingleClr 11 RYB [email protected] [email protected] [email protected] interpolation_cube_corners 0.0 0.0 255.0 0.0 51.0 0.0 153.0 127.5 _returnedBlue [email protected]

ret 3 [email protected] [email protected] [email protected] 

:Interpolate
{
    All floats:
    [email protected] - value
    [email protected] - Lower border of initial range
    [email protected] - Higher border of initial range
    [email protected] - Lower border of desired range
    [email protected] - Higher border of desired range
}
0087: [email protected] = [email protected] // float
0063: [email protected] -= [email protected]  // (s[1] - s[0])
0063: [email protected] -= [email protected] // (val - s[0])
0087: [email protected] = [email protected] // float
0063: [email protected] -= [email protected] // (s2[1] - s2[0])
006B: [email protected] *= [email protected]  // (s2[1] - s2[0]) * (val - s[0])
0073: [email protected] /= [email protected] // (s2[1] - s2[0]) * (val - s[0]) / (s[1] - s[0])
005B: [email protected] += [email protected]  // (float)
ret 1 [email protected]



//call @ShiftColor 2 speed_step 3 direction 1 variable_keeping_track [email protected]
:ShiftColorHue
{
    [email protected] - speed_step - how fast the color change occurs
    [email protected] - direction (1-rgb order, 2-reversed order)
    [email protected] - hue variable which needs to be dedicated for this snippet (it's actually the only variable that is required in external code for this snippet)
}
if [email protected] == 1
then
005A: [email protected] += [email protected]  // (int)
    if [email protected] > 359
    then
    [email protected] = 0
    end
end

if [email protected] == 2
then
0062: [email protected] -= [email protected]  // (int)
    if 001B:   0 > [email protected]
    then
    [email protected] = 359
    end
end
ret 1 [email protected] 

//call @GetRGBfromHSV 3 hue [email protected] saturation 1.0 value 1.0 _returnedRGB [email protected] [email protected] [email protected]
:GetCLRfromHSV
{
    [email protected] - Hue (0 - 360 int)
    [email protected] - Saturation  (0.0 - 1.0 float)
    [email protected] - Value (0.0 - 1.0 float)
}
0085: [email protected] = [email protected] // hue copy
0093: [email protected] = integer [email protected] to_float

//C = value * saturation
0087: [email protected] = [email protected] // C
006B: [email protected] *= [email protected]  // C

//X = C * (1.0 - abs((hue/60.0)%2 - 1.0))
0087: [email protected] = [email protected] // hue
[email protected] /= 60.0 // (hue/60.0)

if and  // fix for the bugged 0b14 (when float is used, idk if it happens with int too)
[email protected] >= 2.0 
0023:   4.0 > [email protected]
then
[email protected] -= 2.0
else
    if and 
    [email protected] >= 4.0 
    0023:   6.0 > [email protected]
    then
    [email protected] -= 4.0 
    else
        if and 
        [email protected] >= 6.0 
        0023:   8.0 > [email protected]
        then
        [email protected] -= 6.0 
        end
    end   
end

0B14: [email protected] = [email protected] MOD 2.0 // sampfuncs modulo function is probably not working for numbers that are at least twice as big, or because it's float... idk
//printf "X= %.2f" 1000 [email protected]
[email protected] -= 1.0
0097: make [email protected] absolute_float
[email protected] = 1.0
0063: [email protected] -= [email protected] // (1.0 - abs((hue/60.0)%2 - 1.0))
0087: [email protected] = [email protected] // X = C *
006B: [email protected] *= [email protected] // X = C * (1.0 - abs((hue/60.0)%2 - 1.0))

//m = value - C
0087: [email protected] = [email protected]
0063: [email protected] -= [email protected]  // m = value - C

// C = [email protected]
// X = [email protected]
// m = [email protected]

//printf "C= %.2f X= %.2f m= %.2f" 1000 [email protected] [email protected] [email protected]
 
//sectionList (0 - 0, C - 1, X - 2)
alloc [email protected] 100
0085: [email protected] = [email protected] // (int)
0085: [email protected] = [email protected] // (int)

//[C, X, 0],
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4

//[X, C, 0],
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4

//[0, C, X],
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4

//[0, X, C],
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4

//[X, 0, C],
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4

//[C, 0, X],
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0


//section = sectionList[hue/60]
[email protected] /= 60 // hue/60
[email protected] *= 12 
005A: [email protected] += [email protected]  // (int)
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
[email protected] += 4
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
[email protected] += 4
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0

// [email protected] [email protected] [email protected] have now values from 0 to 2 (they're just indicators)
0093: [email protected] = integer [email protected] to_float
0093: [email protected] = integer [email protected] to_float
0093: [email protected] = integer [email protected] to_float
call @AssignHSVSectionValue 3 [email protected] [email protected] [email protected] _ret [email protected]
call @AssignHSVSectionValue 3 [email protected] [email protected] [email protected] _ret [email protected]
call @AssignHSVSectionValue 3 [email protected] [email protected] [email protected] _ret [email protected]

005A: [email protected] += [email protected]  // (int)
005A: [email protected] += [email protected]  // (int)
005A: [email protected] += [email protected]  // (int)
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
0092: [email protected] = float [email protected] to_integer
0092: [email protected] = float [email protected] to_integer
0092: [email protected] = float [email protected] to_integer

free [email protected]

ret 3 [email protected] [email protected] [email protected]

:AssignHSVSectionValue
{
    [email protected] - indicator_1
    [email protected] - val_C
    [email protected] - val_X
}
if [email protected] == 0.0
then
ret 1 0.0
else
    if [email protected] == 1.0
    then
    ret 1 [email protected]
    else
        if [email protected] == 2.0
        then
        ret 1 [email protected]
        end
    end
end
ret 1 0.0
 
OP
OP
monday

monday

Well-Known Member
Joined
Jun 23, 2014
Messages
921
Likes
4
Points
68
#5
idk, I bet this guy knows: https://www.youtube.com/watch?v=8sgHR0L5Kac
@springfield (?)
 

_=Gigant=_

Well-Known Member
Joined
Mar 21, 2017
Messages
382
Likes
8
Points
23
#8
get player skin
get player struct

:getSkinParams
0A96: [email protected] = actor [email protected] struct

get bodypart and texture 
apply color to the texture (actor cloth)

0500:   player $PLAYER_CHAR skin == "GIMPLEG" on_bodypart 17

https://gtagmodding.com/sanandreas/player-body-parts/ 

make rainbow
 
Joined
Aug 9, 2017
Messages
16
Likes
0
Points
1
1
#9
_=Gigant=_ said:
get player skin
get player struct

:getSkinParams
0A96: [email protected] = actor [email protected] struct

get bodypart and texture 
apply color to the texture (actor cloth)

0500:   player $PLAYER_CHAR skin == "GIMPLEG" on_bodypart 17

https://gtagmodding.com/sanandreas/player-body-parts/ 

make rainbow
How can I apply color to the texture.I searched but I dont find.Sorry for my bad english.
 

_=Gigant=_

Well-Known Member
Joined
Mar 21, 2017
Messages
382
Likes
8
Points
23
#10
Stickey said:
How can I apply color to the texture.I searched but I dont find.Sorry for my bad english.
idk really for cleo i use c++ 

static int Color = 0xFFFF00FF;

if (Color < 0xFFFFFFFF)
(Color += 0xFFFF00FF);

sTexture->Begin(D3DXSPRITE_ALPHABLEND);
sTexture->SetTransform(&mat);
sTexture->Draw(tTexture, NULL, NULL, NULL, Color);
sTexture->End();
 
Joined
Aug 9, 2017
Messages
16
Likes
0
Points
1
1
#11
_=Gigant=_ said:
Stickey said:
How can I apply color to the texture.I searched but I dont find.Sorry for my bad english.
idk really for cleo i use c++ 

static int Color = 0xFFFF00FF;

if (Color < 0xFFFFFFFF)
(Color += 0xFFFF00FF);

sTexture->Begin(D3DXSPRITE_ALPHABLEND);
sTexture->SetTransform(&mat);
sTexture->Draw(tTexture, NULL, NULL, NULL, Color);
sTexture->End();
I dont know C++.I need it in cleo.Pls search for me!I need this very much.
 

shanker

Well-Known Member
Joined
Sep 18, 2016
Messages
238
Likes
2
Points
33
Location
Romania
#12
Stickey said:
_=Gigant=_ said:
Stickey said:
How can I apply color to the texture.I searched but I dont find.Sorry for my bad english.
idk really for cleo i use c++ 

static int Color = 0xFFFF00FF;

if (Color < 0xFFFFFFFF)
(Color += 0xFFFF00FF);

sTexture->Begin(D3DXSPRITE_ALPHABLEND);
sTexture->SetTransform(&mat);
sTexture->Draw(tTexture, NULL, NULL, NULL, Color);
sTexture->End();
I dont know C++.I need it in cleo.Pls search for me!I need this very much.
if u need this so much why dont you just do it by yourself?

why some one should search it / rewrite it for you? at least he gave you an example lmao kys  :areyoukiddingme:
 

user88

Well-Known Member
Joined
Jun 29, 2017
Messages
196
Likes
15
Points
23
Location
Afghanistan
#13
Selfmade things are prestige symbols in my oppinion

Just try it urself and if u need help were helping (Maybe)

Dont say give sauce
 
OP
OP
monday

monday

Well-Known Member
Joined
Jun 23, 2014
Messages
921
Likes
4
Points
68
#14
maybe this could be useful but idk:
http://gtaforums.com/topic/670975-sahow-to-change-the-color-of-objects/?p=1064905731
 
OP
OP
monday

monday

Well-Known Member
Joined
Jun 23, 2014
Messages
921
Likes
4
Points
68
#15
https://github.com/DK22Pac/plugin-sdk/tree/master/examples/PedPainting
 
OP
OP
monday

monday

Well-Known Member
Joined
Jun 23, 2014
Messages
921
Likes
4
Points
68
#18
I think it would be the best if you quoted the parts of the thread that you don't understand and then I'd try to expand their description or show some example of how that specific part works.
Because now I can only guess whether it's about being unfamiliar with scm functions or general cleo knowledge?

I added comments to the code so it's more clear what is going on and how it should be used:
Code:
/* 
INITIALIZATION THAT EVERY CLEO HAS
*/
{$CLEO}
0000: NOP


/*
WAITING FOR SAMP TO LOAD
*/
repeat
    wait 50
until 0AFA:  is_samp_available




/*
THE PART THAT HAS TO BE IMPLEMENTED BY YOU IN YOUR CODE
*/
[email protected] = 0  // hue 0 - 359 (variable required to keep track of the colour)   

while true
wait 0

    call @ShiftColorHue 3 speed_step 1 direction 1 hue_var [email protected] _returned_hue_var [email protected]    // it increases/decreases [email protected] variable between 0-359  (0 = fully red, ~119 = fully green  ~239 = fully blue, ~359 = almost fully red again)
    call @GetCLRfromHSV 3 hue [email protected] saturation 1.0 value 1.0 _returnedColor [email protected] [email protected] [email protected] //  conversion from 0-359 ([email protected]) to 3 Red ([email protected]) Green ([email protected]) Blue values ([email protected])
    call @RYB_to_RGB 3 RYB [email protected] [email protected] [email protected] _RGB [email protected] [email protected] [email protected]  // making the color less "highlighting" (more aesthetic in my opinion)
    
    0B67: render a 255 r [email protected] g [email protected] b [email protected] to_argb [email protected] // joining Red Green Blue variables into 1 variable ([email protected])
    call @Draw 1 [email protected]  // Drawing function that you have to implement using [email protected] color, [email protected] is the end product of this snippet, the goal of this snippet is to create this [email protected] color. The user has to draw things himself and implement his own drawing function using color provided by this snippet 
end

/*
END OF THAT PART
*/








/*
THE PART THAT HAS TO BE COPY/PASTED AT THE END OF YOUR CODE
*/

:Draw
0B5A: get_screen_resolution [email protected] [email protected]
[email protected]/=2
[email protected]/=3
0085: [email protected] = [email protected] // (int)
[email protected]/=2
0B70: render draw_polygon_pos [email protected] [email protected] size [email protected] [email protected] corners 8 rotation 0.0 color [email protected] //[email protected], [email protected] [int] [email protected], [email protected] [int], [email protected] [int], [email protected] [float], [email protected] [int]
ret 0


:RYB_to_RGB_GetSingleClr
{
    [email protected] - R
    [email protected] - Y
    [email protected] - B
    
    [email protected] - front_up_left : [1, 1, 0],
    [email protected] - front_up_right: [1, 0.5, 0],
    [email protected] - "front_down_left": [1, 1, 1],
    [email protected] - "front_down_right": [1, 0, 0],
    [email protected] - "back_up_left": [0, 0.66, 0.2],
    [email protected] - "back_up_right": [0.2, 0.094, 0],
    [email protected] - "back_down_left": [0.163, 0.373, 0.6],
    [email protected] - "back_down_right": [0.5, 0.0, 0.5],
}

/*
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
*/
//chatmsg "%.2f %.2f %.2f" -1 [email protected] [email protected] [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 front_up_left [email protected] front_up_right [email protected] _side_front_up [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 front_down_left [email protected] front_down_right [email protected] _side_front_down [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 back_up_left [email protected] back_up_right [email protected] _side_back_up [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 back_down_left [email protected] back_down_right [email protected] _side_back_down [email protected]

//chatmsg "%.2f %.2f %.2f %.2f" -1 [email protected] [email protected] [email protected] [email protected]

call @Interpolate 5 val [email protected] range 0.0 255.0 side_front_down [email protected] side_front_up [email protected] _side_vert_front [email protected]
call @Interpolate 5 val [email protected] range 0.0 255.0 side_back_down [email protected] side_back_up [email protected] _side_vert_back [email protected]

call @Interpolate 5 val [email protected] range 0.0 255.0 side_vert_front [email protected] side_vert_back [email protected] _returnedValue [email protected]

/*
sideways_front_up = Interpolate(r, [0,1], [
    RYB_RGB_cube["front_up_left"][i],
    RYB_RGB_cube["front_up_right"][i]
    ])

sideways_front_down = Interpolate(r, [0,1], [
    RYB_RGB_cube["front_down_left"][i],
    RYB_RGB_cube["front_down_right"][i]
    ])

sideways_back_up = Interpolate(r, [0,1], [
    RYB_RGB_cube["back_up_left"][i],
    RYB_RGB_cube["back_up_right"][i]
    ])

sideways_back_down = Interpolate(r, [0,1], [
    RYB_RGB_cube["back_down_left"][i],
    RYB_RGB_cube["back_down_right"][i]
    ])
*/

//[email protected] *= 255.0
0092: [email protected] = float [email protected] to_integer
ret 1 [email protected]

:RYB_to_RGB
{
    [email protected] [email protected] [email protected] - Red, Yellow, Blue (integers 0-255)
   More info and python example: https://github.com/michalmonday/RGB_rainbowLoop/blob/master/RYB_RGB_conversion_rainbowLoop.py
}
0093: [email protected] = integer [email protected] to_float
0093: [email protected] = integer [email protected] to_float
0093: [email protected] = integer [email protected] to_float

call @RYB_to_RGB_GetSingleClr 11 RYB [email protected] [email protected] [email protected] interpolation_cube_corners 255.0 255.0 255.0 255.0 0.0 51.0 41.565 127.5 _returnedRed [email protected]
call @RYB_to_RGB_GetSingleClr 11 RYB [email protected] [email protected] [email protected] interpolation_cube_corners 255.0 127.5 255.0 0.0 168.3 23.97 95.115 0.0 _returnedGreen [email protected]
call @RYB_to_RGB_GetSingleClr 11 RYB [email protected] [email protected] [email protected] interpolation_cube_corners 0.0 0.0 255.0 0.0 51.0 0.0 153.0 127.5 _returnedBlue [email protected]

ret 3 [email protected] [email protected] [email protected]

:Interpolate
{
    All floats:
    [email protected] - value
    [email protected] - Lower border of initial range
    [email protected] - Higher border of initial range
    [email protected] - Lower border of desired range
    [email protected] - Higher border of desired range
}
0087: [email protected] = [email protected] // float
0063: [email protected] -= [email protected]  // (s[1] - s[0])
0063: [email protected] -= [email protected] // (val - s[0])
0087: [email protected] = [email protected] // float
0063: [email protected] -= [email protected] // (s2[1] - s2[0])
006B: [email protected] *= [email protected]  // (s2[1] - s2[0]) * (val - s[0])
0073: [email protected] /= [email protected] // (s2[1] - s2[0]) * (val - s[0]) / (s[1] - s[0])
005B: [email protected] += [email protected]  // (float)
ret 1 [email protected]



//call @ShiftColor 2 speed_step 3 direction 1 variable_keeping_track [email protected]
:ShiftColorHue
{
    [email protected] - speed_step - how fast the color change occurs
    [email protected] - direction (1-rgb order, 2-reversed order)
    [email protected] - hue variable which needs to be dedicated for this snippet (it's actually the only variable that is required in external code for this snippet)
}
if [email protected] == 1
then
005A: [email protected] += [email protected]  // (int)
    if [email protected] > 359
    then
    [email protected] = 0
    end
end

if [email protected] == 2
then
0062: [email protected] -= [email protected]  // (int)
    if 001B:   0 > [email protected]
    then
    [email protected] = 359
    end
end
ret 1 [email protected]

//call @GetRGBfromHSV 3 hue [email protected] saturation 1.0 value 1.0 _returnedRGB [email protected] [email protected] [email protected]
:GetCLRfromHSV
{
    [email protected] - Hue (0 - 360 int)
    [email protected] - Saturation  (0.0 - 1.0 float)
    [email protected] - Value (0.0 - 1.0 float)
}
0085: [email protected] = [email protected] // hue copy
0093: [email protected] = integer [email protected] to_float

//C = value * saturation
0087: [email protected] = [email protected] // C
006B: [email protected] *= [email protected]  // C

//X = C * (1.0 - abs((hue/60.0)%2 - 1.0))
0087: [email protected] = [email protected] // hue
[email protected] /= 60.0 // (hue/60.0)

if and  // fix for the bugged 0b14 (when float is used, idk if it happens with int too)
[email protected] >= 2.0
0023:   4.0 > [email protected]
then
[email protected] -= 2.0
else
    if and
    [email protected] >= 4.0
    0023:   6.0 > [email protected]
    then
    [email protected] -= 4.0
    else
        if and
        [email protected] >= 6.0
        0023:   8.0 > [email protected]
        then
        [email protected] -= 6.0
        end
    end   
end

0B14: [email protected] = [email protected] MOD 2.0 // sampfuncs modulo function is probably not working for numbers that are at least twice as big, or because it's float... idk
//printf "X= %.2f" 1000 [email protected]
[email protected] -= 1.0
0097: make [email protected] absolute_float
[email protected] = 1.0
0063: [email protected] -= [email protected] // (1.0 - abs((hue/60.0)%2 - 1.0))
0087: [email protected] = [email protected] // X = C *
006B: [email protected] *= [email protected] // X = C * (1.0 - abs((hue/60.0)%2 - 1.0))

//m = value - C
0087: [email protected] = [email protected]
0063: [email protected] -= [email protected]  // m = value - C

// C = [email protected]
// X = [email protected]
// m = [email protected]

//printf "C= %.2f X= %.2f m= %.2f" 1000 [email protected] [email protected] [email protected]
 
//sectionList (0 - 0, C - 1, X - 2)
alloc [email protected] 100
0085: [email protected] = [email protected] // (int)
0085: [email protected] = [email protected] // (int)

//[C, X, 0],
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4

//[X, C, 0],
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4

//[0, C, X],
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4

//[0, X, C],
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4

//[X, 0, C],
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4

//[C, 0, X],
0A8C: write_memory [email protected] size 4 value 1 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 0 virtual_protect 0
[email protected]+=4
0A8C: write_memory [email protected] size 4 value 2 virtual_protect 0


//section = sectionList[hue/60]
[email protected] /= 60 // hue/60
[email protected] *= 12
005A: [email protected] += [email protected]  // (int)
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
[email protected] += 4
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
[email protected] += 4
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0

// [email protected] [email protected] [email protected] have now values from 0 to 2 (they're just indicators)
0093: [email protected] = integer [email protected] to_float
0093: [email protected] = integer [email protected] to_float
0093: [email protected] = integer [email protected] to_float
call @AssignHSVSectionValue 3 [email protected] [email protected] [email protected] _ret [email protected]
call @AssignHSVSectionValue 3 [email protected] [email protected] [email protected] _ret [email protected]
call @AssignHSVSectionValue 3 [email protected] [email protected] [email protected] _ret [email protected]

005A: [email protected] += [email protected]  // (int)
005A: [email protected] += [email protected]  // (int)
005A: [email protected] += [email protected]  // (int)
[email protected] *= 255.0
[email protected] *= 255.0
[email protected] *= 255.0
0092: [email protected] = float [email protected] to_integer
0092: [email protected] = float [email protected] to_integer
0092: [email protected] = float [email protected] to_integer

free [email protected]

ret 3 [email protected] [email protected] [email protected]

:AssignHSVSectionValue
{
    [email protected] - indicator_1
    [email protected] - val_C
    [email protected] - val_X
}
if [email protected] == 0.0
then
ret 1 0.0
else
    if [email protected] == 1.0
    then
    ret 1 [email protected]
    else
        if [email protected] == 2.0
        then
        ret 1 [email protected]
        end
    end
end
ret 1 0.0

 
Top