Rosetta Code

Talk about anything
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Rosetta Code

10 Jan 2014, 07:54

Rosetta Code
Category: Programming Tasks
Category: Solutions by Programming Task

Tasks not implemented in AutoHotkey
AutoHotkey examples needing attention

Rank: 29. Jan 2017 (RC_POP.OUT)

Code: Select all

  1. Racket        932
....
 19. Ada           634
 20. AutoHotkey    611
 21. Common Lisp   609
....
132. AutoIt         91
===============================================

Added:
- MD4
- SHA-1
- SHA-256
- CRC32

Fixed:
- Leap Year

Improvement:
- SEDOL
Last edited by jNizM on 27 Aug 2014, 03:13, edited 30 times in total.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Rosetta Code

11 Jan 2014, 01:58

nice :D
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Rosetta Code

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.
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Rosetta Code

15 Jan 2014, 13:41

Alright! I agree :D
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Rosetta Code

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? :mrgreen:
Recommends AHK Studio
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: Rosetta Code

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
radius := 12             ;Ball radius in pixels
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)
  DllCall("Ellipse", "ptr", mdc, "int", ballx-radius, "int", bally-radius, "int", ballx+radius, "int", bally+radius)
  ;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
Last edited by LinearSpoon on 15 Jan 2014, 22:51, edited 1 time in total.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Rosetta Code

15 Jan 2014, 19:31

nice!
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Rosetta Code

16 Jan 2014, 00:59

@joedf Sweet! :D

Added: Word wrap
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.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Rosetta Code

16 Jan 2014, 03:03

Nice word-wrap you too :D
updated Palindrome detection - Now supports "Inexact" palindromes
http://rosettacode.org/wiki/Palindrome_ ... AutoHotkey
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Rosetta Code

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

Return to “Off-topic Discussion”

Who is online

Users browsing this forum: staletkzpb and 27 guests