Jump to content

windows and physics


Recommended Posts

Hi there

I wanted to do this:

Move a window, once you release it goes a little further (as if it kept moving for the acceleration of the movement) and then it flicks back like pulled back by a spring

I thought that using Hooke's law was the appropriate thing to do... but I haven't got the faintest idea on how to achieve the movement by using Hooke's law and the harmonic motion in general

any help is greatly appreciated

thanks in advance :)

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Hi there

I wanted to do this:

Move a window, once you release it goes a little further (as if it kept moving for the acceleration of the movement) and then it flicks back like pulled back by a spring

I thought that using Hooke's law was the appropriate thing to do... but I haven't got the faintest idea on how to achieve the movement by using Hooke's law and the harmonic motion in general

any help is gratly appreciated

thanks in advance :)

I think the easiest thing to do is to measure the speed of the window as it is being moved so that you know the speed and direction when it is released. Say the release speed is $v then as an approximation you could make a calculation every 50mS say

pos = pos + $v* 50*factor1

$v = $v * cos(Time_since_release * factor2)

and you need to play with it to decide the factors.

I haven't tried it of course :party: but Hooks law produces simple hormonic motion which a Cos calcultaion would simulate.

(Only one axis considered in my 'hand waving' description of course.)

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.
Link to comment
Share on other sites

ok thanks :)

what's factor_1 & factor_2 though ??

excuse me but i'm quite new to physics, and don't know lots of trigonomerty too XD

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

  • Moderators

torels,

I cheated and just took the distance moved as a measure of how far to "bounce":

#include <GUIConstantsEx.au3>

Global Const $WM_MOVING = 0x3
Global $iFlag = 0

$hGUI = GUICreate("Test", 500, 500)

GUIRegisterMsg($WM_MOVING, "_MY_WM_MOVE")

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    
    If $iFlag = 0 Then
        $aPos_Start = WinGetPos("Test", "")
        $iFlag = 1
    EndIf
    
    If $iFlag = 2 Then
        $aPos_Stop = WinGetPos("Test", "")
        
        $iDiff_X = ($aPos_Stop[0] - $aPos_Start[0]) * .002
        $iDiff_Y = ($aPos_Stop[1] - $aPos_Start[1]) * .002
        
        For $i = 1 To 50
            Winmove("Test", "", $aPos_Stop[0] + ($iDiff_X * $i), $aPos_Stop[1] + ($iDiff_Y * $i))
            Sleep(10)
        Next
        
        For $i = 49 To 0 Step -2
            Winmove("Test", "", $aPos_Stop[0] + ($iDiff_X * $i), $aPos_Stop[1] + ($iDiff_Y * $i))
            Sleep(10)
        Next
        
        $iFlag = 0
    EndIf

WEnd

Func _MY_WM_MOVE($hWndGUI, $MsgID, $WParam, $LParam)
    $iFlag = 2
EndFunc

Have fun! :-)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

thanks Melba32

I was actually thinking of a slyghtly different thing though... the point in harmonic motion is that the window (in this case) moves at its movement speed at firts and goes decreasing down to 0... once 0 is reached it goes back again increasing up to the original speed

it's driving me nuts... I'm trying to do think of something but I obtain nothing... I haven't got a clue on wheter or not to use loop and whatsoever XD

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

  • Moderators

torels,

I am now getting shouted at by "she-who-must-be-obeyed" for "playing about" and not helping prepare for the arrival of our weekend guests, but this a better version. Works best with higher speed movements! :-)

#include <GUIConstantsEx.au3>

Global Const $WM_MOVING = 0x3, $pi = 3.14159265358979
Global $iFlag = 0, $iTime, $iTime_Start

$hGUI = GUICreate("Test", 500, 500)

GUIRegisterMsg($WM_MOVING, "_MY_WM_MOVE")

GUISetState()

While 1
    
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    
    If $iFlag = 0 Then
        $aPos_Start = WinGetPos("Test", "")
        $iFlag = 1
    EndIf
    
    If $iFlag = 1 Then $iTime_Start = TimerInit()
        
    If $iFlag = 2 Then
        
        $iTime = TimerDiff($iTime_Start)
        
        $aPos_Current = WinGetPos("Test", "")
        
        $nVel_X = ($aPos_Current[0] - $aPos_Start[0]) * 30 / $iTime
        $nVel_Y = ($aPos_Current[1] - $aPos_Start[1]) * 30 / $iTime
        
        For $i = 0 To 360 Step 5
            $nFactor = Cos($i * $pi / 180)
            
            If $i > 180 Then
                WinMove("Test", "", $aPos_Current[0] + Int($nVel_X * $nFactor / 2), $aPos_Current[1] + Int($nVel_Y * $nFactor / 2))
            Else
                WinMove("Test", "", $aPos_Current[0] + Int($nVel_X * $nFactor), $aPos_Current[1] + Int($nVel_Y * $nFactor))
            EndIf
            $aPos_Current = WinGetPos("Test", "")
            Sleep(50 * Sin ($i * $pi / 720))
            
        Next
            
        $iFlag = 0
    EndIf

WEnd

Func _MY_WM_MOVE($hWndGUI, $MsgID, $WParam, $LParam)
    $iFlag = 2
EndFunc

It is far from perfect - I look forward to your improvements. :-)

Ciao,

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...