Thread: Color Cycle
View Single Post
  #1  
Old 05-14-2008, 06:58 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Color Cycle

A simple color cycle. It will turn one number (input) in to a RGB color Graal can understand.

PHP Code:
function ColorCycle(i) {
  
temp.i = i % 114;
  
temp.r = max((sin(max(i, 0) / 12)), 0.01);
  
temp.g = max((sin(max(i - 16, 0) / 16)), 0.01);
  
temp.b = max((sin(max(i - 36, 0) / 20)), 0.01);
  return {
r, g, b};
} 



Example:
PHP Code:
//#CLIENTSIDE
for(temp.i = 0; temp.i < 255; temp.i ++) {
  
showimg(200, "light2.png", x, y);
  
temp.color = colorcycle(i);
  
changeimgcolors(200, color[0], color[1], color[2], 0.99);
  
sleep(0.05);
} 
The light will cycle through all of the colors of the rainbow.


Another example:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
showimg(200, "light2.png", 200, 200);
  
changeimgvis(200, 4);
  
onCreateColor();
  
onTimeout();
}

function 
onCreateColor() {
  new 
GuiWindowCtrl("Color_Window1") {
    
profile = GuiBlueWindowProfile;
    
clientrelative = true;
    
clientextent = "90,90";

    
canmaximize = false;
    
canminimize = false;
    
canmove = true;
    
canresize = false;
    
closequery = false;
    
destroyonhide = false;
    
showtop();
    
text = "Color";
    
x = 50;
    
y = 50;
    new 
GuiShowImgCtrl("Color_Table") {
      
x = y = 0;
      
width = height = 90;
      
image = "tig-colortab.png";
    }
    new 
GuiShowImgCtrl("Color_Cursor") {
      
x = y = 0;
      
image = "tig-colorcursor.png";
    }
  }
}

function 
onTimeout() {
  if (
leftmousebuttonglobal) {
    if (
mousescreenx in |Color_Window1.x + 6, Color_Window1.x + Color_Window1.width - 5| &&
      
mousescreeny in |Color_Window1.y + 24, Color_Window1.y + Color_Window1.height - 5|) {
      
this.mx = Color_Table.globaltolocalcoord({mousescreenx, mousescreeny});
      
Color_Cursor.x = this.mx[0] - 6;
      
Color_Cursor.y = this.mx[1] - 6;
      
temp.color = colorcycle(this.mx[0]);
      
changeimgcolors(200, color[0], color[1], color[2], 0.99);
    }
  }
  
setTimer(0.05);
} 
(See attachment images for this example)
This script will allow you to select any color you want.
Attached Images
  
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 05-15-2008 at 04:11 AM..
Reply With Quote