The_Dark_Side_of_Earth/background/bg_image.gd

14 lines
644 B
GDScript3
Raw Permalink Normal View History

2025-09-24 17:43:16 +02:00
extends TextureRect
@export var colors : Array[Color] = [Color(0.3, 1, 1) * 0.7, Color(1, 0.6, 0.6) * 0.7, Color(1, 1, 1) * 0.7]
# Modulate the background with an interpolation of the colors in the list,
# depending on the players position on the earth.
2025-09-24 17:43:16 +02:00
func _process(_delta: float) -> void:
var index : int = floor((%Player.position.angle() + PI)/ TAU * colors.size())
var diff = (%Player.position.angle() + PI)/ TAU * colors.size() - index
self.modulate = linear_color_interpolation(colors[index], colors[(index + 1) % colors.size()], diff)
func linear_color_interpolation(c1 : Color, c2 : Color, t : float):
return c1 + (c2 - c1) * t