﻿#AutoIt3Wrapper_Run_Au3Check=n
; Jos didn't fix this yet. UTF8BOM scripts don't work with UDFs, even
; ASCII ones.
#include "StringAPL.au3"

$hGUI = GUICreate("StringAPL Examples")
GUICtrlCreateLabel("Example 1: Draw a Mandelbrot", 5, 5, 193, 15, 1)
GUICtrlSetBkColor(-1, 0x505050)
GUICtrlSetColor(-1, 0xFFFFEE)
GUICtrlCreateLabel("Example 2: Multiplication Table", 202, 5, 193, 15, 1)
GUICtrlSetBkColor(-1, 0x505050)
GUICtrlSetColor(-1, 0xFFFFEE)
GUICtrlCreateLabel("Example 4: Rule 30", 202, 140, 193, 15, 1)
GUICtrlSetBkColor(-1, 0x505050)
GUICtrlSetColor(-1, 0xFFFFEE)
GUICtrlCreateLabel("Example 3: Draw Sierpinski's triangle", 5, 140, 193, 15, 1)
GUICtrlSetBkColor(-1, 0x505050)
GUICtrlSetColor(-1, 0xFFFFEE)
$hGraphics = GUICtrlCreateGraphic(0, 0) ; Those coordinates are completely irrelevant
GUICtrlSetGraphic($hGraphics, 8, 0xFF0000)
GUICtrlSetGraphic($hGraphics, 10, 5, 25, 193, 110)
GUICtrlSetGraphic($hGraphics, 10, 5, 160, 193, 193)
GUICtrlSetGraphic($hGraphics, 10, 202, 25, 193, 110)
GUICtrlSetGraphic($hGraphics, 10, 202, 160, 193, 193)

; Mandelbrot
$iTimer = TimerInit()
$aMandel = StringSplit(StringAPL("' #'[9>|⊃{⍺+⍵*2}/9⍴⊂¯3×.7j.5-⍉a∘.+0j1×a←(⍳n+1)÷n←98]", "{rm el}"), @CRLF, 3)
ConsoleWrite("-> Mandelbrot: " & Round(TimerDiff($iTimer),2) & "ms" & @LF)
For $i = 0 To UBound($aMandel)-1
	For $n = 1 To 100
		If StringMid($aMandel[$i], $n, 1) = "#" Then
			GUICtrlSetGraphic($hGraphics, 18, $n + 45, $i + 30)
		EndIf
	Next
Next

; Multiplication table
$iTimer = TimerInit()
GUICtrlCreateLabel(StringAPL("(⍳ 8) ∘.× ⍳ 12"), 215, 32, 170, 100)
ConsoleWrite("-> Multi Table: " & Round(TimerDiff($iTimer),2) & "ms" & @LF)
GUICtrlSetFont(-1, 8, -1, -1, "Consolas")

; Sierpinski's triangle
$iTimer = TimerInit()
$aSier = StringSplit(StringAPL("f ← {(⍵,(⍴⍵)⍴0)⍪⍵,⍵}\.\S ← {' #'[(f⍣⍵) 1 1 ⍴ 1]}\.\S 5"), @CRLF, 3)
ConsoleWrite("-> Sierpinski: " & Round(TimerDiff($iTimer),2) & "ms" & @LF)
ConsoleWrite($aSier)
For $i = 0 To UBound($aSier)-1
	For $n = 1 To 33
		If StringMid($aSier[$i], $n, 1) = "#" Then
			GUICtrlSetGraphic($hGraphics, 12, $n*4 + 35, $i*4 + 190, 4, 4)
		EndIf
	Next
Next

; Prime numbers
$iTimer = TimerInit()
GUICtrlCreateLabel("Primes 0 < n < 175:" & @CRLF & StringAPL("(1=+⌿0=A∘.∣A)/A←2↓⍳175"), 5, 360, 390, 40)
ConsoleWrite("-> Primes: " & Round(TimerDiff($iTimer),2) & "ms" & @LF)
GUICtrlSetFont(-1, -1, -1, -1, "Consolas")

; Rule 30
$iTimer = TimerInit()
$aSolution = StringSplit(StringAPL("rule←30\.\n←75\.\t←⌽rule⊤⍨8⍴2\.\' #'[⊃⌽{⍵,⍨⊂t[2⊥¨3,/0,0,⍨↑⍵]}⍣n⊂z,1,z←n⍴0]"), @CRLF, 3)
ConsoleWrite("-> Rule 30: " & Round(TimerDiff($iTimer),2) & "ms" & @LF)
For $i = 0 To UBound($aSolution)-1
	For $n = 1 To StringLen($aSolution[$i])
		If StringMid($aSolution[$i], $n, 1) = "#" Then
			GUICtrlSetGraphic($hGraphics, 18, $n + 220, $i*2 + 180)
		EndIf
	Next
Next

GUICtrlSetGraphic($hGraphics, 22)
GUISetState()


While GUIGetMsg()<>-3
WEnd