Advertisement
metalx1000

Godot Map/Lerp a Range of numbers

Sep 15th, 2022
2,711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Godot GLSL 0.61 KB | Source Code | 0 0
  1. extends Node2D
  2.  
  3. onready var label = $Label
  4. onready var color_1 = $ColorRect
  5. onready var color_2 = $ColorRect2
  6.  
  7. func _ready():
  8.     pass # Replace with function body.
  9.  
  10. func _process(delta):
  11.     var x = get_global_mouse_position().x
  12.     var y = get_global_mouse_position().y
  13.     var w = get_viewport().size.x
  14.     var h = get_viewport().size.y
  15.  
  16.     var v1 = range_lerp(x,0,w,0,255)
  17.     var v2 = range_lerp(x,0,w,255,0)
  18.     var v3 = range_lerp(y,0,h,255,0)
  19.    
  20.     label.text = "v1: " + String(v1) + "\nv2: " + String(v2)
  21.     label.text += "\nv3: " + String(v3)
  22.      
  23.     color_1.color = Color8(v3,v3,v1)
  24.     color_2.color = Color8(v2,v3,v3)
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement