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.114;
  
temp.max((sin(max(i0) / 12)), 0.01);
  
temp.max((sin(max(160) / 16)), 0.01);
  
temp.max((sin(max(360) / 20)), 0.01);
  return {
rgb};





Example:
PHP Code:

//#CLIENTSIDE
for(temp.0temp.255temp.++) {
  
showimg(200"light2.png"xy);
  
temp.color colorcycle(i);
  
changeimgcolors(200color[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"200200);
  
changeimgvis(2004);
  
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";
    
50;
    
50;
    new 
GuiShowImgCtrl("Color_Table") {
      
0;
      
width height 90;
      
image "tig-colortab.png";
    }
    new 
GuiShowImgCtrl("Color_Cursor") {
      
0;
      
image "tig-colorcursor.png";
    }
  }
}

function 
onTimeout() {
  if (
leftmousebuttonglobal) {
    if (
mousescreenx in |Color_Window1.6Color_Window1.Color_Window1.width 5| &&
      
mousescreeny in |Color_Window1.24Color_Window1.Color_Window1.height 5|) {
      
this.mx Color_Table.globaltolocalcoord({mousescreenxmousescreeny});
      
Color_Cursor.this.mx[0] - 6;
      
Color_Cursor.this.mx[1] - 6;
      
temp.color colorcycle(this.mx[0]);
      
changeimgcolors(200color[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.0temp.255temp.++) {
  
showimg(200"light2.png"xy);
  
temp.color colorcycle(i);
  
changeimgcolors(200temp.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.0temp.115temp.++) {
  
showpoly(300 i, {p[0] + ip[1], p[0] + ip[1] + 100});
  
changeimgvis(300 i4);
  
temp.color ColorCycle(i);
  
changeimgcolors(300 icolor[0], color[1], color[2], 1);


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

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



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.0.99;
  
this.sat 0;
  
this.mx = {150};
  
temp.= {screenwidth 2screenheight 2};

  
showimg(200"light4.png"200200);
  
changeimgvis(2004);
  
temp.color colorcycle(this.mx[0]);
  
changeimgcolors(200color[0] - color[0] / this.satcolor[1] - color[1] / this.satcolor[2] - color[2] / this.satthis.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";
    
50;
    
50;

    new 
GuiShowImgCtrl("Color_Table") {
      
0;
      
width height 90;
      
image "tig-colortab.png";
    }
    new 
GuiShowImgCtrl("Color_Cursor") {
      
0;
      
image "tig-colorcursor.png";
    }
    new 
GuiSliderCtrl("Color_Slider1") {
      
profile GuiBlueSliderProfile;
      
height 20;
      
range "0,80";
      
ticks 80;
      
value 80;
      
width 77;
      
7;
      
107;
    }
    new 
GuiTextCtrl("Color_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Saturation:";
      
width 52;
      
7;
      
90;
    }
    new 
GuiTextCtrl("Color_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Luminosity:";
      
width 60;
      
10;
      
120;
    }
    new 
GuiSliderCtrl("Color_Slider2") {
      
profile GuiBlueSliderProfile;
      
height 20;
      
range "0,99";
      
ticks 99;
      
value 99;
      
width 77;
      
7;
      
141;
    }
  }
}

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

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

function 
onTimeout() {
  if (
leftmousebuttonglobal) {
    if (
mousescreenx in |Color_Window1.6Color_Window1.Color_Table.width 7| &&
      
mousescreeny in |Color_Window1.24Color_Window1.115|) {
      
this.mx Color_Table.globaltolocalcoord({mousescreenxmousescreeny});
      
Color_Cursor.this.mx[0] - 6;
      
Color_Cursor.this.mx[1] - 6;
      
temp.color colorcycle(this.mx[0]);
      
changeimgcolors(200color[0] - color[0] / this.satcolor[1] - color[1] / this.satcolor[2] - color[2] / this.satthis.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.100;
  
temp.max((sin(max(80) / 12)), 0.01);
  
temp.max((sin(max(10) / 22)), 0.01);
  
temp.max((sin(max(260) / 21)), 0.01);
  return {
rgb};



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 04:50 PM.

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