Last active
June 19, 2024 10:30
-
-
Save bitbrain/605b77bcbf15e2d2ddb61dfd6c2d851c to your computer and use it in GitHub Desktop.
A gd script implementing a day night cycle using maths only.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends CanvasModulate | |
const NIGHT_COLOR = Color("#091d3a") | |
const DAY_COLOR = Color("#ffffff") | |
const EVENING_COLOR = Color("#ff3300") | |
const TIME_SCALE = 0.1 | |
var time = 0 | |
func _process(delta:float) -> void: | |
self.time += delta * TIME_SCALE | |
var value = (sin(time) + 1) / 2 | |
self.color = get_source_colour(value).linear_interpolate(get_target_colour(value), value) | |
func get_source_colour(value): | |
return NIGHT_COLOR.linear_interpolate(EVENING_COLOR, value) | |
func get_target_colour(value): | |
return EVENING_COLOR.linear_interpolate(DAY_COLOR, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Godot 4: change
linear_interpolate
tolerp