 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
kimbledon
Joined: 28 Sep 2007 Posts: 26
|
Posted: Wed Oct 31, 2007 3:25 pm Post subject: Gravity testing |
|
|
I made an example to simulate gravity in a program.
Maybe this could be used in some useful script
| Code: |
SetBatchLines -1
Gui, Add, Text, x96 y20 w23 h15 vBalltext, Ball
Gui, Add, Button, x16 y20 w50 h20 gDropping, Drop
Gui, Add, Button, x16 y50 w50 h20 gStop, Stop
Gui, Show, x150 y2 h741 w162, Gravity Testing
Return
GuiClose:
ExitApp
Stop:
speed = 0
yposition = 20
SetTimer, falling, off
GuiControl, Move, Balltext, x96 y20
return
Dropping:
speed = 0
yposition = 20
SetTimer, falling, 10
return
falling:
speed += 0.098
yposition += speed
GuiControl, Move, Balltext, x96 y%yposition%
return
|
|
|
| Back to top |
|
 |
Rabiator
Joined: 17 Apr 2005 Posts: 264 Location: Sauerland
|
Posted: Wed Oct 31, 2007 9:44 pm Post subject: |
|
|
Nice idea !
I played around with it a little bit. Now we can watch the ball two-dimensional with damping | Code: | SetBatchLines -1
Height := 600
Width := 960
DiffSpeed := 0.098
Damping := 0.995
y := Height
x := 0
Gui, Add, Text, x96 y20 w23 h15 vBalltext, Ball
Gui, Add, Button, x16 y20 w50 h20 gDropping, Drop
Gui, Add, Button, x16 y50 w50 h20 gStop, Stop
Gui, Show, x10 y10 h%Height% w%Width%, Gravity Testing
Return
GuiClose:
ExitApp
Stop:
SetTimer, falling, off
GuiControl, Move, Balltext, x96 y20
return
Dropping:
speed := 0.0
x := 0
y := Height - 40
SetTimer, falling, 10
return
falling:
x += 0.5
If (y < 0) {
y *= -1.0
speed := Abs(Speed)
}
speed -= DiffSpeed
y += speed
y *= Damping
yposition := (y < 2) ? Height - 20 : Height - y - 20
xposition := x + 96
If (xposition > Width-20)
Goto Stop
GuiControl, Move, Balltext, x%xposition% y%yposition%
return |
|
|
| Back to top |
|
 |
kimbledon
Joined: 28 Sep 2007 Posts: 26
|
Posted: Wed Oct 31, 2007 11:05 pm Post subject: |
|
|
Wow. that's nice
I calculated some extra things on my script. Something like distance from startingpoint, speed in km/h and m/s (I live in Europe)
I post the code tomorrow.
Am I right that 10 pixels would be 1 meter in real world? |
|
| Back to top |
|
 |
kimbledon
Joined: 28 Sep 2007 Posts: 26
|
Posted: Wed Oct 31, 2007 11:39 pm Post subject: |
|
|
I was wrong.. It isn't 10 pixels I have to figure it out
Edit: It's about 50 pixels
And the improved code:
| Code: |
SetBatchLines -1
GuiHeight = 750
MaxHeight := GuiHeight-30
Gui, Add, Text, x120 y20 w23 h15 vBalltext, Ball
Gui, Add, Text, x5 y250 w100 h15 vSpeedtext, Speed:
Gui, Add, Text, x42 y270 w70 h15 vSpeedtextmpers,
Gui, Add, Text, x5 y190 w100 h15 vTimetext, Time:
Gui, Add, Text, x5 y220 w100 h15 vDistancetext, Distance:
textyposition = 34
meters = 0
Loop {
if (textyposition > MaxHeight)
{
textyposition -= 52
meters--
break
}
Gui, Add, Text, x170 y%textyposition% w40 h10, ¯¯¯¯¯¯
meters++
textyposition += 50.5
}
continues:
Gui, Add, Text, x230 y34 w60 h15 , 0 m
Gui, Add, Text, x230 y%textyposition% w60 h15 , %meters% m
Gui, Add, Edit, x16 y110 w40 h17 vMaxtime,
Gui, Add, Text, x66 y110 w45 h17,MAX (s)
Gui, Add, Edit, x16 y130 w40 h17 vMaxdistance,
Gui, Add, Text, x66 y130 w46 h17,MAX (m)
Gui, Add, Edit, x16 y150 w40 h17 vMaxspeed,
Gui, Add, Text, x66 y150 w50 h17,MAX (m/s)
Gui, Add, Button, x16 y20 w40 h20 Default gDropping, Drop
Gui, Add, Button, x16 y50 w40 h20 gPause, Pause
Gui, Add, Button, x16 y80 w40 h20 gReset, Reset
Gui, Show, x150 y2 h741 w270, Gravity Testing
Return
GuiClose:
ExitApp
Reset:
speed = 0
yposition = 20
speedkmperh = 0
speedmpers = 0
Distance = 0
time = o
SetTimer, falling, off
GuiControl, ,Speedtext, Speed: 0 km/h
GuiControl, ,Speedtextmpers, 0 m/s
GuiControl, ,Distancetext, Distance: 0 m
GuiControl,,Timetext, Time: 0 sec
GuiControl, Move, Balltext, x120 y20
return
Dropping:
Gui, Submit, NoHide
if maxdistance =
maxdistance = 100000000000000
if maxtime =
maxtime = 100000000000000
if maxspeed =
maxspeed = 100000000000000
speed = 0
time = 0
speedkmperh = 0
speedmpers = 0
Distance = 0
yposition = 20
SetTimer, falling, 10
return
falling:
time := Round(time+0.01,2)
speed += 0.098
yposition += speed
Distance := Round(speed*(time),2)
speedkmperh := Round(speed*3.6,2)
speedmpers := Round(speed,2)
GuiControl, ,Speedtext, Speed: %speedkmperh% km/h
GuiControl,,Timetext, Time: %time% sec
GuiControl, ,Speedtextmpers, %speedmpers% m/s
GuiControl, ,Distancetext, Distance: %Distance% m
GuiControl, Move, Balltext, x120 y%yposition%
if (distance >= maxdistance || speedmpers >= maxspeed || time >= maxtime)
{
goto pause
}
return
pause:
SetTimer, falling, off
return
|
You can test how long would take if you jumped from 20 meters high
Just put MAX (m) = 20
Of course this doesn't work with high distances. |
|
| Back to top |
|
 |
Dra_Gon
Joined: 25 May 2007 Posts: 167
|
Posted: Fri Dec 07, 2007 2:26 am Post subject: |
|
|
Just discovered this cool toy! Thanks, kimbledon! Of course, I decided to make just an itsy-bitsy change:
| Code: |
from:
Gui, Add, Text, x96 y20 w23 h15 vBalltext, Ball
to:
Gui, Add, Text, x96 y20 w23 vBalltext, %a_space%0`n/!\`n/ \
|
Yeah, it's a bit primitive, but - for some reason - I just needed to do it.
Thanks again.
Dra'Gon _________________ For a good laugh {hopefully} >> megamatts.50megs.com
SciFi/Fantasy Short Stories I wrote {StohlerWorlds I} >>
http://www.mediafire.com/?2yisetu0jud |
|
| Back to top |
|
 |
pockinator
Joined: 06 Dec 2007 Posts: 33
|
Posted: Fri Dec 07, 2007 8:03 pm Post subject: |
|
|
Very neat, kimbledon! I love physics, so I'll probably be using this script later on to learn some more things about programming with a "live" gui. Thanks!  |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 101 Location: Osnabrück, Germany
|
Posted: Sat Dec 08, 2007 12:33 am Post subject: |
|
|
take this line
| Quote: | Gui, Add, Picture,x120 y20 w23 h15 vBalltext Icon1 ,C:\windows\notepad.exe
|
instead
| Quote: | | Gui, Add, Text, x120 y20 w23 h15 vBalltext, Ball |
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|