Jump to content

I can not crack it .. somehow I still get too much similar colors


Guest
 Share

Recommended Posts

Screenshot_1.png

 

Help me. This is what I coded:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ColorConstants.au3>


#include <Array.au3>

Global $_IntColor_aColors[0]
Global Const $_C_IntColor_iMaxColor = 16777215


Example()

Func Example()
    Local $idListview

    $hGUI = GUICreate("ListView Get Item Focused", 400, 300)
;~     $idListview = _GUICtrlListView_Create($hGUI,'',2, 2, 394, 268)
    $idListview = GUICtrlCreateListView ("", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))





    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Column 1", 100)
    _GUICtrlListView_AddColumn($idListview, "Column 2", 100)
    _GUICtrlListView_AddColumn($idListview, "Column 3", 100)
    _GUICtrlListView_AddColumn($idListview, "Column 4", 50)

    ; Add items
    $it0 = GUICtrlCreateListViewItem('adwawd A',$idListview)
        _GUICtrlListView_AddSubItem($idListview, 0, "A.1", 1)
        _GUICtrlListView_AddSubItem($idListview, 0, "A.2", 2)
    $it1 = GUICtrlCreateListViewItem('Bgsefgsf ',$idListview)
        _GUICtrlListView_AddSubItem($idListview, 1, "B.1", 1)

    $it2 = GUICtrlCreateListViewItem('Cfe adwawd ',$idListview)
        _GUICtrlListView_AddSubItem($idListview, 2, "C.2", 2)

    $it3 = GUICtrlCreateListViewItem('dadwadw ad',$idListview)
        _GUICtrlListView_AddSubItem($idListview, 3, "D.0", 0)


    $it4 = GUICtrlCreateListViewItem('',$idListview)
        _GUICtrlListView_AddSubItem($idListview, 4, "E - Some text!!! dawdad", 0)
        _GUICtrlListView_AddSubItem($idListview, 4, "E some text 2 !!!", 1)
        _GUICtrlListView_AddSubItem($idListview, 4, "E some text 3 adwadwawd", 2)

    $it5 = GUICtrlCreateListViewItem('',$idListview)
        _GUICtrlListView_AddSubItem($idListview, 5, "F - Some text!!! dawdad", 0)
        _GUICtrlListView_AddSubItem($idListview, 5, "F some text 2 !!!", 1)
        _GUICtrlListView_AddSubItem($idListview, 5, "F some text 3 adwadwawd", 2)


    GUICtrlSetBkColor($it0, 0xCCFFCC)
    GUICtrlSetBkColor($it1, 0xffbb47)


;~  ConsoleWrite(Random(0,16777215,1) &' (L: '&@ScriptLineNumber&')'&@CRLF)

;~  Sleep(1000)
    GUICtrlSetBkColor($it1, $COLOR_WHITE)
    GUICtrlSetBkColor($it0,$COLOR_RED)

    GUICtrlSetColor($it2,$COLOR_RED)



    $aRandomColors = IntColor_Get2InvertedColors()
    GUICtrlSetBkColor($it0,$aRandomColors[0])
    GUICtrlSetColor($it0,$aRandomColors[1])


    $aRandomColors = IntColor_Get2InvertedColors()
    GUICtrlSetBkColor($it1,$aRandomColors[0])
    GUICtrlSetColor($it1,$aRandomColors[1])



    $aRandomColors = IntColor_Get2InvertedColors()
    GUICtrlSetBkColor($it2,$aRandomColors[0])
    GUICtrlSetColor($it2,$aRandomColors[1])

;~  Exit

    $aRandomColors = IntColor_Get2InvertedColors()
    GUICtrlSetBkColor($it3,$aRandomColors[0])
    GUICtrlSetColor($it3,$aRandomColors[1])

    $aRandomColors = IntColor_Get2InvertedColors()
    GUICtrlSetBkColor($it4,$aRandomColors[0])
    GUICtrlSetColor($it4,$aRandomColors[1])

    $istart = 6
    For $a = 1 To 1000
        $tmp = GUICtrlCreateListViewItem(Random(1000,10000,1),$idListview)
        $aRandomColors = IntColor_Get2InvertedColors()
        GUICtrlSetBkColor($tmp,$aRandomColors[0])
        GUICtrlSetColor($tmp,$aRandomColors[1])
    Next

    _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE_USEHEADER)
    _GUICtrlListView_SetColumnWidth($idListview, 1, $LVSCW_AUTOSIZE_USEHEADER)
    _GUICtrlListView_SetColumnWidth($idListview, 2, $LVSCW_AUTOSIZE_USEHEADER)
;~  _GUICtrlListView_SetColumnWidth($idListview, 3, $LVSCW_AUTOSIZE_USEHEADER)







GUISetState(@SW_SHOW)


    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example











Func IntColor_Get2InvertedColors()
    Local $aColor[2], $iTmpSimilarity
    Local Const $C_iMaxSimilarity = 0.002 , $C_iMaxSimilarity2PrevColors = 0.001
    Do
        $aColor[0] = IntColor_GetRandom()
        For $a = 0 To UBound($_IntColor_aColors)-1
            If IntColor_GetSimilarityLevel($aColor[0],$_IntColor_aColors[$a]) >= _
            $C_iMaxSimilarity2PrevColors Then ContinueLoop 2
        Next
        $aColor[1] = IntColor_Invert($aColor[0])
    Until IntColor_GetSimilarityLevel($aColor[0],$aColor[1]) <= $C_iMaxSimilarity
    _ArrayAdd($_IntColor_aColors,$aColor[0])
    Return $aColor
EndFunc

Func IntColor_CleanPreviousColors()
    ReDim $_IntColor_aColors[0]
EndFunc

Func IntColor_GetSimilarityLevel($iColor1,$iColor2)
    If $iColor1 < $iColor2 Then
        Return $iColor1/$iColor2
    Else
        Return $iColor2/$iColor1
    EndIf
EndFunc


Func IntColor_GetRandom()
    Return Random(0,$_C_IntColor_iMaxColor,1)
EndFunc

Func IntColor_Invert($iColor)
    Local $iAncer = $_C_IntColor_iMaxColor-$iColor


    Return $iAncer
EndFunc

 

The result in the image is the best I got so far. but still far from good.
the colors should be similar but not too much

Thanks!

Edited by Guest
Link to comment
Share on other sites

I don't have to time to write out the example but these functions will help you achieve what you want

Func _ColorAdjustRed($iColor, $iAmount, Const $_iCurrentExtended = @extended)
    If (Not BitAND($iColor, 0xFF0000) And $iAmount < 0) Then Return SetError(1, 0, $iColor)
    Local $iR = BitAND(BitShift($iColor, 16), 0xFF)
    If ($iAmount < 0 And $iR + $iAmount < 0) Then $iAmount = -$iR
    If ($iAmount > 0 And $iR = 255) Then Return $iColor
    If ($iAmount > 0 And $iR + $iAmount > 255) Then $iAmount = Abs($iR - $iAmount)
    Return SetExtended($_iCurrentExtended, $iColor + BitShift($iAmount, -16))
EndFunc   ;==>_ColorAdjustRed

Func _ColorAdjustGreen($iColor, $iAmount, Const $_iCurrentExtended = @extended)
    If (Not BitAND($iColor, 0xFF00) And $iAmount < 0) Then Return SetError(1, 0, $iColor)
    Local $iG = BitAND(BitShift($iColor, 8), 0xFF)
    If ($iAmount < 0 And $iG + $iAmount < 0) Then $iAmount = -$iG
    If ($iAmount > 0 And $iG = 255) Then Return $iColor
    If ($iAmount > 0 And $iG + $iAmount > 255) Then $iAmount = Abs($iG - $iAmount)
    Return SetExtended($_iCurrentExtended, $iColor + BitShift($iAmount, -8))
EndFunc   ;==>_ColorAdjustGreen

Func _ColorAdjustBlue($iColor, $iAmount, Const $_iCurrentExtended = @extended)
    If (Not BitAND($iColor, 0xFF) And $iAmount < 0) Then Return SetError(1, 0, $iColor)
    Local $iB = BitAND($iColor, 0xFF)
    If ($iAmount < 0 And $iB + $iAmount < 0) Then $iAmount = -$iB
    If ($iAmount > 0 And $iB = 255) Then Return $iColor
    If ($iAmount > 0 And $iB + $iAmount > 255) Then $iAmount = Abs($iB - $iAmount)
    Return SetExtended($_iCurrentExtended, $iColor + $iAmount)
EndFunc   ;==>_ColorAdjustBlue

This way you can adjust one of the color components of your starting color value until that value reaches the max, or 0, then move onto the next color component. Looping through the R G and B on each of your items.

Link to comment
Share on other sites

Thanks. I'm not familiar with calculate colors in this way.. I will check it. I'd appreciate it if you give an example of how to use these functions. Do not go too far .. something simple might be enough

Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <Array.au3>
#include <Color.au3>

HotKeySet("{Enter}", NextColor)

Global $hMain = GUICreate("Example", 200, 540)
Global $aLabels[27]
Global $sCurrent = "Blue"

For $i = 0 to UBound($aLabels) - 1
    $aLabels[$i] = GUICtrlCreateLabel("", 0, $i * 20, 200, 20)
Next

NextColor()

GUISetState(@SW_SHOW, $hMain)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            Exit 0
    EndSwitch
WEnd

Func NextColor()
    ; Variable to hold the color we're using
    Local $iColorStart = 0
    ; Variable to hold the function that will be used to adjust the proper color
    Local $sFunctionToAdjust = ""
    ; Variable to hold the function that will be used to check and make sure the color is > 0 and < 255
    Local $sFunctionToCheck = ""
    ; Variable used to adjust the color, increase the color value or decrease the color value
    Local $iOffset = -20
    
    ; Check and see what color we need to switch to next
    Switch ($sCurrent)
        ; Current color is red, move to green
        Case "Red"
            $sCurrent = "Green"
            $iColorStart = 0x00FF00
            $sFunctionToAdjust = _ColorAdjustGreen
            $sFunctionToCheck = _ColorGetGreen
        ; Current color is green, move to blue
        Case "Green"
            $sCurrent = "Blue"
            $iColorStart = 0x0000FF
            $sFunctionToAdjust = _ColorAdjustBlue
            $sFunctionToCheck = _ColorGetBlue
        ; Current color is blue, move to red
        Case "Blue"
            $sCurrent = "Red"
            $iColorStart = 0xFF0000
            $sFunctionToAdjust = _ColorAdjustRed
            $sFunctionToCheck = _ColorGetRed
    EndSwitch

    For $i = 0 to UBound($aLabels) - 1
        ; Get the current color value
        Local $iCurrentColor = $sFunctionToCheck($iColorStart)
        ; If it's <= 0 (black) start increasing the color value
        If ($iCurrentColor <= 0) Then
            $iOffset = 20
        ; It's >= 255, start decreasing the color value
        ElseIf ($iCurrentColor >= 255) Then
            $iOffset = -20
        EndIf
        
        ; Set the color
        GUICtrlSetBkColor($aLabels[$i], $iColorStart)
        
        ; Adjust the color
        $iColorStart = $sFunctionToAdjust($iColorStart, $iOffset)
    Next
EndFunc

Func _ColorAdjustRed($iColor, $iAmount, Const $_iCurrentExtended = @extended)
    If (Not BitAND($iColor, 0xFF0000) And $iAmount < 0) Then Return SetError(1, 0, $iColor)
    Local $iR = BitAND(BitShift($iColor, 16), 0xFF)
    If ($iAmount < 0 And $iR + $iAmount < 0) Then $iAmount = -$iR
    If ($iAmount > 0 And $iR = 255) Then Return $iColor
    If ($iAmount > 0 And $iR + $iAmount > 255) Then $iAmount = Abs($iR - $iAmount)
    Return SetExtended($_iCurrentExtended, $iColor + BitShift($iAmount, -16))
EndFunc   ;==>_ColorAdjustRed

Func _ColorAdjustGreen($iColor, $iAmount, Const $_iCurrentExtended = @extended)
    If (Not BitAND($iColor, 0xFF00) And $iAmount < 0) Then Return SetError(1, 0, $iColor)
    Local $iG = BitAND(BitShift($iColor, 8), 0xFF)
    If ($iAmount < 0 And $iG + $iAmount < 0) Then $iAmount = -$iG
    If ($iAmount > 0 And $iG = 255) Then Return $iColor
    If ($iAmount > 0 And $iG + $iAmount > 255) Then $iAmount = Abs($iG - $iAmount)
    Return SetExtended($_iCurrentExtended, $iColor + BitShift($iAmount, -8))
EndFunc   ;==>_ColorAdjustGreen

Func _ColorAdjustBlue($iColor, $iAmount, Const $_iCurrentExtended = @extended)
    If (Not BitAND($iColor, 0xFF) And $iAmount < 0) Then Return SetError(1, 0, $iColor)
    Local $iB = BitAND($iColor, 0xFF)
    If ($iAmount < 0 And $iB + $iAmount < 0) Then $iAmount = -$iB
    If ($iAmount > 0 And $iB = 255) Then Return $iColor
    If ($iAmount > 0 And $iB + $iAmount > 255) Then $iAmount = Abs($iB - $iAmount)
    Return SetExtended($_iCurrentExtended, $iColor + $iAmount)
EndFunc   ;==>_ColorAdjustBlue

This examply only uses R, G, and B for the color values, if you wanted to do some mixed colors you'll have to figure out the math yourself. But the adjust color functions will help

Here's my original post where I put these functions, in case you wanted to see a hex value demonstration

Link to comment
Share on other sites

Thanks,

First time I see this from  syntax .

I Understand that this

$var = Test

$var() 

Func Test()
    ConsoleWrite(111 &' (L: '&@ScriptLineNumber&')'&@CRLF)
EndFunc

Completely replaces the use of the Call(*) function in my use-case.

It's really great! I did some dirty things with the Call(*) function. this new approach is highly wolcome :)
Thank you also for teaching me this!

Edited by Guest
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...