Jump to content

Recommended Posts

Posted (edited)

hi all this is my first example in autoit forum so please comment

after seeing andybiochem's topic about the elastic radio buttons following the mouse pointer i decided to create something for my GF using this func for valentine's day

HAPPY VALENTINE DAY

ok now to test this u will have to save the script then save the PNGs to a folder named "Set" in the script directory

and it should look like this :

Posted Image

;====== Elastic Trail script ======
; Original Javascript by Philip Winston - pwinston@yahoo.com
; Adapted for AutoIT by AndyBiochem
; Used with GDI+ for PNG's by yehia

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3> 


;----- Variables -----
Global $iDots = 7      ;..... Number of PNGs
Global $aDots[$iDots][5]      ;..... PNGs array
Global $iXpos = 0
Global $iYpos = 0
Global $iDeltaT = 0.01
Global $iSegLen = 10
Global $iSpringK = 10
Global $iMass = 1
Global $iXGravity = 0
Global $iYGravity = 50
Global $iRes = 10
Global $iStopVel = 0.1
Global $iStopAcc = 0.1
Global $iDotSize = 25
Global $iBounce = 0.75

Global Const $AC_SRC_ALPHA      = 1

Global $iHeight = @DesktopHeight
Global $iWidth = @DesktopWidth

;----- 'PNGs' -----
Myname() ; just my name on the back :P

For $i = 1 To ($iDots - 1)
    $iDotSize-=2
    $aDots[$i][0] = GUICreate("", $iDotSize, $iDotSize, 144, 160, $WS_POPUP , $WS_EX_LAYERED + $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir &"\Set\" &$i& ".png")
    SetBitMap($aDots[$i][0] , $hImage, 255)
    GUISetState(@SW_SHOW)
Next

;############### LOOP ###############
While 1

    Sleep(10)

    $m = MouseGetPos()
    $iXpos = $m[0]
    $iYpos = $m[1]

    _Animate()

WEnd
;####################################


Func _Animate()

    $aDots[0][1] = $iXpos
    $aDots[0][2] = $iYpos

    For $i = 1 To ($iDots - 1)

        Local $spring[3]
        $spring[1] = 0
        $spring[2] = 0

        _Spring_Force($i - 1, $i, $spring)
        If $i < ($iDots - 1) Then _Spring_Force($i + 1, $i, $spring)

        Local $resist[3]
        $resist[1] = -$aDots[$i][3] * $iRes
        $resist[2] = -$aDots[$i][4] * $iRes


        Local $accel[3]
        $accel[1] = ($spring[1] + $resist[1]) / $iMass + $iXGravity
        $accel[2] = ($spring[2] + $resist[2]) / $iMass + $iYGravity

        $aDots[$i][3] += ($iDeltaT * $accel[1])
        $aDots[$i][4] += ($iDeltaT * $accel[2])


        If Abs($aDots[$i][3]) < $iStopVel And Abs($aDots[$i][4]) < $iStopVel And Abs($accel[1]) < $iStopAcc And Abs($accel[2]) < $iStopAcc Then
            $aDots[$i][3] = 0
            $aDots[$i][4] = 0
        EndIf

        $aDots[$i][1] += $aDots[$i][3]
        $aDots[$i][2] += $aDots[$i][4]

        If ($aDots[$i][2] < 0) Then
            If ($aDots[$i][4] < 0) Then $aDots[$i][4] = $iBounce * - $aDots[$i][4]
            $aDots[$i][2] = 0
        EndIf

        If ($aDots[$i][2] >= $iHeight - $iDotSize - 1) Then
            If ($aDots[$i][4] > 0) Then $aDots[$i][4] = $iBounce * - $aDots[$i][4]
            $aDots[$i][2] = $iHeight - $iDotSize - 1
        EndIf

        If ($aDots[$i][1] >= $iWidth - $iDotSize) Then
            If ($aDots[$i][3] > 0) Then $aDots[$i][3] = $iBounce * - $aDots[$i][3]
            $aDots[$i][1] = $iWidth - $iDotSize - 1
        EndIf

        If ($aDots[$i][1] < 0) Then
            If ($aDots[$i][3] < 0) Then $aDots[$i][3] = $iBounce * - $aDots[$i][3]
            $aDots[$i][1] = 0
        EndIf

        WinMove($aDots[$i][0], "", $aDots[$i][1], $aDots[$i][2])

    Next

EndFunc  ;==>_Animate


Func _Spring_Force($i, $j, ByRef $spring)

    Local $springF

    $dx = $aDots[$i][1] - $aDots[$j][1]
    $dy = $aDots[$i][2] - $aDots[$j][2]
    $len = Sqrt($dx ^ 2 + $dy ^ 2)

    If Not ($len > $iSegLen) Then Return

    $springF = $iSpringK * ($len - $iSegLen)
    $spring[1] += ($dx / $len) * $springF
    $spring[2] += ($dy / $len) * $springF

EndFunc  ;==>_Spring_Force

Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _WinAPI_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC    ($hMemDC)
EndFunc  ;==>SetBitmap

Func Myname()
    $yGUI = GUICreate("", 200, 120, (@DesktopWidth/2)-100, (@DesktopHeight/2)-60, $WS_POPUP , $WS_EX_LAYERED + $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)
    _GDIPlus_Startup()
    $yImage = _GDIPlus_ImageLoadFromFile(@ScriptDir &"\Set\y.png")
    SetBitMap($yGUI , $yImage, 255)
    GUISetState(@SW_SHOW)
EndFunc  ;==>Myname

NOW the PNGs, download this rar file attached put it in the script directory and bam u got it

HAPPY VALENTINE again

credit goes to andybiochem first then me, i just created the GDI part

Edit : spelling

Set.rar

Edited by yehia
Posted

Very, very nice :)

When you change line 36 to For $i = ($iDots - 1) To 1 Step -1 the hearts will be drawn from back to front.

Thanks,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

thanks all i really lost the hope that someone will replay my topic :)

btw o used PNGs cause u can use them layered for the shadow effects and u can used photoshop to create them

@Andreik u can get a portable version like 50 mb or something

@JRowe thanks man

@UEZ and u have the vars u can change $iSegLen value and u will just get them away from each other :)

Posted

HA! and everyone said this had no use! I feel happy in the fact I may have got you laid.

Good job yehia.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Posted

ok removed the useless part

@UEZ it aint that bad with a GF :)

I don't want to discuss here the sense or nonsenses of Valentine's day even though I've a gf, be married or anything else. :)

I just wanted to say my opinion about VD - probably it was off topic...

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

HA! and everyone said this had no use! I feel happy in the fact I may have got you laid.

Good job yehia.

@andybiochem hahahaha well not laid xD

I don't want to discuss here the sense or nonsenses of Valentine's day even though I've a gf, be married or anything else. :)

I just wanted to say my opinion about VD - probably it was off topic...

UEZ

@UEZ ok

and please if anyone have any changes to apply on this to make it look better just show the codes and thanks all for your nice comments :)

Posted (edited)

since i noticed that the above example just gives PNGs number - 1

so i created this

to get the exact number of PNGs :

;====== Elastic Trail script ======
; Original Javascript by Philip Winston - pwinston@yahoo.com
; Adapted for AutoIT by AndyBiochem
; Used with GDI+ for PNG's by yehia

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3> 


;----- Variables -----
Global $iDots = 7;Number of BNGs
Global $aDots[$iDots + 1][5]     ;to get exact no of BNGs
Global $iXpos = 0
Global $iYpos = 0
Global $iDeltaT = 0.01
Global $iSegLen = 10
Global $iSpringK = 10
Global $iMass = 1
Global $iXGravity = 0
Global $iYGravity = 50
Global $iRes = 10
Global $iStopVel = 0.1
Global $iStopAcc = 0.1
Global $iDotSize = 25
Global $iBounce = 0.75

Global Const $AC_SRC_ALPHA      = 1

Global $iHeight = @DesktopHeight
Global $iWidth = @DesktopWidth

;----- 'Dots' -----
For $i = 1 To $iDots       ;to get exact no of dots
    $iDotSize-=2
    $aDots[$i][0] = GUICreate("", $iDotSize, $iDotSize, 144, 160, $WS_POPUP , $WS_EX_LAYERED + $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir &"\Set\" &$i& ".png");"\untitled.png")
    SetBitMap($aDots[$i][0] , $hImage, 255)
    GUISetState(@SW_SHOW)
Next

;############### LOOP ###############
While 1

    Sleep(10)

    $m = MouseGetPos()
    $iXpos = $m[0]
    $iYpos = $m[1]

    _Animate()

WEnd
;####################################


Func _Animate()

    $aDots[0][1] = $iXpos
    $aDots[0][2] = $iYpos

    For $i = 1 To $iDots    ; to get exact number of dots

        Local $spring[3]
        $spring[1] = 0
        $spring[2] = 0

        _Spring_Force($i - 1, $i, $spring)
        If $i < ($iDots - 1) Then _Spring_Force($i + 1, $i, $spring)

        Local $resist[3]
        $resist[1] = -$aDots[$i][3] * $iRes
        $resist[2] = -$aDots[$i][4] * $iRes


        Local $accel[3]
        $accel[1] = ($spring[1] + $resist[1]) / $iMass + $iXGravity
        $accel[2] = ($spring[2] + $resist[2]) / $iMass + $iYGravity

        $aDots[$i][3] += ($iDeltaT * $accel[1])
        $aDots[$i][4] += ($iDeltaT * $accel[2])


        If Abs($aDots[$i][3]) < $iStopVel And Abs($aDots[$i][4]) < $iStopVel And Abs($accel[1]) < $iStopAcc And Abs($accel[2]) < $iStopAcc Then
            $aDots[$i][3] = 0
            $aDots[$i][4] = 0
        EndIf

        $aDots[$i][1] += $aDots[$i][3]
        $aDots[$i][2] += $aDots[$i][4]

        If ($aDots[$i][2] < 0) Then
            If ($aDots[$i][4] < 0) Then $aDots[$i][4] = $iBounce * - $aDots[$i][4]
            $aDots[$i][2] = 0
        EndIf

        If ($aDots[$i][2] >= $iHeight - $iDotSize - 1) Then
            If ($aDots[$i][4] > 0) Then $aDots[$i][4] = $iBounce * - $aDots[$i][4]
            $aDots[$i][2] = $iHeight - $iDotSize - 1
        EndIf

        If ($aDots[$i][1] >= $iWidth - $iDotSize) Then
            If ($aDots[$i][3] > 0) Then $aDots[$i][3] = $iBounce * - $aDots[$i][3]
            $aDots[$i][1] = $iWidth - $iDotSize - 1
        EndIf

        If ($aDots[$i][1] < 0) Then
            If ($aDots[$i][3] < 0) Then $aDots[$i][3] = $iBounce * - $aDots[$i][3]
            $aDots[$i][1] = 0
        EndIf
        
        $aDots[$i][1] = $aDots[$i][1] + .24*$i   ;for centering PNGs under mouse

        WinMove($aDots[$i][0], "", $aDots[$i][1] , $aDots[$i][2])

    Next

EndFunc  ;==>_Animate


Func _Spring_Force($i, $j, ByRef $spring)

    Local $springF

    $dx = $aDots[$i][1] - $aDots[$j][1]
    $dy = $aDots[$i][2] - $aDots[$j][2]
    $len = Sqrt($dx ^ 2 + $dy ^ 2)

    If Not ($len > $iSegLen) Then Return

    $springF = $iSpringK * ($len - $iSegLen)
    $spring[1] += ($dx / $len) * $springF
    $spring[2] += ($dy / $len) * $springF

EndFunc  ;==>_Spring_Force

Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _WinAPI_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC    ($hMemDC)
EndFunc

comment please

thanks

Edited by yehia
Posted

wow what a nice effect you have here, too bad its late to give my GF that :)

i tested the second script you provided too but didnt notice the difference until i did a count for the hearts :)

good work man

Posted

thanks a lot that's supportive and btw its never too late :)

and about the difference between the first and the second script; the first always misses the last BNG (the smallest one)

thanks for your replay

and thats the script to draw the BNGs from the end

;====== Elastic Trail script ======
; Original Javascript by Philip Winston - pwinston@yahoo.com
; Adapted for AutoIT by AndyBiochem
; Used with GDI+ for PNG's by yehia

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3> 


;----- Variables -----
Global $iDots = 7      ;..... Number of PNGs
Global $aDots[$iDots][5]      ;..... PNGs array
Global $iXpos = 0
Global $iYpos = 0
Global $iDeltaT = 0.01
Global $iSegLen = 10
Global $iSpringK = 10
Global $iMass = 1
Global $iXGravity = 0
Global $iYGravity = 50
Global $iRes = 10
Global $iStopVel = 0.1
Global $iStopAcc = 0.1
Global $iDotSize = 25
Global $iBounce = 0.75

Global Const $AC_SRC_ALPHA      = 1

Global $iHeight = @DesktopHeight
Global $iWidth = @DesktopWidth

;----- 'PNGs' -----
Myname() ; just my name on the back :P

For $i = ($iDots - 1) To 1 Step -1
    $iDotSize-=2
    $aDots[$i][0] = GUICreate("", $iDotSize, $iDotSize, 144, 160, $WS_POPUP , $WS_EX_LAYERED + $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir &"\Set\" &$i& ".png")
    SetBitMap($aDots[$i][0] , $hImage, 255)
    GUISetState(@SW_SHOW)
Next

;############### LOOP ###############
While 1

    Sleep(10)

    $m = MouseGetPos()
    $iXpos = $m[0]
    $iYpos = $m[1]

    _Animate()

WEnd
;####################################


Func _Animate()

    $aDots[0][1] = $iXpos
    $aDots[0][2] = $iYpos

    For $i = 1 To ($iDots - 1)

        Local $spring[3]
        $spring[1] = 0
        $spring[2] = 0

        _Spring_Force($i - 1, $i, $spring)
        If $i < ($iDots - 1) Then _Spring_Force($i + 1, $i, $spring)

        Local $resist[3]
        $resist[1] = -$aDots[$i][3] * $iRes
        $resist[2] = -$aDots[$i][4] * $iRes


        Local $accel[3]
        $accel[1] = ($spring[1] + $resist[1]) / $iMass + $iXGravity
        $accel[2] = ($spring[2] + $resist[2]) / $iMass + $iYGravity

        $aDots[$i][3] += ($iDeltaT * $accel[1])
        $aDots[$i][4] += ($iDeltaT * $accel[2])


        If Abs($aDots[$i][3]) < $iStopVel And Abs($aDots[$i][4]) < $iStopVel And Abs($accel[1]) < $iStopAcc And Abs($accel[2]) < $iStopAcc Then
            $aDots[$i][3] = 0
            $aDots[$i][4] = 0
        EndIf

        $aDots[$i][1] += $aDots[$i][3]
        $aDots[$i][2] += $aDots[$i][4]

        If ($aDots[$i][2] < 0) Then
            If ($aDots[$i][4] < 0) Then $aDots[$i][4] = $iBounce * - $aDots[$i][4]
            $aDots[$i][2] = 0
        EndIf

        If ($aDots[$i][2] >= $iHeight - $iDotSize - 1) Then
            If ($aDots[$i][4] > 0) Then $aDots[$i][4] = $iBounce * - $aDots[$i][4]
            $aDots[$i][2] = $iHeight - $iDotSize - 1
        EndIf

        If ($aDots[$i][1] >= $iWidth - $iDotSize) Then
            If ($aDots[$i][3] > 0) Then $aDots[$i][3] = $iBounce * - $aDots[$i][3]
            $aDots[$i][1] = $iWidth - $iDotSize - 1
        EndIf

        If ($aDots[$i][1] < 0) Then
            If ($aDots[$i][3] < 0) Then $aDots[$i][3] = $iBounce * - $aDots[$i][3]
            $aDots[$i][1] = 0
        EndIf

        WinMove($aDots[$i][0], "", $aDots[$i][1], $aDots[$i][2])

    Next

EndFunc  ;==>_Animate


Func _Spring_Force($i, $j, ByRef $spring)

    Local $springF

    $dx = $aDots[$i][1] - $aDots[$j][1]
    $dy = $aDots[$i][2] - $aDots[$j][2]
    $len = Sqrt($dx ^ 2 + $dy ^ 2)

    If Not ($len > $iSegLen) Then Return

    $springF = $iSpringK * ($len - $iSegLen)
    $spring[1] += ($dx / $len) * $springF
    $spring[2] += ($dy / $len) * $springF

EndFunc  ;==>_Spring_Force

Func _Close()
    Exit
EndFunc  ;==>_Close

Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _WinAPI_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC    ($hMemDC)
EndFunc  ;==>SetBitmap

Func Myname()
    $yGUI = GUICreate("", 200, 120, (@DesktopWidth/2)-100, (@DesktopHeight/2)-60, $WS_POPUP , $WS_EX_LAYERED + $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)
    _GDIPlus_Startup()
    $yImage = _GDIPlus_ImageLoadFromFile(@ScriptDir &"\Set\y.png")
    SetBitMap($yGUI , $yImage, 255)
    GUISetState(@SW_SHOW)
EndFunc
  • 1 month later...
Posted

thanks a lot :o

im just thinking what more can this example do ...

something like a mouse key chain :D

Easter Bunnies hanging/shagging arround would be... something.

♡♡♡

.

eMyvnE

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