Sign in to follow this  
Followers 0
ludocus

making a 0xFFFFFF color darker or lighter? [solved]

9 posts in this topic

#1 ·  Posted (edited)

I want to convert a 0xFFFFFF color into some number wich I can make higher or lower and then convert back and then let the color be lighter or darker

is there a way to do this??

Please help, thnx in advance

Edited by ludocus

Share this post


Link to post
Share on other sites



I want to convert a 0xFFFFFF color into some number wich I can make higher or lower and then convert back and then let the color be lighter or darker

is there a way to do this??

Please help, thnx in advance

Convert it to RGB and work that way? There are examples around the forum.

Share this post


Link to post
Share on other sites

I searched the forum but what keyword do I search??

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I want to convert a 0xFFFFFF color into some number wich I can make higher or lower and then convert back and then let the color be lighter or darker

is there a way to do this??

Please help, thnx in advance

Split the colour into rde, green and blue components, reduce oir increase the value of each with a limit of 0 min, 255 max, then add them back together again. There are posts around I think about this, but it would be something like

ALterBrightness($colour,$amount)
 
 Func AlterBrightness($c,$a)
 
 local $red = BitAnd($c,0xff0000)/0x10000
 Local $grn = BitANd($c,0x00ff00)/0x100
 Local $blu = BitAnd($c,0x0000FF)
 
 $red = $red + $a
 if $red > 255 Then $red = 255
 if $red < 0 Then $red = 0
;same for others
 
  return $red * 0x10000 + $grn * 0x100 + $blu
 
 EndFunc

But not tested - it's just to show the idea.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

thnx thnx thnx!!

that helps alot..:)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

but....

it doesn't work for me :)

Edited by ludocus

Share this post


Link to post
Share on other sites

but....

it doesn't work for me :)

Well in that case I actually try using it myself and then I'll get back.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well in that case I actually try using it myself and then I'll get back.

I tried it and it works ok. Try this

GUICreate("Brightness change")
GUISetBkColor(0x345678)

GUISetState()

For $n = 0 To 100
    Sleep(20)

    $new = _ALterBrightness(0x345678, -$n)
    GUISetBkColor($new)

Next

For $n = -100 To 200
    Sleep(20)

    $new = _ALterBrightness(0x345678, $n)
    GUISetBkColor($new)

Next

While GUIGetMsg() <> -3

WEnd

;======AlterBrightness==================
;Returns the colour made by changing the brightness of $c
;according to the value of $adjust which is the amount to adjust the red green and blue components,
;and the value of $group.
;If $group = 7 (default) adjust red, green and blue by $adjust.
;         = 1 red only
;         = 2 green only
;         = 4 blue only
Func _AlterBrightness($StartCol, $adjust, $Select=7)

    Local $red = $adjust*(BitAnd(1,$Select) <> 0) + BitAND($StartCol, 0xff0000) / 0x10000
    Local $grn = $adjust*(BitAnd(2,$Select) <> 0) + BitAND($StartCol, 0x00ff00) / 0x100
    Local $blu = $adjust*(BitAnd(4,$Select) <> 0) + BitAND($StartCol, 0x0000FF)

    Return LimitCol($red) * 0x10000 + LimitCol($grn) * 0x100 + LimitCol($blu)

EndFunc  ;==>AlterBrightness

: _LimitCol
;returns the value of $cc limited to a value from 0 to 255
Func limitCol($cc)
    If $cc > 255 Then Return 255
    If $cc < 0 Then Return 0
    Return $cc
EndFunc  ;==>limitCol

Edit:improved it to allow indivual colour components to be adjusted

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

wow man, thnx alot :)

Edited by ludocus

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0