PDA

View Full Version : HSL tutorial



Lorax
03-08-2007, 06:35 PM
Hi I'm Lorax, as any of you with more scripting knowledge knows, I'm a big fan of HSL (Hue, saturation, luminance).. I use it mainly for finding middle of objects as to use HSL is a great way for finding objects..
I have been asked to make this tutorial several times, and I know I'm not good at writing tutorials, but I will try anyway..

Introduction to HSL:
HSL is a way of defining colours. Just like RGB, Hex and the colours you use in SCAR (Color32)..
In RGB every colour has a Red value, a Green value and a Blue value.. And with a mix of those 3 values you can create any colour.. as some of you know RGB values range from 0-225..

HSL<>RGB:
RGB uses Integer values (jf. 0-225), but HSL uses floating points and ranges from (0.0-100.0)
When you set Red to 255, Green to 0 and Blue to 0 in RGB you will get the colour 0..
In HSL, it's the variable Hue which determines what colour you are having..

Examples using a color converter:
R 255, G 0, B 0 --> H 0.0, S 50.0, L 100.0
R 0, G 255, B 0 --> H 33.33, S 50.0, L100.0

What colour lies where is rather irelevant, but I can tell you that HSL is made like a circle and therefor Hue 100.0 and 0.0 is allmost the same color..

So Hue is the colour, what are the remaining two variables then?
Let's start of by talking about Luminance..
Luminance is (what the word suggests) lightness of the color..
If you set the Luminance to 100.0 you would get white and if you set it to 0.0 you would get black.. all Luminance values in between is simply a color with a lightness grade between black and white..

Saturation?
Saturation is what I prefer to call as "Grayness".. it simply shows how gray our color is..
if you set Saturation to 0.0 you would get the color gray no matter the Hue parameter.. if you set Saturation to 100.0 you would get a clean color, like 255, 0, 0..

So great, now I know what HSL is that's fine - but what do I use it for?
Don't make such stupid questions :)
I can tell you that Luminance can be used for detecting lines, because when there is a line you will see a radical change in Luminance..
All in all, HSL gives us some very neat variables to work on, and try to use a Color picker (with HSL) and run over for example a rock..
That's how I knew how I would make my findMiddle (of rock) procedure in my newest powerminer.. --> when a rock ends there's a radical change in Saturation..

Simply go ahead and explore HSL.. it's a fun tool..

And some fun, code :)




function SLFindMiddleOfTree(var ax, ay: Integer; tColor: Integer): Boolean;
var
Count, x1, y1, x2, y2, bCount, aCount: Integer;
arLuminance: array[0..1] of Extended;
Hue, Saturation: Extended;
begin
if(ax < 10)then
ax := 10;
if(ay < 10)then
ay := 10;
if(FindColorSpiralTolerance(ax, ay, tColor, ax - 10, ay - 10, ax + 10, ay + 10, 5))and
(LoggedIn)then
begin
for bCount := 0 to 3 do
begin
ColorToHSL(GetColor(ax, ay), Hue, Saturation, arLuminance[1]);
Count := 0;
if(bCount = 2)then
ax := (x2 + x1) div 2;
repeat
arLuminance[0] := arLuminance[1];
case bCount of
0: ColorToHSL(GetColor(ax - Count, ay), Hue, Saturation, arLuminance[1]);
1: ColorToHSL(GetColor(ax + Count, ay), Hue, Saturation, arLuminance[1]);
2: ColorToHSL(GetColor(ax, ay - Count), Hue, Saturation, arLuminance[1]);
3: ColorToHSL(GetColor(ax, ay + Count), Hue, Saturation, arLuminance[1]);
end;

if(Hue > 14)and(Hue < 34)then
begin
if(arLuminance[0] < arLuminance[1] - 1.5)or
(arLuminance[0] > arLuminance[1] + 1.5)then
aCount := 0
else
aCount := aCount + 1;
end else
aCount := aCount + 1;

if(aCount = 3)then
begin
case bCount of
0: x1 := ax - Count + 3;
1: x2 := ax + Count - 3;
2: y1 := ay - Count + 3;
3: y2 := ay + Count - 3;
end;
end;
Count := Count + 1;
until(Count = 60)or(aCount = 3);
if(Count = 60)then
begin
case bCount of
0: x1 := ax - Count;
1: x2 := ax + Count;
2: y1 := ay - Count;
3: y2 := ay + Count;
end;
end;
end;

ay := (y2 + y1) div 2;
if((x2 - x1) * (y2 - y1) >= MinWCount * MinHCount)then
Result := True;
end;
end;




This is what I use in our wood cutter for finding the middle of a tree, it's simple but works great..
Now go ahead and make your own object finders using HSL..
I myself have allready made (A tree middle finder, a rock middle finder, a fishing spot middle finder)..

Smartzkid
03-08-2007, 07:26 PM
Wow, this seems really intriguing...

Nice tut, I'll have to read it more thoroughly when I get home

Secet
03-08-2007, 10:05 PM
This seems really advanced stuff, but can I ask you one question.. Why do you want to find middle of tree or rock?

pwnaz0r
03-08-2007, 10:26 PM
Thank god :D gj bro

Lorax
03-08-2007, 11:01 PM
This seems really advanced stuff, but can I ask you one question.. Why do you want to find middle of tree or rock?
Well it's posted under Tutorials for the Advanced ;)
Try reading through my power miner or my wood cutter..

Cheesehunk
03-08-2007, 11:25 PM
Very awesome! I honestly didn't know most of this stuff, great tutorial. :) I hadn't seen many of your scripts until recently, but I have to say, you are one of my favourite scripters now.

Boreas
03-08-2007, 11:33 PM
Good news Lorax, Freddy said he will put HSL (and RGB) bruteforcers into a future version of Divi, so we can autocolor with a minH, maxH, minS.... !:D

Lorax
03-09-2007, 11:48 AM
Thanks Cheesehunk,
well that's great news - it will problemly make scripting easier ;)
I don't use HSL for minimap though..
Places where I used HSL:
1: Tutorial Island Runner, for detecting the progress bar (it's transparent) - Hue
2: My karamja power fisher for finding middle of fish spots (Luminance)
3: SL PSWW - finding middle of tree (Luminance)
4: Power Miner - finding middle of rock (Saturation)..

Perhaps I should make a chicken killer that uses HSL ;)
That would indeed be fun

SonOfSheep
03-10-2007, 08:38 PM
Thanks Cheesehunk,
well that's great news - it will problemly make scripting easier ;)
I don't use HSL for minimap though..
Places where I used HSL:
1: Tutorial Island Runner, for detecting the progress bar (it's transparent) - Hue
2: My karamja power fisher for finding middle of fish spots (Luminance)
3: SL PSWW - finding middle of tree (Luminance)
4: Power Miner - finding middle of rock (Saturation)..

Perhaps I should make a chicken killer that uses HSL ;)
That would indeed be fun

What on earth would you need to find the middle of a chicken for? Or is there some sort of secret chicken finding magical hue! Lol this is just what i needed for my oak annihilator, it is working so much better than i thought it could! I plugged this in and it worked magic. One question though, can i use this in my script? I don't feel like making my own procedure and if i did it would work the same, probably just different variable names. (i'm not sure what yours does, but if i made one it would keep going up and down until it saw a big change, then find the midpoint. Next it would go left and right until it finds a big change and then find the midpoint. Then it would place the midpoints into the x y values.)

Wizzup?
03-10-2007, 09:11 PM
Glad to see you created The Tutorial. ;)

Lorax
03-10-2007, 11:23 PM
SonOfSheep yes that's excatly what my procedure does aswell.. What you descriped, except it goes up and down afterwards aswell..
The chicken middle finder was more of a joke..
Hehe, Wizzup - thanks.. I wish I were more understandable though..
But english isn't my first language ;)

SonOfSheep
03-10-2007, 11:53 PM
SonOfSheep yes that's excatly what my procedure does aswell.. What you descriped, except it goes up and down afterwards aswell..
The chicken middle finder was more of a joke..
Hehe, Wizzup - thanks.. I wish I were more understandable though..
But english isn't my first language ;)

Your english is much better than some people who speak only english. Example:


hi im new i need a script please help me i cant get any ones to work please i need money sometimes im broke because i have 1gp but my main got banned he was level 145 pls helpz i need super autokiller has to solve random events all time and all i have to do is press go i dont know how to work scripts kthxbai oh oh oh and you can send me an email at imanewbz@hawtmail.com!




but yah this is great. You should release more advanced colorfinding tutorials.

IEatJ00erBaybees
03-11-2007, 12:31 AM
A little too advanced for me, but I thought I'd point this out


1-225

That was what you said the RGB values can be. It's actually 0-255, just thought I'd let you know that. Might have just been a typo.

Lorax
03-11-2007, 09:59 AM
Thanks @ SonOfSheep - and concerning releasing more color finding tutorials:
I was asked to make this, and I don't believe that there is any more efficient way of finding objects than using this..
I haven't however tried CMYK.. It has four variables (Cyan, Magenta, Yellow(?), K?) I'm not that much into CMYK, but well I think any color definition is better than Color32 except with speeds..

Color32 is the fastest way of defining colors and can be more than 100x faster than any other way of defining colors.. However HSL is more efficient when it comes to identifying objects..

edit: I'm not that much into RGB, I wasn't 100% sure, but I'll go fix it..

Avaphi
03-11-2007, 11:25 AM
Thanks for re-interesting me in HSL !!! I haven't touched it since computer graphics class. I am definetly going to read up on it then maybe make a tutorial to rival yours :)

Boreas
03-11-2007, 03:25 PM
Bramble and I have taken samples of colors of different things on the minimap, which in SCAR color format, are millions apart. But when converted to HSL and RGB, they were very close. For some things RGB was closer, and some HSL was closer, however HSL was closer more of the time. This fits in with jagex generating colors from picking random H, S, and L from ranges. So I doubt CMYK will be closer, but you could try it.

Ruroken
03-13-2007, 03:20 PM
THANK YOU!

i have been waiting for this :)

Nice tut.

Killerdou
03-13-2007, 04:11 PM
this give me an idea... what about we use hsl to scan the minimap, creating a certain shape(diffrence in hsl, dunno which one should be used for this) which could be compared to the entire worldmap, to know where we are:) that would make cheating so much easier... but we shouldnt do it.... its like ... cheating:P

Avaphi
03-13-2007, 04:57 PM
I will look into it Ili8......

Killerdou
03-13-2007, 06:41 PM
and maybe to make to area smaller have it look for symbols road/water colors, i just finished making an autocolor for fallador buildings, could be used aswell... lets hope it'll work

Lorax
03-13-2007, 07:50 PM
That minimap --> worldmap is allmost impossible and I don't think that it will ever be made.. that xscar was the closest.. but I'm afraid that the solution of hacking the client isn't preferable..

Killerdou
03-13-2007, 08:40 PM
im pretty sure its possible, could you help me with changing a picture of the minimap so that most colors are gone, but you can still distinct water road grass etc...? i think that would be the key to finding your position...

Boreas
03-13-2007, 11:23 PM
Drop dots, player dots, npc dots, and red doors would be your best bet, but it would still be so hard its not worth it.

Lorax
03-15-2007, 12:16 PM
Mutant Squirlle(sp?) once made some kind of Dungeon walker, you could perhaps get inspired from him?
I weren't that interested and didn't get that much into what it actually did..
I'm sure he'll give it to you..

Avaphi
03-15-2007, 07:04 PM
That minimap --> worldmap is allmost impossible and I don't think that it will ever be made.. that XSCAR was the closest.. but I'm afraid that the solution of hacking the client isn't preferable..

Nowadays though the use of BCEL its passively editing the client, so there is no detectability except for 1) Poor BCEL Hacks 2) Trying to play with an un-updated BCEL Hack.

Jason2gs
06-08-2007, 09:13 PM
Nice, thanks for this :)

R0b0t1
06-13-2007, 02:17 AM
For anyone who wanted to know - Scalable Vector Graphics CMYK (Cyan-Magenta-Yellow-blacK)

And are used as such - cmyk(0%, 100%, 100%, 0%) (RED). (I think HSL/RGB is better).


I think HSL could be a good step forward in walking/something.

da_professa
06-18-2007, 11:06 PM
I got this tutorial up until the hsl and everything, but I don't understand how u used it to get middle of tree.. Is it possible for you to explain it a bit more cuz I am very very interested..

the scar noob
09-23-2007, 03:33 PM
I get it until I saw your example :p
Are you telling that the hue has got a maximum value of 100?
cause that would be wrong, since (240°, 0.5, 0.25) would give you a dark-blue color.

Thanks for sharing your k nowledge with us, we all can learn from it ;)

-tsn.

King of Knives
09-23-2007, 04:36 PM
I understood the part about Hue, Saturation and Luminance, but you lost me in that Get-Middle-Of-Tree-Script.

I tried to read it through and all, but I didn't understand it.
Instead, my head exploded, so now my roof is covered with sticky brain

-Knives