Hey I made this awhile ago in a different programming language. Does anyone know how I can recreate the eyes as an image that is changing colors?
Here is the pseudocode for how you might do that:
create a variable called "hue"
create a constant called period
each frame:
increase hue by Time.deltaTime / period
set hue to hue%1 (remainder when divided by 1)
set the color to Color.HSVToRGB(hue, 1f, 1f)
(with a sprite you'd use SpriteRenderer.color)
The hue is a value between 0 and 1, which determines the hue in the HSV color space
You add Time.deltaTime so that the hue variable changes according to how much time has passed since the last frame (technically the time between the last 2 frames, but don’t worry about that)
The period constant is how much time you want for it to cycle through all colors (a period of 2 takes 2 seconds to cycle through all colors). It works by scaling the speed at which hue changes.
The mod (%) makes it so it doesn’t overflow, essentially keeping it between 0 and 1.
The Color.HSVtoRGB() is a neat way to go from hue to the desired color. You can change the first 1f to any value between 0 and 1, which changes how saturated it is. You can change the second 1f to change its value (essentially brightness).
Here’s a simplified example using Python and OpenCV:
pythonCopy code
import cv2
import numpy as np
import time
# Load base eye image
base_eye_image = cv2.imread('base_eye_image.png')
# Define colors to cycle through
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] # Example: Red, Green, Blue
# Main loop for color animation
while True:
# Iterate through colors
for color in colors:
# Copy base image to avoid modifying original
eye_image = base_eye_image.copy()
# Change eye color
eye_image[:, :, :] = color
# Display updated image
cv2.imshow('Changing Eye Color', eye_image)
cv2.waitKey(500) # Adjust timing as needed
Thanks! it works :))