Andy: hehe
Der Erste Schritt in FreeBasic ist getan
Vermutlich extrem verbesserungsbedürftig, aber es funktioniert.
(ASM um in die Bitmap zu schreiben in einer Schleife = Armutszeugnis )
Spoiler anzeigen
Function Sign(a As Integer) As Integer
If a < 0 Then
Return -1
EndIf
If a = 0 Then
Return 0
EndIf
Return 1
End Function
Type vStruct
x As Double
y As Double
xx As Double
yy As Double
End Type
Extern "Windows-MS"
Sub Hopalong(a As Double, b As Double, c As Double, n As Integer, pBitmap As Integer, iW As Integer, iH As Integer, s As Integer, vStr As vStruct Ptr) Export
Dim As Double x = vStr->x, y = vStr->y, xx = vStr->xx, yy = vStr->yy
Dim as Integer iCol = 0, iPos = 0, iPx = iW*iH-4
pBitmap -= 4
For i As Integer = n To n+s Step 1
xx = y - Sign(x) * (Abs(b*x-c))^0.5
yy = a - x
x = xx
y = yy
iCol = 255*i
If x+iW/2 >= iW Then Continue For
If y+iH/2 >= iH Then Continue For
If x+iW/2 < 0 Then Continue For
If y+iH/2 < 0 Then Continue For
iPos = pBitmap + (Int(x+iW/2))*4 + (Int(y+iH/2))*iW*4
Asm
mov eax, [iPos]
mov ebx, [iCol]
mov dword[eax], ebx
End Asm
Next
'vStr->x = x
'vStr->y = y
'vStr->xx = xx
'vStr->yy = yy
End Sub
End Extern
Alles anzeigen
; Hopalong Fraktal
[/autoit] [autoit][/autoit] [autoit]#include <WinAPI.au3>
#include <Misc.au3>
#include <Array.au3>
Opt('GUIOnEventMode', 1)
[/autoit] [autoit][/autoit] [autoit]; Einstellungen:
Global $a = Round(Random(-10, 10),2)
Global $b = Round(Random(-10, 10),2)
Global $c = Round(Random(-10, 10),2)
; Weiteres
Global $n = 1250000
Global $s = 20000
Global Const $iW = 512
Global Const $iH = 512
; Globale Variablen
Global $hGUI, $hDC_GUI, $vIMG, $hDLL_GDI32, $hDLL_MARS, $hDC_BUF, $vSTR, $aSLI[4], $hLAB, $hBTN[3]
; Programmstart
$hDLL_GDI32 = DllOpen('GDI32.dll')
$hDLL_MARS = DllOpen('MARS.dll')
$hGUI = GUICreate('Hopalong Fraktal', $iW + 185, $iH)
$hDC_GUI = _WinAPI_GetDC($hGUI)
$vIMG = _Image_Create($iW, $iH)
$hDC_BUF = DllStructGetData($vIMG, 1, 1)
$vSTR = DllStructCreate('double x; double y; double xx; double yy')
GUICtrlCreateLabel('a b c n', $iW + 25, 5)
$hLAB = GUICtrlCreateLabel('a = ' & $a & @CRLF & 'b = ' & $b & @CRLF &'c = ' & $c & @CRLF &'n = ' & $n, $iW + 15, 275, 120, 75)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial', 5)
$hBTN[0] = GUICtrlCreateButton('Zufall', $iW + 15, 360, 155, 30)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial', 5)
GUICtrlSetOnEvent(-1, 'Event')
For $i = 0 To 3 Step 1
$aSLI[$i] = GUICtrlCreateSlider($iW + 20+ 40*$i, 20, 40, 250, 2+0x10)
GUICtrlSetLimit(-1, 1000, -1000)
GUICtrlSetOnEvent(-1, 'Event')
Next
GUICtrlSetLimit(-1, 500, 1)
_SetRnd()
GUISetOnEvent(-3, '_Exit', $hGUI)
GUIRegisterMsg(0xF, 'WM_PAINT')
OnAutoItExitRegister('_Freigeben')
GUISetState(@SW_SHOW, $hGUI)
_Draw()
[/autoit] [autoit][/autoit] [autoit]While Sleep(1000)
WEnd
Func Event()
Switch @GUI_CtrlId
Case $hBTN[0]
_SetRnd()
EndSwitch
_Draw()
EndFunc
Func _SetRnd()
GUICtrlSetData($aSLI[0], Round(Random(-10, 10),2)*100)
GUICtrlSetData($aSLI[1], Round(Random(-10, 10),2)*100)
GUICtrlSetData($aSLI[2], Round(Random(-10, 10),2)*100)
GUICtrlSetData($aSLI[3], Random(1,500,1))
EndFunc
Func _Draw()
$a = GUICtrlRead($aSLI[0])/100
$b = GUICtrlRead($aSLI[1])/100
$c = GUICtrlRead($aSLI[2])/100
$n = GUICtrlRead($aSLI[3])*2500
GUICtrlSetData($hLAB, 'a = ' & $a & @CRLF & 'b = ' & $b & @CRLF &'c = ' & $c & @CRLF &'n = ' & $n)
_WinAPI_BitBlt($hDC_BUF, 0, 0, $iW, $iH, 0, 0, 0, 0x42)
DllCall($hDLL_MARS, 'none', 'Hopalong', 'double', $a, 'double', $b, 'double', $c, 'int', 0, 'int', DllStructGetData($vIMG, 1, 4), 'int', $iW, 'int', $iH, 'int', $n, 'ptr', DllStructGetPtr($vSTR))
WM_PAINT()
EndFunc
Func _Freigeben()
_WinAPI_ReleaseDC($hGUI, $hDC_GUI)
_Image_Delete($vIMG)
DllClose($hDLL_GDI32)
DllClose($hDLL_MARS)
EndFunc ;==>_Freigeben
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _FPS($s)
Static $z = TimerInit(), $y
Local $x = TimerDiff($z), $w = (1000 / $s - $x)
$y += $w
If $y < 0 Then $y = 0
If $w < 0 Then $w = 0
Sleep(Int($y / 10) * 10)
$y -= Int($y / 10) * 10
$z = TimerInit()
Return $x / ($x + $w)
EndFunc ;==>_FPS
Func WM_PAINT()
Local Static $iFPS, $iFPS_Timer = TimerInit()
If TimerDiff($iFPS_Timer) > 1000 Then
WinSetTitle($hGUI, '', 'Lava-Fraktal: ' & $iFPS & ' FPS')
$iFPS = 0
$iFPS_Timer = TimerInit()
EndIf
_WinAPI_BitBlt($hDC_GUI, 0, 0, $iW, $iH, $hDC_BUF, 0, 0, 0xCC0020)
$iFPS += 1
EndFunc ;==>WM_PAINT
Func _Image_Create($iW, $iH)
Local $Ptr, $hDC, $hBmp, $tBMI, $aDIB, $vStruct
$hDC = _WinAPI_CreateCompatibleDC(0)
$tBMI = DllStructCreate($tagBITMAPINFO)
DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
DllStructSetData($tBMI, "Width", $iW)
DllStructSetData($tBMI, "Height", -$iH)
DllStructSetData($tBMI, "Planes", 1)
DllStructSetData($tBMI, "BitCount", 32)
$aDIB = DllCall($hDLL_GDI32, 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0)
$hBmp = $aDIB[0]
$Ptr = $aDIB[4]
_WinAPI_SelectObject($hDC, $hBmp)
$vStruct = DllStructCreate('int[5]')
DllStructSetData($vStruct, 1, $hDC, 1)
DllStructSetData($vStruct, 1, $iW, 2)
DllStructSetData($vStruct, 1, $iH, 3)
DllStructSetData($vStruct, 1, $Ptr, 4)
DllStructSetData($vStruct, 1, $hBmp, 5)
Return $vStruct
EndFunc ;==>_Image_Create
Func _Image_Delete(ByRef $vStruct)
_WinAPI_DeleteObject(DllStructGetData($vStruct, 1, 5))
_WinAPI_DeleteDC(DllStructGetData($vStruct, 1, 1))
$vStruct = 0
EndFunc ;==>_Image_Delete
Bei mir wird die dll leider als Virus "erkannt" (Antivir). Hab deshalb das Virenprogramm abgeschaltet, um nicht andauernd genervt zu werden.
.
.