Advertisement
AceScottie

main.gd

Sep 16th, 2018
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. extends Spatial
  2. #scene root:
  3. #----MeshInstance
  4. #----HSlider (0, 512, step=1_
  5. #----Camera:
  6. #--------Direction Light
  7.  
  8. func _ready():
  9. pass
  10.  
  11.  
  12. func get_percent(cur, pmin, pmax):
  13. var r = 0
  14. var g = 0
  15. var x= 0
  16. if cur >= pmax:
  17. cur = cur-pmax-pmin
  18. x = 1
  19. else:
  20. cur = cur-pmin
  21. x = 0
  22. cur+=1
  23. if cur > 255:
  24. cur = 255
  25. print(cur)
  26. var percent = int(float(cur)/(float(pmax)/100.0))
  27. print(percent)
  28. if percent == 0:
  29. percent =1
  30. if x == 1:
  31. r= 255.0-((float(cur)/100.0)*float(percent))
  32. g= 255.0
  33. else:
  34. r= 255.0
  35. g= 0.0+((float(cur)/100.0)*float(percent))
  36. return Color(int(r), int(g), int(0), int(1))
  37.  
  38. func change_material(colour):
  39. var set_material = FixedMaterial.new()
  40. set_material.set_parameter(set_material.PARAM_DIFFUSE, colour)
  41. self.get_node("MeshInstance").set("material/0", set_material)
  42.  
  43.  
  44. func _on_HSlider_value_changed( value ):
  45. var col = get_percent(value, 0, 255)
  46. change_material(col)
  47. print(col)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement