Page 1 of 11

### Rosetta Code

Posted: 10 Jan 2014, 07:54
Rosetta Code

AutoHotkey examples needing attention

Rank: 29. Jan 2017 (RC_POP.OUT)

Code: Select all

``````  1. Racket        932
....
20. AutoHotkey    611
21. Common Lisp   609
....
132. AutoIt         91``````
===============================================

- MD4
- SHA-1
- SHA-256
- CRC32

Fixed:
- Leap Year

Improvement:
- SEDOL

### Re: Rosetta Code

Posted: 11 Jan 2014, 01:58
nice

### Re: Rosetta Code

Posted: 11 Jan 2014, 04:42

### Re: Rosetta Code

Posted: 15 Jan 2014, 06:44
@jNiZm
Please add this link ( http://rosettacode.org/wiki/Reports:Tas ... AutoHotkey ) to the top so that anybody who wants to enrich AutoHotkey by completing more and more tasks can help.
Let's put AHK in top 10 there.

### Re: Rosetta Code

Posted: 15 Jan 2014, 13:41
Alright! I agree

### Re: Rosetta Code

Posted: 15 Jan 2014, 13:58
Lets Discuss things here:
http://rosettacode.org/wiki/Animate_a_pendulum
This one is easy though it seems complex at first sight.
Instead of calculating the position with complex physical calculation, you should rather calculate the angle of the pendulum.
Its done with the folowing:

Code: Select all

``angle:=minmaxangle*sin(speed*currenttime)``
When using OpenGL (like C does there) the angle is just the Information you need.
Any better Ideas?

### Re: Rosetta Code

Posted: 15 Jan 2014, 18:16
Did someone ask for a pendulum simulation? The physics behind it isn't too bad.

Probably could have been done with gdip.ahk but I didn't want dependencies on external libraries if it's going on Rosetta Code. (so you can just copy the code and run it)

Code: Select all

``````angle := 3.14159 / 2.5   ;Starting angle in radians
velocity := 0            ;Initial angular velocity in radians/second
dt := 0.01               ;How often to update the simulation in seconds
gravity := -9.81         ;Acceleration due to gravity
lineColor := 0xffffff    ;Line and ball outline color
ballColor := 0xee00ff    ;Ball color
backColor := 0x000000    ;Background color
timescale := 5           ;Simulation speed multiplier (1 = realtime)
width := 500             ;Window width in pixels
height := 500            ;Window height in pixels
length := floor(0.4*(width < height ? width : height))  ;Line length in pixels

;Set up gui and memory bitmap
Gui, +hwndDrawSurface
hdc := DllCall("GetDC", "ptr", DrawSurface)
mdc := DllCall("CreateCompatibleDC", "ptr", hdc)
hbm := DllCall("CreateCompatibleBitmap", "ptr", hdc, "int", width, "int", height)

;Set up drawing resources
BallBrush := DllCall("CreateSolidBrush", "uint", ballColor)
LinePen := DllCall("CreatePen", "int", 0, "int", 2, "uint", lineColor)
BackBrush := DllCall("CreateSolidBrush", "uint", backColor)

;Get the default objects for cleanup later
defaultBitmap := DllCall("SelectObject", "ptr", mdc, "ptr", hbm)
defaultBrush := DllCall("SelectObject", "ptr", mdc, "ptr", BallBrush)
defaultPen := DllCall("SelectObject", "ptr", mdc, "ptr", LinePen)

;Show window and create a timer to update and redraw the pendulum
Gui, Show, w%width% h%height%
SetTimer, UpdatePendulum, % 1000*dt
dt *= timescale
return

UpdatePendulum:
;Update physics
acceleration := gravity / length * sin(angle)
velocity += acceleration * dt
angle += velocity * dt
ballx := width//2 + sin(angle)*length
bally := height//2 + cos(angle)*length

;Draw line first, then the ball on top
DllCall("MoveToEx", "ptr", mdc, "int", width//2, "int", height//2, "ptr", 0)
DllCall("LineTo", "ptr", mdc, "int", ballx, "int", bally)
;Draw the memory bitmap onto the window
DllCall("BitBlt", "ptr", hdc, "int", 0, "int", 0, "int", width, "int", height, "ptr", mdc, "int", 0, "int", 0, "uint", 0xCC0020)

;Clear the memory bitmap with the back color
DllCall("SelectObject", "ptr", mdc, "ptr", BackBrush)
DllCall("Rectangle", "ptr", mdc, "int", 0, "int", 0, "int", width, "int", height)

;Put the ball brush back
DllCall("SelectObject", "ptr", mdc, "ptr", BallBrush)
return

GuiClose:
;Cleanup
DllCall("SelectObject", "ptr", mdc, "ptr", defaultBitmap)
DllCall("SelectObject", "ptr", mdc, "ptr", defaultBrush)
DllCall("SelectObject", "ptr", mdc, "ptr", defaultPen)
DllCall("DeleteObject", "ptr", hbm)
DllCall("DeleteObject", "ptr", BallBrush)
DllCall("DeleteObject", "ptr", LinePen)
DllCall("DeleteObject", "ptr", BackBrush)
DllCall("ReleaseDC", "ptr", DrawSurface, "ptr", hdc)
DllCall("DeleteDC", "ptr", mdc)
ExitApp
return``````

### Re: Rosetta Code

Posted: 15 Jan 2014, 19:31
nice!

### Re: Rosetta Code

Posted: 15 Jan 2014, 22:15

### Re: Rosetta Code

Posted: 15 Jan 2014, 22:59
http://rosettacode.org/wiki/Terminal_co ... AutoHotkey

### Re: Rosetta Code

Posted: 16 Jan 2014, 00:59
@joedf Sweet!

Note: I just added a basic version, so consider it a placeholder until someone writes a more advanced one.

Edited: Palindrome detection
Removed message saying the solution was incorrect and removed "canonicalization" from the function. So it is no longer an AutoHotkey example needing attention.

### Re: Rosetta Code

Posted: 16 Jan 2014, 03:03
Nice word-wrap you too
updated Palindrome detection - Now supports "Inexact" palindromes
http://rosettacode.org/wiki/Palindrome_ ... AutoHotkey

### Re: Rosetta Code

Posted: 16 Jan 2014, 04:12

### Re: Rosetta Code

Posted: 16 Jan 2014, 05:26

### Re: Rosetta Code

Posted: 16 Jan 2014, 05:44

### Re: Rosetta Code

Posted: 16 Jan 2014, 06:59

### Re: Rosetta Code

Posted: 16 Jan 2014, 07:23

### Re: Rosetta Code

Posted: 16 Jan 2014, 08:01

### Re: Rosetta Code

Posted: 16 Jan 2014, 08:36
added Write language name in 3D ASCII
http://rosettacode.org/wiki/Write_langu ... AutoHotkey

### Re: Rosetta Code

Posted: 17 Jan 2014, 05:10
@people_who_have_a_rpsetta_account:

Wouldn't it make sense to update the AutoHotkey-Category page with following:
• Remove obsolete link to autohokey.net
• Remove obsolete link to old wiki (replace by new one?)
• Promote new forum/website ahkscript.org instead of autohotkey.com
I don't have an rosetta-account, so I can't edit the corresponding page ...