Jump to content



1

How do we cycle colors from low to high and back down again (twice)?


8 replies to this topic

#1 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,923 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Sep 14, 2011 12:01 AM

I need to cycle from $40 to $46, then from $46 to $40, but I need to do it twice in a row.

The only thing I can think of uses bloated code, a whole variable as a counter and too many bits. Is there a simpler, easier way to ping pong though a range of colors for a certain number of times?


Thanks.

#2 disjaukifa OFFLINE  

disjaukifa

    River Patroller

  • 2,088 posts
  • Berzerker In Training
  • Location:Southwest Virginia

Posted Wed Sep 14, 2011 12:17 AM

Random

That's how I do it. I just use a frame counter for a continues loop. If you only need to be done twice you could either use bit operators or a for loop and use the temp5 variable for your for loop.

#3 jrok OFFLINE  

jrok

    Stargunner

  • 1,108 posts

Posted Wed Sep 14, 2011 1:02 AM

View PostRandom Terrain, on Wed Sep 14, 2011 12:01 AM, said:

I need to cycle from $40 to $46, then from $46 to $40, but I need to do it twice in a row.

The only thing I can think of uses bloated code, a whole variable as a counter and too many bits. Is there a simpler, easier way to ping pong though a range of colors for a certain number of times?


Thanks.


Since the color array is static, how about just use a pointer and a data table.


 
 data colorflash 
 $40,$42,$44,$46,$44,$42,$40,$42,$44,$46,$44,$42,$40
end
 

Loop

 COLUBK = 0

 if a < colorflash_length-1 then a = a + 1 :  COLUBK = colorflash[a]

 if joy0fire then a = 0

 drawscreen

 goto Loop

Edited by jrok, Wed Sep 14, 2011 1:04 AM.


#4 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,923 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Sep 14, 2011 5:14 AM

View Postjrok, on Wed Sep 14, 2011 1:02 AM, said:

Since the color array is static, how about just use a pointer and a data table.


 
 data colorflash 
 $40,$42,$44,$46,$44,$42,$40,$42,$44,$46,$44,$42,$40
end
 

Loop

 COLUBK = 0

 if a < colorflash_length-1 then a = a + 1 :  COLUBK = colorflash[a]

 if joy0fire then a = 0

 drawscreen

 goto Loop
That's a heck of a lot easier than the stupid, bloated crap I was trying to do.


Thanks.

#5 ScumSoft OFFLINE  

ScumSoft

    Moonsweeper

  • 331 posts
  • Location:Polysorbate 60

Posted Wed Sep 14, 2011 5:18 PM

I would just do this instead:

 dim color = a
 dim FrameNum = b

 rem set starting color
 color = $40

Loop
 drawscreen
 FrameNum = FrameNum + 1
 
 rem cycle color from 40 and 46 every other frame
 if FrameNum{0} then color = color ^ 6

 COLUBK = color
 goto Loop


#6 jrok OFFLINE  

jrok

    Stargunner

  • 1,108 posts

Posted Wed Sep 14, 2011 5:54 PM

View PostScumSoft, on Wed Sep 14, 2011 5:18 PM, said:

I would just do this instead:

 dim color = a
 dim FrameNum = b

 rem set starting color
 color = $40

Loop
 drawscreen
 FrameNum = FrameNum + 1
 
 rem cycle color from 40 and 46 every other frame
 if FrameNum{0} then color = color ^ 6

 COLUBK = color
 goto Loop

I was working under the assumption that he wanted to limit RAM usage, and have an effect that was simple to restart and stop after two iterations. My version uses 22 more bytes of ROM, but it only uses 1 byte of RAM and resets to defaults after two flashes.

And - maybe I was wrong in assuming this - but I figured that the "flash" effect itself was something that would start when a certain condition was triggered, like a ship being smacked with a missile, and stop after a certain duration.

In that spirit, I put together a little demo showing how 9 bits can be used to trigger a color & sound event. This could be optimized in a bunch of ways (including storing both the color and sound effect in a single data table), but I get the feeling that this is somewhat along the lines of what RT was looking for.

Attached Files


Edited by jrok, Wed Sep 14, 2011 5:54 PM.


#7 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,923 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Sep 14, 2011 5:54 PM

View PostScumSoft, on Wed Sep 14, 2011 5:18 PM, said:

I would just do this instead . . .
Thanks. Using data was good for this situation because I ended up changing the pattern and added a series of different colors at the end of it.

#8 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,923 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Sep 14, 2011 6:01 PM

View Postjrok, on Wed Sep 14, 2011 5:54 PM, said:

. . . but I get the feeling that this is somewhat along the lines of what RT was looking for.
I needed to change the color of the score background after shooting 100 bits of seaweed. Data worked great for what I ended up doing.

I hoped to upload the latest unfinished version of Seaweed Assault today, but it's taking longer than I planned.

#9 ScumSoft OFFLINE  

ScumSoft

    Moonsweeper

  • 331 posts
  • Location:Polysorbate 60

Posted Thu Sep 15, 2011 2:41 AM

No problem, it's all good. Thought this was like that other post looking to flip 255 and 1, with only two values returned.
Don't mind me :) carry on.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users