Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Color Cycle (https://forums.graalonline.com/forums/showthread.php?t=79730)

Tigairius 05-14-2008 06:58 AM

Color Cycle
 
2 Attachment(s)
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.

Robin 05-14-2008 08:29 AM

PHP Code:

for(temp.i = 0; temp.i < 255; temp.i ++) {
  
showimg(200, "light2.png", x, y);
  
temp.color = colorcycle(i);
  
changeimgcolors(200, temp.color[0], temp.color[1], temp.color[2], 0.99);
  
sleep(0.05);
} 

So it's not calling your function 765 times :P

Tigairius 05-14-2008 08:47 AM

Quote:

Originally Posted by Robin (Post 1390734)
So it's not calling your function 765 times :P

Meant to change that before I released it, thanks :p.

zokemon 05-14-2008 10:55 AM

Seems to only support hue? What about saturation and luminosity? :frown:

Tigairius 05-14-2008 05:40 PM

Quote:

Originally Posted by zokemon (Post 1390748)
Seems to only support hue? What about saturation and luminosity? :frown:

Well the actual thing I'm submitting is the simple color cycle lol. If I were to actually script a color table there is a more efficient way of doing it.

Tigairius 05-14-2008 06:59 PM

Some more examples:

This example will generate your own color table.
PHP Code:

//#CLIENTSIDE
for (temp.i = 0; temp.i < 115; temp.i ++) {
  
showpoly(300 + i, {p[0] + i, p[1], p[0] + 1 + i, p[1] + 100});
  
changeimgvis(300 + i, 4);
  
temp.color = ColorCycle(i);
  
changeimgcolors(300 + i, color[0], color[1], color[2], 1);
} 

This will generate another color table with a triangular shape:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
temp.w = 115;
  
temp.h = 10;
  for (
temp.i = 0; temp.i < w * h; temp.i ++) {
    
temp.color = ColorCycle(i);
    
showpoly(300 + i, {p[0] + ((p[0] + i) % w), p[1] + int(i / w), (p[0] + i / 23 + 1), p[1] + int(i / w * h) + 1, (p[0] + 1)});
    
changeimgcolors(300 + i, color[0], color[1], color[2], 1 - (int(i / w)) / 100);
    
changeimgvis(300 + i, 4);
  }
} 


DustyPorViva 05-14-2008 07:05 PM

Did you know of:

getimgpixel("imagename.png",posx,posy);

Returns the Graal equivalent RGB of the position in an image?
I don't know if it's related(I kind of browsed through), but you would be able to take a color map image, and use it to find the RGB values just by clicking on it.

Tigairius 05-14-2008 07:07 PM

Quote:

Originally Posted by DustyPorViva (Post 1390768)
Did you know of:

getimgpixel("imagename.png",posx,posy);

Returns the Graal equivalent RGB of the position in an image?
I don't know if it's related(I kind of browsed through), but you would be able to take a color map image, and use it to find the RGB values just by clicking on it.

Yes, that's what I meant by, "If I were to actually script a color table there is a more efficient way of doing it." :p

Galdor 05-14-2008 07:44 PM

cool tig :) I like colors.

Crow 05-14-2008 08:05 PM

That's pretty awesome. I think I will find some use for this :D

Tigairius 05-14-2008 08:22 PM

Quote:

Originally Posted by Galdor (Post 1390771)
cool tig :) I like colors.

Me too! :p

Tigairius 05-15-2008 01:35 AM

Quote:

Originally Posted by zokemon (Post 1390748)
Seems to only support hue? What about saturation and luminosity? :frown:

Added it in for you :D

Below is an example of hue, saturation and luminosity.
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.a = 0.99;
  
this.sat = 0;
  
this.mx = {15, 0};
  
temp.p = {screenwidth / 2, screenheight / 2};

  
showimg(200, "light4.png", 200, 200);
  
changeimgvis(200, 4);
  
temp.color = colorcycle(this.mx[0]);
  
changeimgcolors(200, color[0] - color[0] / 2 + this.sat, color[1] - color[1] / 2 + this.sat, color[2] - color[2] / 2 + this.sat, this.a);

  
onCreateColor();
  
onTimeout();
}

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

    
canmaximize = false;
    
canminimize = false;
    
canmove = true;
    
canresize = false;
    
closequery = false;
    
destroyonhide = false;
    
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";
    }
    new 
GuiSliderCtrl("Color_Slider1") {
      
profile = GuiBlueSliderProfile;
      
height = 20;
      
range = "0,80";
      
ticks = 80;
      
value = 80;
      
width = 77;
      
x = 7;
      
y = 107;
    }
    new 
GuiTextCtrl("Color_Text1") {
      
profile = GuiBlueTextProfile;
      
height = 20;
      
text = "Saturation:";
      
width = 52;
      
x = 7;
      
y = 90;
    }
    new 
GuiTextCtrl("Color_Text2") {
      
profile = GuiBlueTextProfile;
      
height = 20;
      
text = "Luminosity:";
      
width = 60;
      
x = 10;
      
y = 120;
    }
    new 
GuiSliderCtrl("Color_Slider2") {
      
profile = GuiBlueSliderProfile;
      
height = 20;
      
range = "0,99";
      
ticks = 99;
      
value = 99;
      
width = 77;
      
x = 7;
      
y = 141;
    }
  }
}

function 
Color_Slider2.onReleaseSlider(value) {
  
this.a = value / 100;
  
temp.color = colorcycle(this.mx[0]);
  
changeimgcolors(200, color[0] - color[0] / 2 + this.sat, color[1] - color[1] / 2 + this.sat, color[2] - color[2] / 2 + this.sat, this.a);
}

function 
Color_Slider1.onReleaseSlider(value) {
  
this.sat = 1 - abs(value / 100);
  
temp.color = colorcycle(this.mx[0]);
  
changeimgcolors(200, color[0] - color[0] / 2 + this.sat, color[1] - color[1] / 2 + this.sat, color[2] - color[2] / 2 + this.sat, this.a);
}

function 
onTimeout() {
  if (
leftmousebuttonglobal) {
    if (
mousescreenx in |Color_Window1.x + 6, Color_Window1.x + Color_Table.width + 7| &&
      
mousescreeny in |Color_Window1.y + 24, Color_Window1.y + 115|) {
      
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[0] / 2 + this.sat, color[1] - color[1] / 2 + this.sat, color[2] - color[2] / 2 + this.sat, this.a);
    }
  }
  
setTimer(0.05);
} 


cbk1994 05-15-2008 01:56 AM

Nice addition, I will probably be using this!

smirt362 05-15-2008 12:26 PM

I don't understand the script, but I'm understanding what it's for...very awesome!

Tigairius 05-15-2008 06:43 PM

Crow was complaining about the green channel being misplaced (not enough yellow) so the math was pretty much completely redone.
PHP Code:

function ColorCycle(i) {
  
temp.i = i % 100;
  
temp.r = max((sin(max(i + 8, 0) / 12)), 0.01);
  
temp.g = max((sin(max(i + 1, 0) / 22)), 0.01);
  
temp.b = max((sin(max(i - 26, 0) / 21)), 0.01);
  return {
r, g, b};
} 


Crow 05-15-2008 08:49 PM

Quote:

Originally Posted by Tigairius (Post 1390872)
(not enough yellow)

There was no yellow at all ;D

Rapidwolve24 05-18-2008 01:30 AM

Cool script.


All times are GMT +2. The time now is 01:08 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.