Skip to content

Instantly share code, notes, and snippets.

@bitbrain
Last active October 17, 2023 17:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitbrain/605b77bcbf15e2d2ddb61dfd6c2d851c to your computer and use it in GitHub Desktop.
Save bitbrain/605b77bcbf15e2d2ddb61dfd6c2d851c to your computer and use it in GitHub Desktop.
A gd script implementing a day night cycle using maths only.
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)
@dadrox
Copy link

dadrox commented Jul 31, 2023

For Godot 4: change linear_interpolate to lerp

@Mashedpotato98
Copy link

lets gooo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment