Jump to content
Sign in to follow this  
xan

Fun ordering

Recommended Posts

xan

Example Bubble sort

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global  $posw = 3
Global $memoria = "mem...",$fim = False, $i,$array[9] = [8,5,7,3,1,6,4,2]


#Region ### START Koda GUI section ### Form=d:\documents and settings\xan\meus documentos\bublesort.kxf
$Form1 = GUICreate("Autoit", 738, 450, 192, 224)
GUISetBkColor(0xD4D0C8)
$Label1 = GUICtrlCreateLabel("Bubble Sort", 212, 5, 598, 177)
GUICtrlSetFont(-1, 75, 400, 10, "MS Sans Serif")
$b1 = GUICtrlCreateButton($array[0], 16, 114, 78, 80)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, 0)
$b2 = GUICtrlCreateButton($array[1], 104, 114, 78, 80)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, 0)
$b3 = GUICtrlCreateButton($array[2], 192, 114, 78, 80)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, 0)
$b4 = GUICtrlCreateButton($array[3], 280, 114, 78, 80)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, 0)
$b5 = GUICtrlCreateButton($array[4], 368, 114, 78, 80)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, 0)
$b6 = GUICtrlCreateButton($array[5], 456, 114, 78, 80)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, 0)
$b7 = GUICtrlCreateButton($array[6], 552, 114, 78, 80)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, 0)
$b8 = GUICtrlCreateButton($array[7], 640, 114, 78, 80)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, 0)
$Button3 = GUICtrlCreateButton("", 0, 366, 737, 17,0)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DEFBUTTON )
$for = GUICtrlCreateButton("Ordenar", 16, 8, 200, 81, $WS_BORDER)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFF0000)
$Button4 = GUICtrlCreateButton("....", 0, 250, 737, 17,0)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, 0 )
$while = GUICtrlCreateButton("While 0", 3, 305, 193, 129)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFF0000)
GUICtrlSetState(-1, $GUI_DISABLE)
$mem = GUICtrlCreateButton("Memória", $posw + 12, 194, 161, 73, 0)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $For
            ExitLoop
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Display()
    GUICtrlSetData($for, "For Stop")
    GUICtrlSetBkColor($for, 0xFF0000);ver
    Sleep(1000)
    GUICtrlSetBkColor($for, 0x009900)
    Sleep(500)
    GUICtrlSetBkColor($for, 0xffff00)
    Sleep(500)
    GUICtrlSetBkColor($for, 0x009900)
    Sleep(500)
    GUICtrlSetBkColor($for, 0xffff00)
    GUICtrlSetData($for, "For Start")
    Sleep(500)
    GUICtrlSetBkColor($for, 0x009900)
    Sleep(1000)

For $i = 1 To 8 Step 1
        GUICtrlSetData($for, "For  $i = "&$i)
        BotCollor()
    Sleep(400)
    While $array[$i] < $array[$i-1]
        GUICtrlDelete($while)
        $while = GUICtrlCreateButton("While 1", $posw, 290, 193, 129)
        GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
        GUICtrlSetBkColor(-1, 0x009900)
        GUICtrlSetState(-1, $GUI_DISABLE)
        $memoria    =  $array[$i]
        Display()
        $array[$i]  =  $array[$i-1]
        Display()
        $array[$i-1]   = $memoria
        Display()
        $fim         = False
    Sleep(700)
        GUICtrlDelete($while)
        $while = GUICtrlCreateButton("While 0", $posw, 290, 193, 129)
        GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
        GUICtrlSetBkColor($while, 0xFF0000)
        $memoria     = "mem..."
        Display()
    WEnd

    if $i >= 7 and $fim  Then
        GUICtrlSetData($mem, "  OK !!! ")
        GUICtrlSetData($for, "Ordenado !!!")
        Sleep(300)
        GUICtrlSetBkColor($for, 0xffffff)
        Sleep(300)
        GUICtrlSetBkColor($for, 0xffff00)
        Sleep(300)
        GUICtrlSetBkColor($for, 0xffffff)
        Sleep(300)
        GUICtrlSetBkColor($for, 0xffff00)
        Sleep(300)
        GUICtrlSetBkColor($for, 0xffffff)
        Sleep(300)
        GUICtrlSetBkColor($for, 0xffff00)
        Sleep(300)
        GUICtrlSetBkColor($for, 0xffffff)
        Sleep(300)
        GUICtrlSetBkColor($for, 0xffff00)
        Sleep(9000)
        Exit
    EndIf

    If  $i  >= 7 Then
        $i   = 0
        $fim = True
    EndIf
    Movewhile()
next

Func BotCollor()
    Switch $i
        Case 1
            GUICtrlSetBkColor($B1, 0x666666)
            GUICtrlSetBkColor($B2, 0x9900cc)
        Case 2
            GUICtrlSetBkColor($B2, 0x666666)
            GUICtrlSetBkColor($B3, 0x9900cc)
        Case 3
            GUICtrlSetBkColor($B3, 0x666666)
            GUICtrlSetBkColor($B4, 0x9900cc)
        Case 4
            GUICtrlSetBkColor($B4, 0x666666)
            GUICtrlSetBkColor($B5, 0x9900cc)
        Case 5
            GUICtrlSetBkColor($B5, 0x666666)
            GUICtrlSetBkColor($B6, 0x9900cc)
        Case 6
            GUICtrlSetBkColor($B6, 0x666666)
            GUICtrlSetBkColor($B7, 0x9900cc)
        Case 7
            GUICtrlSetBkColor($B7, 0x666666)
            GUICtrlSetBkColor($B8, 0x9900cc)
    EndSwitch
        Sleep(300)
EndFunc

Func Movewhile()
If $i >= 1 Then
    $posw += 90
    GUICtrlSetData($mem, $memoria)
    GUICtrlSetBkColor($mem, 0xA6CAF0)
    GUICtrlSetState($mem, $GUI_DEFBUTTON )
    GUICtrlSetPos($mem, $posw + 12)
    GUICtrlSetData($while, "While 0")
    GUICtrlSetPos($while, $posw)
    GUICtrlSetBkColor($while, 0xFF0000)
    GUICtrlSetBkColor($B1, 0xf5f5f5)
    GUICtrlSetBkColor($B2, 0xf5f5f5)
    GUICtrlSetBkColor($B3, 0xf5f5f5)
    GUICtrlSetBkColor($B4, 0xf5f5f5)
    GUICtrlSetBkColor($B5, 0xf5f5f5)
    GUICtrlSetBkColor($B6, 0xf5f5f5)
    GUICtrlSetBkColor($mem, 0xA6CAF0)
Else
        GUICtrlSetBkColor($B7, 0xf5f5f5)
        GUICtrlSetBkColor($B8, 0xf5f5f5)
        GUICtrlSetBkColor($mem, 0xA6CAF0)
    While $posw  > 3
        $posw -= 1
        GUICtrlSetPos($while, $posw)
        GUICtrlSetPos($mem, $posw+12)
    WEnd
EndIf
EndFunc

Func Display()
    Sleep(60)
    GUICtrlSetData($b1, $array[0])
    GUICtrlSetData($b2, $array[1])
    GUICtrlSetData($b3, $array[2])
    GUICtrlSetData($b4, $array[3])
    GUICtrlSetData($b5, $array[4])
    GUICtrlSetData($b6, $array[5])
    GUICtrlSetData($b7, $array[6])
    GUICtrlSetData($b8, $array[7])
    GUICtrlSetPos($mem, $posw + 12)
    GUICtrlSetBkColor($mem, 0x9900cc)
    GUICtrlSetData($mem, $memoria)
EndFunc
Edited by xan

Share this post


Link to post
Share on other sites
xan

Example Insertion Sort

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

Global $num1 = 8, $num2 = 5, $num3 = 7, $num4 = 3, $num5 = 1, $num6 = 6, $num7 = 4, $num8 = 2, _
       $posComp = 3, $CollorWhile = 0x9900cc, $B1x = 16, $B2x = 96, $B3x = 176, $B4x = 264, _
       $B5x = 344, $B6x = 432, $B7x = 520, $B8x = 600, $aux = "Start !!", $Btcor

#Region ### START Koda GUI section ### Form=d:\documents and settings\xan\meus documentos\booblesort.kxf
$Form1 = GUICreate("Autoit", 742, 454, 192, 224)
      GUISetBkColor(0xD4D0C8)
$Label1 = GUICtrlCreateLabel("InsertionSort", 170, 5, 598, 177)
      GUICtrlSetFont(-1, 75, 400, 10, "MS Sans Serif")
$b1 = GUICtrlCreateButton($num1, 16, 114, 78, 80)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, 0)
$b2 = GUICtrlCreateButton($num2, 104, 114, 78, 80)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, 0)
$b3 = GUICtrlCreateButton($num3, 192, 114, 78, 80)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, 0)
$b4 = GUICtrlCreateButton($num4, 280, 114, 78, 80)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, 0)
$b5 = GUICtrlCreateButton($num5, 370, 114, 78, 80)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, 0)
$b6 = GUICtrlCreateButton($num6, 460, 114, 78, 80)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, 0)
$b7 = GUICtrlCreateButton($num7, 552, 114, 78, 80)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, 0)
$b8 = GUICtrlCreateButton($num8, 640, 114, 78, 80)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, 0)
$Button3 = GUICtrlCreateButton("", 0, 366, 737, 17,0)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, $GUI_DISABLE )
$ordenar = GUICtrlCreateButton("Sort", 16, 8, 150, 81, $WS_BORDER)
      GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
      GUICtrlSetBkColor(-1, 0xFF0000)
$Button4 = GUICtrlCreateButton("....", 0, 250, 737, 17,0)
      GUICtrlSetFont(-1, 75, 400, 0, "MS Sans Serif")
      GUICtrlSetState(-1, $GUI_DISABLE)
$while = GUICtrlCreateButton("While 0", 16, 290, 700, 121, $WS_BORDER)
      GUICtrlSetFont(-1, 75, 400, 0, "MS Sans Serif")
      GUICtrlSetBkColor(-1, 0xFF0000)
      GUICtrlSetState(-1, $GUI_DISABLE)
$mem = GUICtrlCreateButton("Memory", $posComp + 13, 195, 165, 93, 0)
      GUICtrlSetFont(-1, 28, 400, 0, "MS Sans Serif")
      GUICtrlSetBkColor(-1, 0xA6CAF0)
      GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    if GUIGetMsg() = $ordenar Then
        $CollorWhile = 0x009900
        GUICtrlSetBkColor($ordenar, 0xffff33)
        GUICtrlSetBkColor($while, $CollorWhile)
        Sleep(500)
        ExitLoop
    EndIf
WEnd

While 1
    GUICtrlSetBkColor($B1,  0xf5f5f5)
    GUICtrlSetBkColor($B2,  0xf5f5f5)
    GUICtrlSetBkColor($B3,  0xf5f5f5)
    GUICtrlSetBkColor($B4,  0xf5f5f5)
    GUICtrlSetBkColor($B5,  0xf5f5f5)
    GUICtrlSetBkColor($B6,  0xf5f5f5)
    GUICtrlSetBkColor($B7,  0xf5f5f5)
    GUICtrlSetBkColor($B8,  0xf5f5f5)
    $CollorWhile = 0x00cc33
    GUICtrlSetBkColor($while, $CollorWhile)
    GUICtrlSetData($while, "While 1")
    Sleep(200)

    if $aux = False Then
        GUICtrlDelete($mem)
       $mem = GUICtrlCreateButton("OK !!", $posComp + 13, 195, 165, 93, 0)
       GUICtrlSetFont(-1, 24)
       GUICtrlSetData($while, "Orderly !!!")
    While $posComp  > 3
        $posComp -= 2
        GUICtrlSetPos($mem, $posComp +12)
        Sleep(1)
    WEnd
    Sleep(6000)
        Exit
    EndIf
    $aux = False
    if $num1 > $num2 Then
        $aux = $num1
        Comparador()
        $num1= "..."
        Troca()
        $num1= $num2
        $num2= "..."
        Troca()
        $num2= $aux
        $aux = "..."
        Troca()
    ElseIf $num2 > $num3 Then
        $aux = $num2
        Comparador()
        $num2= "..."
        Troca()
        $num2 = $num3
        $num3= "..."
        Troca()
        $num3 = $aux
        $aux = "..."
        Troca()
    ElseIf $num3 > $num4 Then
        $aux = $num3
        Comparador()
        $num3= "..."
        Troca()
        $num3 = $num4
        $num4= "..."
        Troca()
        $num4 = $aux
        $aux = "..."
        Troca()
    ElseIf $num4 > $num5 Then
        $aux = $num4
        Comparador()
        $num4= "..."
        Troca()
        $num4 = $num5
        $num5= "..."
        Troca()
        $num5 = $aux
        $aux = "..."
        Troca()
    ElseIf $num5 > $num6 Then
        $aux = $num5
        Comparador()
        $num5= "..."
        Troca()
        $num5 = $num6
        $num6= "..."
        Troca()
        $num6 = $aux
        $aux = "..."
        Troca()
    ElseIf $num6 > $num7 Then
        $aux = $num6
        Comparador()
        $num6= "..."
        Troca()
        $num6 = $num7
        $num7= "..."
        Troca()
        $num7 = $aux
        $aux = "..."
        Troca()
    ElseIf $num7 > $num8 Then
        $aux = $num7
        Comparador()
        $num7= "..."
        Troca()
        $num7 = $num8
        $num8= "..."
        Troca()
        $num8 = $aux
        $aux = "..."
        Troca()
    EndIf
WEnd

Func Comparador()
    $CollorWhile = 0x009900
    Switch $aux
        case $num1
            $posComp = 3
            $Btcor   = $B1
        Case $num2
            $posComp = 93
            $Btcor   = $B2
        Case $num3
            $posComp = 183
            $Btcor   = $B3
        Case $num4
            $posComp = 273
            $Btcor   = $B4
        Case $num5
            $posComp = 363
            $Btcor   = $B5
        Case $num6
            $posComp = 453
            $Btcor   = $B6
        Case $num7
            $posComp = 543
            $Btcor   = $B7
        Case $num8
            $posComp = 633
            $Btcor   = $B8
    EndSwitch

    GUICtrlSetBkColor($Btcor, 0x999999)
    GUICtrlSetData($mem, ">>")
    GUICtrlSetPos($mem, $posComp + 12)
    Sleep(300)
    GUICtrlSetBkColor($while, $CollorWhile)
    GUICtrlSetBkColor($mem, 0x999999)
    Sleep(300)
EndFunc

Func Troca()
    GUICtrlSetBkColor($Btcor, 0xf5f5f5)
    GUICtrlSetData($B1,$num1)
    GUICtrlSetData($B2,$num2)
    GUICtrlSetData($B3,$num3)
    GUICtrlSetData($B4,$num4)
    GUICtrlSetData($B5,$num5)
    GUICtrlSetData($B6,$num6)
    GUICtrlSetData($B7,$num7)
    GUICtrlSetData($B8,$num8)
    GUICtrlSetData($mem,$aux)
    GUICtrlSetData($mem,$aux)
    GUICtrlSetPos($mem, $posComp + 12)
    Sleep(500)
EndFunc
Edited by xan

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  

×