Page 1 of 1

simple Spectrum cycle

PostPosted: Sat Dec 10, 2011 1:05 am
by JamesLeonardo32
Heres a very simple code i was using in AXRIA, but decided to share with thou.

All it requires is a Draw actor function using vairables of r, g, b. Plus a special actor vairable that in this case i've called "fade".

Re: simple Spectrum cycle

PostPosted: Sun Dec 11, 2011 9:17 pm
by Camper1995
Neat. Now make this as a function and it'll be great. ;)

Re: simple Spectrum cycle

PostPosted: Mon Dec 12, 2011 6:10 pm
by SuperSonic
Hey, that's cool :D

Re: simple Spectrum cycle

PostPosted: Wed Dec 14, 2011 3:06 pm
by CoFFiN6
Wow this would look awsum on main menu backgrounds. nice! :D

Re: simple Spectrum cycle

PostPosted: Thu Dec 15, 2011 8:25 am
by JamesLeonardo32
Camper1995 wrote:Neat. Now make this as a function and it'll be great. ;)

If i learn to, I will. =)

CoFFiN6 wrote:Wow this would look awsum on main menu backgrounds.


Indeed it would.

Re: simple Spectrum cycle

PostPosted: Fri Dec 16, 2011 8:53 pm
by DST
Here are a couple alternate methods for this.

global Code:
Code: Select all
int coldir=0;
 
void changeColor(int rate) {
    switch(coldir) {
    case 0:
      g+=rate;
      if (g>=255) {
        coldir++;
      }
      break;
    case 1:
      r-=rate;
      if (r<=0) {
        coldir++;
      }
      break;
    case 2:
      b+=rate;
      if (b>=255) {
        coldir++;
      }
      break;
    case 3:
      g-=rate;
      if (g<=0) {
        coldir++;
      }
      break;
    case 4:
      r+=rate;
      if (r>=255) {
        coldir++;
      }
      break;
    case 5:
      b-=rate;
      if (b<=0) {
        coldir=0;
      }
      break;
    }
  }


And an even simpler one:

global Code:
Code: Select all
float colSpeed=4;
int colDir=0;
int colSwitch=0;
int colValues[][]={{1, 0, 0},{0, 0, -1},{0, 1, 0},{-1, 0, 0},{0, 0, 1},{0, -1, 0}};

void rotateColor(){
  colSwitch+=colSpeed;
  if(colSwitch>=255){
    colSwitch=0;
    colDir++;
    colDir=iLoop(colDir, 0, 5);
  }
r+=colValues[colDir][0]*colSpeed;
g+=colValues[colDir][1]*colSpeed;
b+=colValues[colDir][2]*colSpeed;
}


This one is what i use now. It references another function, iLoop() but i always have that function in every game i make anyway. It's a super useful function. Using data arrays to control things is much simpler than if's or switches. In addition, you don't have to test things as much. If you want your enemy to shoot a spread pattern, you can just write the data array right before your spread() function.
viewtopic.php?f=5&t=6854&start=90#p80105

Note that you wouldn't use r, g, or b values directly like that. I just changed them to that to make it apparent, because all of this should be in global code. This way, you can run one master color cycle, dump it to three global rgb variables, and have lots of Actors access those colors. You can have some use 255- those values to display the opposite color.


Here's the loop/Constrain functions. Like i said, i have them in every program i write.

Code: Select all
int iConstrain(int xx, int ll, int ul){
  if(xx<ll){xx=ll;}
  if(xx>ul){xx=ul;}
  return xx;
}

float fConstrain(float xx, float ll, float ul){
  if(xx<ll){xx=ll;}
  if(xx>ul){xx=ul;}
  return xx;
}

int iLoop(int xx, int ll, int ul){
  if(xx<ll){xx=ul;}
  else if(xx>ul){xx=ll;
  }
  return xx;
}

float fLoop(float xx, float ll, float ul){
  if(xx<ll){xx=ul;}
  else if(xx>ul){xx=ll;
  }
  return xx;
}

Re: simple Spectrum cycle

PostPosted: Fri Dec 16, 2011 9:24 pm
by JamesLeonardo32
Excellent, I'll look into using this.
=>

Re: simple Spectrum cycle

PostPosted: Fri Dec 16, 2011 10:18 pm
by tintran
here's a random spectrum with linear fade between random target colors. :) it uses a bunch of actor variables to record original rgb values and target rgb values.
int the .ged the code for target rgb values is rand(200)+55; to prevent colors from getting to dark but in testing i find that rand(240)+15; is much cooler.
shown image is an example of the spectrum as it runs, the .ged doesn't show that debug (it's just a simple CreateActor and copy rgb values over as it runs it is only to show you a possible spectrum it runs through, but there's no guarantee since it is random).

Re: simple Spectrum cycle

PostPosted: Fri Dec 16, 2011 11:44 pm
by JamesLeonardo32
My eyes... :shock:

But still, good coding. I might use it!