#Include <GDIPlus.au3>
#Include <GUIConstantsEx.au3>
#Include <Math.au3>
#Include <WinAPI.au3>
Global Const $Pi = 3.14159265358979
Dim $aPoints[100][2] = [[0.0, 0]]
For $i = 1 To 99
$aPoints[$i][0] = $aPoints[$i - 1][0] + 0.01
$aPoints[$i][1] = 0
Next
For $i = 1 To 100000
; $Val = Random(0, 1)
$Val = _GRandom(0, 1)
For $j = 0 To UBound($aPoints) - 1
If ($Val >= $aPoints[$j][0]) And ($Val <= $aPoints[$j][0] + 0.01) Then
$aPoints[$j][1] +=1
ExitLoop
EndIf
Next
Next
$Max = 0
For $i = 0 To UBound($aPoints) - 1
ConsoleWrite(StringFormat('%.2f', $aPoints[$i][0]) & ' ' & $aPoints[$i][1] & @CR)
If $Max < $aPoints[$i][1] Then
$Max = $aPoints[$i][1]
EndIf
Next
For $i = 0 To UBound($aPoints) - 1
$aPoints[$i][1] /= $Max
Next
_ViewGraph($aPoints)
Func _GRandom($Min, $Max)
Local $D = 2
Return (1 / ($D * Sqrt(2 * $Pi))) * Exp(-(Random($Min, $Max) - ($Min + $Max) / 2) ^ 2 / (2 * $D ^ 2))
EndFunc ;==>_GRandom
Func _ViewGraph($aPoints)
Local $hForm, $Pic, $hPic
Local $Scale, $Xi, $Yi, $Xp, $Yp, $XOffset, $YOffset, $Xmin = $aPoints[0][0], $Ymin = $aPoints[0][1], $Xmax = $Xmin, $Ymax = $Ymin
Local $hBitmap, $hObj, $hGraphic, $hImage, $hBrush, $hPen
For $i = 1 To UBound($aPoints) - 1
If $aPoints[$i][0] < $Xmin Then
$Xmin = $aPoints[$i][0]
Else
If $aPoints[$i][0] > $Xmax Then
$Xmax = $aPoints[$i][0]
EndIf
EndIf
If $aPoints[$i][1] < $Ymin Then
$Ymin = $aPoints[$i][1]
Else
If $aPoints[$i][1] > $Ymax Then
$Ymax = $aPoints[$i][1]
EndIf
EndIf
Next
$Scale = 560 / _Max($Xmax - $Xmin, $Ymax - $Ymin)
$XOffset = Floor(($Xmin + $Xmax) * $Scale / 2)
$YOffset = Floor(($Ymin + $Ymax) * $Scale / 2)
_GDIPlus_Startup()
$hBitmap = _WinAPI_CreateBitmap(601, 601, 1, 32)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
_WinAPI_DeleteObject($hBitmap)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$hPen = _GDIPlus_PenCreate(0xFFFF0000)
_GDIPlus_GraphicsFillRect($hGraphic, 0, 0, 601, 601, $hBrush)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
If Abs($XOffset) <= 300 Then
_GDIPlus_GraphicsDrawLine($hGraphic, 300 - $XOffset, 0, 300 - $XOffset, 601, $hPen)
EndIf
If Abs($YOffset) <= 300 Then
_GDIPlus_GraphicsDrawLine($hGraphic, 0, 300 + $YOffset, 601, 300 + $YOffset, $hPen)
EndIf
_GDIPlus_PenDispose($hPen)
$hPen = _GDIPlus_PenCreate(0xFF000000)
For $i = 0 To UBound($aPoints) - 1
$Xi = 300 - $XOffset + $Scale * $aPoints[$i][0]
$Yi = 300 + $YOffset - $Scale * $aPoints[$i][1]
If $i Then
_GDIPlus_GraphicsDrawLine($hGraphic, $Xp, $Yp, $Xi, $Yi, $hPen)
EndIf
$Xp = $Xi
$Yp = $Yi
Next
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_PenDispose($hPen)
_GDIPlus_Shutdown()
$hForm = GUICreate('My Graph', 601, 601)
$Pic = GUICtrlCreatePic('', 0, 0, 601, 601)
$hPic = GUICtrlGetHandle(-1)
_WinAPI_DeleteObject(_SendMessage($hPic, 0x0172, 0, $hBitmap))
$hObj = _SendMessage($hPic, 0x0173)
If $hObj <> $hBitmap Then
_WinAPI_DeleteObject($hBitmap)
EndIf
GUISetState(@SW_SHOW, $hForm)
Do
Until GUIGetMsg() = -3
GUIDelete($hForm)
EndFunc ;==>_ViewGraph