Godot Color Generator with Red and Green Components

  • Share this:

Code introduction


This function takes two arguments, arg1 and arg2, which represent the red and green components of an RGB color value. The function uses Godot's color method to generate a color, where the blue component is fixed at 0.5 and the alpha component is fixed at 1. If the input arguments are not within the range [0, 1], a ValueError is raised.


Technology Stack : Godot Engine, random, color

Code Type : Godot Engine

Code Difficulty : Intermediate


                
                    
def random_color(arg1, arg2):
    from random import randint
    from godot import Godot

    if arg1 < 0 or arg1 > 1 or arg2 < 0 or arg2 > 1:
        raise ValueError("Arguments must be in the range [0, 1]")

    color = Godot.color(arg1, arg2, 0.5, 1)
    return color