Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #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.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.
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
  #2  
Old 05-14-2008, 08:29 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
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
__________________

Reply With Quote
  #3  
Old 05-14-2008, 08:47 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
Quote:
Originally Posted by Robin View Post
So it's not calling your function 765 times :P
Meant to change that before I released it, thanks .
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #4  
Old 05-14-2008, 10:55 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Seems to only support hue? What about saturation and luminosity?
__________________
Do it with a DON!
Reply With Quote
  #5  
Old 05-14-2008, 05:40 PM
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
Quote:
Originally Posted by zokemon View Post
Seems to only support hue? What about saturation and luminosity?
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 05-14-2008, 06:59 PM
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
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);
  }

__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #7  
Old 05-14-2008, 07:05 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #8  
Old 05-14-2008, 07:07 PM
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
Quote:
Originally Posted by DustyPorViva View Post
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."
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #9  
Old 05-14-2008, 07:44 PM
Galdor Galdor is offline
░▒▓██▓▒░
Galdor's Avatar
Join Date: Feb 2004
Posts: 2,434
Galdor has a reputation beyond reputeGaldor has a reputation beyond reputeGaldor has a reputation beyond reputeGaldor has a reputation beyond reputeGaldor has a reputation beyond reputeGaldor has a reputation beyond reputeGaldor has a reputation beyond reputeGaldor has a reputation beyond reputeGaldor has a reputation beyond repute
cool tig I like colors.
Reply With Quote
  #10  
Old 05-14-2008, 08:05 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
That's pretty awesome. I think I will find some use for this
Reply With Quote
  #11  
Old 05-14-2008, 08:22 PM
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
Quote:
Originally Posted by Galdor View Post
cool tig I like colors.
Me too!
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #12  
Old 05-15-2008, 01:35 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
Quote:
Originally Posted by zokemon View Post
Seems to only support hue? What about saturation and luminosity?
Added it in for you

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);

__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #13  
Old 05-15-2008, 01:56 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Nice addition, I will probably be using this!
__________________
Reply With Quote
  #14  
Old 05-15-2008, 12:26 PM
smirt362 smirt362 is offline
Tee Hee
smirt362's Avatar
Join Date: Feb 2005
Location: Texas
Posts: 2,101
smirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant futuresmirt362 has a brilliant future
Send a message via AIM to smirt362 Send a message via MSN to smirt362
I don't understand the script, but I'm understanding what it's for...very awesome!
__________________

Don Hertzfeldt <3
Reply With Quote
  #15  
Old 05-15-2008, 06:43 PM
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
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};

__________________


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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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