Advertisement
Mangus875

(autohotkey) bouncing deskop cat friend

May 4th, 2024
1,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance Off
  2. CoordMode "Mouse", "Screen"
  3. CoordMode "ToolTip", "Screen"
  4. #R::Reload
  5. SetWinDelay 0
  6.  
  7. guiW := 60
  8. guiH := 46
  9.  
  10. MyGui := Gui(, "")
  11. MyGui.Opt("ToolWindow -Sysmenu +AlwaysOnTop")
  12. MyGui.SetFont "s36 w700"
  13. ;"ebad54"
  14. ; MyGui.BackColor := format("{1:x}", ((235 << 16) | (173 << 8) | 84) + ((random(-35,35) << 16) | (random(-30,30) << 8) | random(-20,20)))
  15. MyGui.BackColor := format("{1:x}", ((random(50,240) << 16) | (random(50,240) << 8) | random(50,240)))
  16.  
  17. MyGui.Add("Text", "x" (guiW/2-21) " y" (guiH/2-44), ". .")
  18. MyGui.SetFont "cfff0ee s30", "Javanese Text"
  19. MyGui.Add("Text", "xp15 yp-1", "!")
  20. MyGui.SetFont "s16"
  21. MyGui.SetFont "c000000", "Courier New"
  22. MyGui.Add("Text", "w12 yp44", "^")
  23. WinSetStyle("-0xC00000", MyGui)
  24.  
  25. OnMessage(0x201, WM_MouseDown)
  26. MyGui.Show("w" guiW " h" guiH " Center NoActivate")
  27. lastX := 0
  28. lastY := 0
  29. dx := 0
  30. dy := 0
  31. falling := false
  32. grabbed := false
  33. areaLeft := 0
  34. areaTop := 0
  35. areaRight := 0
  36. areaBottom := 0
  37.  
  38. !P::ExitApp
  39.  
  40. WM_MouseDown(wParam, lParam, msg, window) {
  41.     global grabbed
  42.    
  43.     if (window != MyGui.Hwnd) {
  44.         return
  45.     }
  46.    
  47.     grabbed := true
  48.     MouseGetPos &mouseX, &mouseY
  49.     lastX := mouseX
  50.     lastY := mouseY
  51. }
  52.  
  53. ~LButton Up::MouseUp
  54. MouseUp() {
  55.     global grabbed
  56.     global dx
  57.     global dy
  58.    
  59.     speedFactor := 0.2
  60.    
  61.     if grabbed {
  62.         grabbed := false
  63.         fall(dx*speedFactor, dy*speedFactor)
  64.     }
  65. }
  66.  
  67. velx := 0.0
  68. posx := 0.0
  69. accy := 0.1
  70. vely := 0.0
  71. posy := 0.0
  72. fall(xinit := 0, yinit := 0) {
  73.     global velx
  74.     global posx
  75.     global vely
  76.     global accy
  77.     global posy
  78.     global dx
  79.     global dy
  80.     global falling
  81.     velX := xinit
  82.     velY := yinit
  83.    
  84.     fric := 1
  85.     bounce := 1
  86.    
  87.     falling := true
  88.    
  89.     WinGetPos &startX, &startY,,, MyGui
  90.     posY := startY
  91.     posX := startX
  92.    
  93.     MonitorGetWorkArea , &areaLeft, &areaTop, &areaRight, &areaBottom
  94.     while (abs(velY) > 0.5 or (areaBottom - abs(posY+guiH) > 2)) {
  95.         Sleep 1
  96.         velY += accY
  97.         posY += velY
  98.         posX += velX
  99.        
  100.         WinGetPos &winx, &winy,,, MyGui
  101.         if (posY+guiH > areaBottom) {
  102.             ; WinMove winx, areaBottom-guiH,,, MyGui
  103.             posY := areaBottom-guiH
  104.             velY := -bounce*abs(velY)
  105.             velX *= fric
  106.         } else if (posY < areaTop) {
  107.             ; WinMove winx, areaTop,,, MyGui
  108.             posY := areaTop
  109.             velY := bounce*abs(velY)
  110.             velX *= fric
  111.         }
  112.        
  113.         if (winX+guiW > areaRight) {
  114.             ; WinMove areaRight-guiW, posY,,, MyGui
  115.             posX := areaRight-guiW
  116.             velX := -bounce*abs(velX)
  117.             velY *= fric
  118.         } else if (posX < areaLeft) {
  119.             ; WinMove areaLeft, posY,,, MyGui
  120.             posX := areaLeft
  121.             velX := bounce*abs(velX)
  122.             velY *= fric
  123.         }
  124.        
  125.         WinMove posX, posY,,, MyGui
  126.         if grabbed {
  127.             break
  128.         }
  129.     }  
  130.    
  131.     WinGetPos &endposX,,,, MyGui
  132.     if (!grabbed) {
  133.         WinMove endposX, areaBottom-guiH,,, MyGui
  134.     }
  135.     velY := 0
  136.     posY := 0
  137.     velX := 0
  138.     posX := 0
  139.     SetTimer () => falling := false, -5
  140. }
  141.  
  142. fall(0, -3)
  143.  
  144. while true {
  145.     global dx
  146.     global dy
  147.     global lastX
  148.     global lastY
  149.     global grabbed
  150.     WinGetPos &winx, &winy,,, MyGui
  151.     MouseGetPos &x, &y
  152.     dx := x-lastX
  153.     dy := y-lastY
  154.     lastX := x
  155.     lastY := y
  156.    
  157.     if (!falling && grabbed) {
  158.         WinMove winx+dx, winy+dy,,, MyGui
  159.     }
  160.    
  161.     sleep 1
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement