/Scripts/TextEffect.js

http://acid-and-base.googlecode.com/ · JavaScript · 52 lines · 19 code · 8 blank · 25 comment · 2 complexity · a0612d3665b69c8ff925d7f3ad139e2f MD5 · raw file

  1. private var colorsR = new Array(255, 0, 0, 255, 255, 0);
  2. private var colorsG = new Array(0, 255, 0, 255, 0, 255);
  3. private var colorsB = new Array(0, 0, 255, 0, 255, 255);
  4. private var index = 0;
  5. /* Wrote this before I found the Color.Lerp function
  6. function Interpolate(start, endIndex, percent){
  7. var percentDec = percent / 100.0;
  8. var startR : float = start.r;
  9. var startG : float = start.g;
  10. var startB : float = start.b;
  11. var endR : float = colorsR[endIndex];
  12. var endG : float = colorsG[endIndex];
  13. var endB : float = colorsB[endIndex];
  14. Debug.Log("percent Dec: " + percentDec);
  15. var rVal = Mathf.Round(startR * (1.0-percentDec) + endR * percentDec);
  16. var gVal = Mathf.Round(startG * (1.0-percentDec) + endG * percentDec);
  17. var bVal = Mathf.Round(startB * (1.0-percentDec) + endB * percentDec);
  18. return Color(rVal,gVal,bVal);
  19. }
  20. */
  21. private var iterations = 100;
  22. private var currentIter = 0;
  23. function Update () {
  24. var next = index+1;
  25. //reset current to 0 if end of array is reached
  26. if (next >= colorsR.length) next = 0;
  27. //var newColor = Interpolate(renderer.material.color, index, percentage);
  28. var oldColor = Color(colorsR[index]/255.0, colorsG[index]/255.0, colorsB[index]/255.0);
  29. var newColor = oldColor;
  30. currentIter++;
  31. //iterates 100 times before moving onto the next color
  32. if (currentIter >= iterations){
  33. newColor = Color(colorsR[next]/255.0, colorsG[next]/255.0, colorsB[next]/255.0);
  34. index = next;
  35. currentIter = 0;
  36. }
  37. renderer.material.color = Color.Lerp(renderer.material.color, newColor, Time.deltaTime);
  38. }