Been awhile since my last snippet... $bRGB is just a simple picwin tool. It works the same way as $rgb, it returns the rgb value of any 3 numbers.
Except there's one difference. In the traditional rgb identifier, the values restart at 256, meaning that the value 256 is processed as "1," and 257 is processed as "2." In my version, which would come in handy when blending colors, 256 is processed as "254," and 257 is processed as "253." Meaning, when you pass 255, instead of starting over at 0, the numbers decrease.
When it gets to 510 (0), it starts increasing again. So 511 is "1," and 512 is "2." Get it? I know, nothing much, and probably won't be of any use to any of you. Regardless, I'd personally still find it useful, and maybe there's some other PicWinners out there who could make some good use of this...
;BlueThen's $bRGB
;Made September 19, 2008.
;To install, paste this snippet in your remotes (Alt + R)
;Then, in your scripts, use $brgb(N,N,N) to get an rgb value.
;BlueThen.com
alias brgb {
var %brgb.r, %brgb.g, %brgb.b
if ($1 > 255) %brgb.r = $calc($iif(. isin $calc($int($calc($1 / 255))/2) ,255 -)($1 - (255 * $int($calc($1 / 255)))))
else %brgb.r = $1
if ($2 > 255) %brgb.g = $calc($iif(. isin $calc($int($calc($2 / 255))/2) ,255 -)($2 - (255 * $int($calc($2 / 255)))))
else %brgb.g = $2
if ($3 > 255) %brgb.b = $calc($iif(. isin $calc($int($calc($3 / 255))/2) ,255 -)($3 - (255 * $int($calc($3 / 255)))))
else %brgb.b = $3
return $rgb(%brgb.r,%brgb.g,%brgb.b)
}
Jonsey, as he tried to explain, you are right, the max is 255 but normally the $rgb will accept higher numbers only it does as follows, 256 is interpeted as 1, and 257 = 2, and so on, well the problem here is 255 is black and 1 is white so if u were increasing a variable to make a gradiant color change then going above 255 would mess it up because it would go straight from black to white with no blending of all the colors in between.
What this code does is makes it work back down to 1 from 255 as you increase the number past 255, so, instead of 256 being interpeted as 1 it gets interpeted as 254 so that 252 253 254 255 256 257 258 would actually be the same as doing 252 253 254 255 254 253 252 instead of 252 253 254 255 1 2 3.
Hope that made sense.
I gave a detailed explanation as possible in the description. When you use $rgb(256,256,256), it comes out as black, rather than white like $rgb(255,255,255). But when you use $brgb(256,256,256), it comes out as black, except with a tad lighter shade. That way, when making an animation, the colors will blend if you merely increase one of the values each frame.
You have a $2 in the $3 line.
My bad. Fixed.
I did thought about doing a while loop, but decided it was unnecessary, only because it's only repeated 3 times. :P
Yea just change unset %brgb.* to var %brgb.r,%brgb.g,%brgb.g
Or you could put the unset at the bottom instead.
I'd use unset at the bottom, but if you've ever made a custom identifier, the script halts after "return," and a timer would probably mess it up if the identifier is used again immediately after the first one.
Regardless, I'll change it to var anyways. Thanks for the tips.
Very cool snippet BlueThen. I definately see how this could be usefull but when I tested it I seemed to have problems. I went to shorten your code a little bit and my output was different than yours and I finally realized why. I thought I was messing mine up and infact I had discovered a mistake in yours. You have a $2 in the $3 line.
Heres my ideas to shorten it a little bit. I just used a while loop to make the 1 if line handle all three $'s. I also added a check for $3 to make sure that it exists and I didnt totally understand your calc's when I thought there was an error so I made a new one which seemed to test just fine and is shorter than the one you came up with.
alias brgb {
if ($3) {
var %brgb.r, %brgb.g, %brgb.b, %endnum $0
while (%endnum) {
var %dotletter $iif(%endnum == 3,b,$iif($v1 == 2,g,$iif($v1 == 1,r))), %dollarnum $ $+ %endnum
if ($(%dollarnum,2) > 255) %brgb. [ $+ [ %dotletter ] ] = $calc(255 - ($(%dollarnum,2) - (255 * $int($calc($(%dollarnum,2) / 255)))))
else %brgb. [ $+ [ %dotletter ] ] = $(%dollarnum,2)
dec %endnum
}
return $rgb(%brgb.r,%brgb.g,%brgb.b)
}
}
Anyhow, mine isn't a whole lot shorter but I think it is definately shorter and does show a bit of a different way of doing things for anyone looking.
I really do like the idea and like I said it does make sense and people should find it usefull.
Well done.