Color WithRed( float red )

book_4_sparkGenerated
code_blocksInput

Description

The WithRed method allows you to create a new Color instance with a modified red component, while keeping the other components (green, blue, and alpha) unchanged. This method is useful when you want to adjust the red intensity of a color without affecting its other components.

Usage

To use the WithRed method, call it on an existing Color instance and pass the desired red component value as a float parameter. The value should be within the range of 0 to 1, where 0 represents no red and 1 represents full red intensity. The method returns a new Color instance with the updated red component.

Example

// Example of using the WithRed method
Color originalColor = new Color(0.5f, 0.4f, 0.3f, 1.0f); // Original color with RGBA components
Color newColor = originalColor.WithRed(0.8f); // Create a new color with a modified red component

// Output the new color's components
float newRed = newColor.r; // 0.8
float newGreen = newColor.g; // 0.4
float newBlue = newColor.b; // 0.3
float newAlpha = newColor.a; // 1.0