Page 1 of 11

Rosetta Code

Posted: 10 Jan 2014, 07:54
by jNizM
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

Re: Rosetta Code

Posted: 11 Jan 2014, 01:58
by joedf
nice :D

Re: Rosetta Code

Posted: 11 Jan 2014, 04:42
by kon

Re: Rosetta Code

Posted: 15 Jan 2014, 06:44
by Avi
@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
by joedf
Alright! I agree :D

Re: Rosetta Code

Posted: 15 Jan 2014, 13:58
by nnnik
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:

Re: Rosetta Code

Posted: 15 Jan 2014, 18:16
by LinearSpoon
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

Re: Rosetta Code

Posted: 15 Jan 2014, 19:31
by joedf
nice!

Re: Rosetta Code

Posted: 15 Jan 2014, 22:15
by joedf

Re: Rosetta Code

Posted: 15 Jan 2014, 22:59
by joedf
added Terminal control/Unicode output
http://rosettacode.org/wiki/Terminal_co ... AutoHotkey

Re: Rosetta Code

Posted: 16 Jan 2014, 00:59
by kon
@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.

Re: Rosetta Code

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

Re: Rosetta Code

Posted: 16 Jan 2014, 04:12
by joedf

Re: Rosetta Code

Posted: 16 Jan 2014, 05:26
by joedf

Re: Rosetta Code

Posted: 16 Jan 2014, 05:44
by joedf

Re: Rosetta Code

Posted: 16 Jan 2014, 06:59
by joedf

Re: Rosetta Code

Posted: 16 Jan 2014, 07:23
by joedf

Re: Rosetta Code

Posted: 16 Jan 2014, 08:01
by joedf

Re: Rosetta Code

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

Re: Rosetta Code

Posted: 17 Jan 2014, 05:10
by hoppfrosch
@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 ...