simple Spectrum cycle

Post here your demos and examples with the source files.
Forum rules
Always post the games with a screenshot.
The file must have the ged and data files (complete game source)
Use the forum attachment to post the files.
It is always better to use the first post to put the game files

simple Spectrum cycle

Postby JamesLeonardo32 » Sat Dec 10, 2011 1:05 am

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".
Attachments
simpleSpectrum.ged
(1.09 KiB) Downloaded 269 times
spec.png
JamesLeonardo32
 
Posts: 320
Joined: Wed Oct 13, 2010 4:57 pm
Score: 36 Give a positive score

Re: simple Spectrum cycle

Postby Camper1995 » Sun Dec 11, 2011 9:17 pm

Neat. Now make this as a function and it'll be great. ;)
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: simple Spectrum cycle

Postby SuperSonic » Mon Dec 12, 2011 6:10 pm

Hey, that's cool :D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: simple Spectrum cycle

Postby CoFFiN6 » Wed Dec 14, 2011 3:06 pm

Wow this would look awsum on main menu backgrounds. nice! :D
Don't run faster then the dragon, run faster than your friends :P
User avatar
CoFFiN6
 
Posts: 49
Joined: Sun Sep 11, 2011 8:17 pm
Location: South Africa
Score: 4 Give a positive score

Re: simple Spectrum cycle

Postby JamesLeonardo32 » Thu Dec 15, 2011 8:25 am

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.
JamesLeonardo32
 
Posts: 320
Joined: Wed Oct 13, 2010 4:57 pm
Score: 36 Give a positive score

Re: simple Spectrum cycle

Postby DST » Fri Dec 16, 2011 8:53 pm

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;
}
Last edited by DST on Fri Dec 16, 2011 9:30 pm, edited 1 time in total.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: simple Spectrum cycle

Postby JamesLeonardo32 » Fri Dec 16, 2011 9:24 pm

Excellent, I'll look into using this.
=>
JamesLeonardo32
 
Posts: 320
Joined: Wed Oct 13, 2010 4:57 pm
Score: 36 Give a positive score

Re: simple Spectrum cycle

Postby tintran » Fri Dec 16, 2011 10:18 pm

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).
Attachments
pacman.jpg
randomSpetrum.ged
(1.82 KiB) Downloaded 191 times
User avatar
tintran
 
Posts: 157
Joined: Fri Dec 24, 2010 1:34 am
Score: 30 Give a positive score

Re: simple Spectrum cycle

Postby JamesLeonardo32 » Fri Dec 16, 2011 11:44 pm

My eyes... :shock:

But still, good coding. I might use it!
JamesLeonardo32
 
Posts: 320
Joined: Wed Oct 13, 2010 4:57 pm
Score: 36 Give a positive score


Return to Game Demos

Who is online

Users browsing this forum: No registered users and 1 guest

cron