Jump to content

Recommended Posts

Posted

I need help with image resize in a GUI It looks like the images needs to to be repainted when resizing them the code is below as well as some screenshots 

 

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

;Set Hot-Keys
HotKeySet("s", "Stop")

$random1 = Random(0,9,1)
$random2 = Random(0,9,1)
$random3 = Random(0,9,1)
$Spin = False
$Sleep = 50
$Height = 132

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 492, 252, 181, 124)
GUISetBkColor(0x000000)
Global $Pic1 = GUICtrlCreatePic( @ScriptDir & "\Numbers\" & $random1 & ".jpg", 48, 16, 100, 132)
Global $Pic2 = GUICtrlCreatePic( @ScriptDir & "\Numbers\" & $random2 & ".jpg", 184, 16, 100, 132)
Global $Pic3 = GUICtrlCreatePic( @ScriptDir & "\Numbers\" & $random3 & ".jpg", 320, 16, 100, 132)
Global $Button1 = GUICtrlCreateButton("Spin", 56, 184, 75, 25)
Global $Button2 = GUICtrlCreateButton("Stop", 336, 184, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $Spin = True
            Spin()


    EndSwitch
WEnd


Func Spin()

While $Spin = True





For $a = 1 to 132 Step 10
GUICtrlSetPos ($Pic1,48, 16, 100, 132 - $a )
Sleep($Sleep)
Next
For $a = 1 to 132 Step 10
GUICtrlSetPos ($Pic2,184, 16, 100, 132 - $a )
Sleep($Sleep)
Next
For $a = 1 to 132 Step 10
GUICtrlSetPos ($Pic3,320, 16, 100, 132 - $a )
Sleep($Sleep)
Next




$random1 = Random(0,9,1)
$random2 = Random(0,9,1)
$random3 = Random(0,9,1)

GUICtrlSetImage ( $Pic1, @ScriptDir & "\Numbers\" & $random1 & ".jpg")
GUICtrlSetImage ( $Pic2, @ScriptDir & "\Numbers\" & $random2 & ".jpg")
GUICtrlSetImage ( $Pic3, @ScriptDir & "\Numbers\" & $random3 & ".jpg")

For $a = 1 to 132 Step 10
GUICtrlSetPos ($Pic1,48, 16, 100, 2 + $a )
Sleep($Sleep)
Next
For $a = 1 to 132 Step 10
GUICtrlSetPos ($Pic2,184, 16, 100, 2 + $a )
Sleep($Sleep)
Next
For $a = 1 to 132 Step 10
GUICtrlSetPos ($Pic3,320, 16, 100, 2 + $a )
Sleep($Sleep)
Next




WEnd

EndFunc



Func Stop()

$Spin = False

    EndFunc

 

how image supposed to look.JPG

how they look after resizing.JPG

Numbers.zip

Posted

@Andreikthanks for that effect it looks nice but that's not what I want since your effect only changes the position of the image but I want to resize it like close and open close with one number and open with another number.

Posted (edited)

This is REALLY not the way I would be doing this but whatever its all about learning I suppose

Your issue is that you loaded the new pictures while the controls were shrunk

I fixed that with a loop to resize them load the random picture and reshrink them 

I also added a way to stop the darn script while I was at it --Edit Oh I See you Set the hotkey to Stop it

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

;Set Hot-Keys
HotKeySet("s", "Stop")

$random1 = Random(0, 9, 1)
$random2 = Random(0, 9, 1)
$random3 = Random(0, 9, 1)
$Spin = False
$Sleep = 50
$Height = 132

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 492, 252, 181, 124)
GUISetBkColor(0x000000)
Global $Pic1 = GUICtrlCreatePic(@ScriptDir & "\Numbers\" & $random1 & ".jpg", 48, 16, 100, 132)
Global $Pic2 = GUICtrlCreatePic(@ScriptDir & "\Numbers\" & $random2 & ".jpg", 184, 16, 100, 132)
Global $Pic3 = GUICtrlCreatePic(@ScriptDir & "\Numbers\" & $random3 & ".jpg", 320, 16, 100, 132)
Global $Button1 = GUICtrlCreateButton("Spin", 56, 184, 75, 25)
Global $Button2 = GUICtrlCreateButton("Stop", 336, 184, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            Opt("GUIOnEventMode", 1)
            GUICtrlSetOnEvent($Button2, Stop)
            $Spin = True
            Spin()


    EndSwitch
WEnd


Func Spin()
    Local $aPicCtrls[3] = [$Pic1, $Pic2, $Pic3]
    Local $aPicLeft[3] = [48, 184, 320]
    While $Spin = True

        For $i = 0 To UBound($aPicCtrls) - 1
            For $a = 1 To 132 Step 10
                GUICtrlSetPos($aPicCtrls[$i], $aPicLeft[$i], 16, 100, 132 - $a)
                Sleep($Sleep)
                If Not $Spin Then ExitLoop 3
            Next
        Next

        For $i = 0 To UBound($aPicCtrls) - 1
            $iRand = Random(0, 9, 1)
            GUICtrlSetState($aPicCtrls[$i], $GUI_HIDE)
            GUICtrlSetPos($aPicCtrls[$i], $aPicLeft[$i], 16, 100, 132)
            GUICtrlSetImage($aPicCtrls[$i], @ScriptDir & "\Numbers\" & $iRand & ".jpg")
            GUICtrlSetPos($aPicCtrls[$i], $aPicLeft[$i], 16, 100, 0)
            GUICtrlSetState($aPicCtrls[$i], $GUI_SHOW)
        Next

        For $i = 0 To UBound($aPicCtrls) - 1
            For $a = 1 To 132 Step 10
                GUICtrlSetPos($aPicCtrls[$i], $aPicLeft[$i], 16, 100, 2 + $a)
                Sleep($Sleep)
                If Not $Spin Then ExitLoop 3
            Next
        Next

    WEnd

EndFunc   ;==>Spin

Func Stop()
    Opt("GUIOnEventMode", 0)
    $Spin = False
EndFunc   ;==>Stop

 

Edited by Bilgus
Posted

@Mannyfresh31, Thanks for this, I can use this in our current activity "Lucky 3 for a Cause". We are using bottle with numbers in it and shake it for the lucky 3 numbers, once you hit the 3 lucky numbers based, the one that holds the numbers will have cash and 50% of that cash will be donated to our selected charity.:lol: \m/

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Posted

@KickStarter15  A word of warning Those numbers are severely NON-Random I would never base a game of chance on them even a charity one..

At the very least see SRandom() in the manual, better would be a few more steps for the calculations, best would be a real(er?) random number generator

 

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
  • Recently Browsing   0 members

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