Aaaah
jetzt hab ichs gerafft^^
Ich hab gedacht man muss eine Funktion finden die anhand der Position des Pixels iwie "Automatisch" etwas sinnvolles reinbaut. (also ohne vorher iwie den Abstand zum Mittelpunkt zu berechnen oder irgendwelche Winkel)
Mein erstes gutes Resultat !
Spoiler anzeigen
#include <Misc.au3>
#include <WinAPIEX.au3>
#include <GDIPlus.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global Const $Size = 600
Global Const $Breite = $Size
Global Const $Hoehe = $Size
Global Const $Titel = 'Mustergenerator...'
Global Const $WS_EX_LAYERED = 0x00080000
Global Const $WS_POPUP = 0x80000000
Global Const $SRCCOPY = 0x00CC0020
Global Const $BLACKNESS = 0x00000042
Global Const $h_NTDLL_DLL = DllOpen('ntdll.dll')
Global Const $h_MSIMG32_DLL = DllOpen('msimg32.dll')
Global Const $gdi32 = DllOpen('gdi32.dll')
Global Const $Stretch = 1
Global Const $WM_NCHITTEST = 0x0084
Global Const $HTCAPTION = 2
Global $hGUI = GUICreate($Titel, $Breite * $Stretch, $Hoehe * $Stretch, _C($Breite * $Stretch, 1), _C($Hoehe * $Stretch, 0), $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0x000000, $hGUI)
WinSetTrans($hGUI, '', 255)
GUISetOnEvent(-3, '_Exit', $hGUI)
GUISetState(@SW_SHOW, $hGUI)
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]Global $hDC_GUI = _WinAPI_GetDC($hGUI)
Global $ptr_Backbuffer, $hbmp_Backbuffer
Global $hDC_Backbuffer = _CreateNewBmp32($Breite, $Hoehe, $ptr_Backbuffer, $hbmp_Backbuffer)
Global $DLL_Struct = DllStructCreate('int[' & $Breite * $Hoehe & ']', $ptr_Backbuffer)
Global $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_GUI)
Global $Frame, $Struct, $ptr, $hbmp
Global $Counter = 0
Global $Mode = 0 ;0 = NeuesBild, 1=PerlinNoise
Global $Neu = True
OnAutoItExitRegister('_Exit')
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
Switch $Mode
Case 0
_NeuesBild()
Case 1
Local $a = _PerlinNoise($Breite, $Hoehe, 15, 0.9, Random(1, 5000))
$Frame = $a[0]
$ptr = $a[2]
$hbmp = $a[1]
EndSwitch
While Sleep(20)
_Winapi_StretchBlt($hDC_GUI, 0, 0, $Breite * $Stretch, $Hoehe * $Stretch, $Frame, 0, 0, $Breite, $Hoehe, $SRCCOPY)
If _IsPressed('20') Then _Neu()
If _IsPressed('53') Then _Save()
WEnd
Func _Neu()
Switch $Mode
Case 0
_NeuesBild()
Case 1
_Delete_Bitmap32($Frame, $hbmp)
Local $a = _PerlinNoise($Breite, $Hoehe, 15, 0.9, Random(1, 5000))
$Frame = $a[0]
$ptr = $a[2]
$hbmp = $a[1]
EndSwitch
EndFunc ;==>_Neu
;##########################HIER EIGENE FORMELN EINBAUEN############################################
; r = Rotanteil
; g = Grünanteil
; b = Blauanteil
; Es muss das Hex-Format verwendet werden. Hex(blabla, 2)
Func _Funktion($x, $y, ByRef $r1, ByRef $g1, ByRef $b1)
Local $col, $r, $g, $b, $AbstandMitte, $atx, $aty, $atx2, $aty2
[/autoit] [autoit][/autoit] [autoit]Local Static $Counter = 0
$Counter += 1
If $Neu Then
$Neu = False
$Counter = 0
EndIf
$AbstandMitte = (($y - $Hoehe/2)^2 + ($Breite/2 - $x)^2)^0.5
$atx = ATan2($x, $AbstandMitte)
$aty = ATan2($y, $AbstandMitte)
$atx2 = ATan2($Breite - $x, $AbstandMitte)
$aty2 = ATan2($Hoehe - $y, $AbstandMitte)
;~ $r = Hex($AbstandMitte + Random(0, 4, 1) ,2)
;~ $g = Hex(Sin($AbstandMitte/50) * 200 + Random(0, 4, 1) , 2)
;~ $b = Hex(Cos($AbstandMitte/20)*200 , 2)
$r += Hex(Tan($atx*5 + 2)*60, 2)
$g += Hex(Tan($atx*5 - 2)*60, 2)
$b += Hex(Tan($atx*5)*60, 2)
$r += Hex(Tan($atx2*5 + 2)*60, 2)
$g += Hex(Tan($atx2*5 - 2)*60, 2)
$b += Hex(Tan($atx2*5)*60, 2)
$r += Hex(Tan($aty*5 + 2)*60, 2)
$g += Hex(Tan($aty*5 - 2)*60, 2)
$b += Hex(Tan($aty*5)*60, 2)
$r += Hex(Tan($aty2*5 + 2)*60, 2)
$g += Hex(Tan($aty2*5 - 2)*60, 2)
$b += Hex(Tan($aty2*5)*60, 2)
If $col Then Return $col
[/autoit] [autoit][/autoit] [autoit]$r1 = Hex($r, 2)
$g1 = Hex($g, 2)
$b1 = Hex($b, 2)
Return 0
EndFunc ;==>_Funktion
;###################################################################################################
Func _F($x)
Return ($x ^ 2 + 5) ^ 0.5
EndFunc ;==>_F
Func _Kleeblatt($x, $y)
Local $w = $Breite, $h = $Hoehe, $r, $g, $b, $p, $col, $l
$r = Sqrt((($w / 2) - $x) ^ 2 + (($h / 2) - $y) ^ 2) / 150
$p = atan2(($w / 2) - $x, ($h / 2) - $y)
$l = $r / (((1 + Cos(4 * $p)) ^ 0.125) - (1 / 40 * (1 + Cos(8 * $p)) ^ 2))
$col = Int(1 / 4 * (1 - $l) ^ 0.125 * (1 + $l ^ 16) * (1 + 3 * $r) * 256) * 256
Return $col
EndFunc ;==>_Kleeblatt
Func ATan2($y, $x)
return (2 * ATan($y / ($x + Sqrt($x * $x + $y * $y))))
EndFunc ;==>ATan2
Func _Min($a, $b)
If $a > $b Then Return $b
Return $a
EndFunc ;==>_Min
Func Log2($x)
Return Log($x) / Log(2) ;10 is the base
EndFunc ;==>Log2
Func _Bet($a)
If $a > 0 Then Return $a
Return -$a
EndFunc ;==>_Bet
Func _Zufall(ByRef $Zufallszahl)
Local Const $a = 7141
Local Const $b = 54773
Local Const $c = 259200
$Zufallszahl = Mod(($a * $Zufallszahl + $b), $c)
If $Zufallszahl < $c / 2 Then
Return 1
Else
Return 0
EndIf
EndFunc ;==>_Zufall
Func _PerlinNoise($b, $h, $Tiefe = 5, $Helligkeit = 1, $Nummer = 1)
If $Tiefe < 1 Then $Tiefe = 1
If Int(Log2(_Min($b, $h))) - 1 <= Int($Tiefe) Then $Tiefe = Int(Log2(_Min($b, $h))) - 2 ;Überprüfung ob die Tiefe möglich ist bei der angegebenen Auflösung
[/autoit] [autoit][/autoit] [autoit]_Winapi_StretchBlt($hDC_Backbuffer, 0, 0, $Breite * $Stretch, $Hoehe * $Stretch, $Frame, 0, 0, $Breite, $Hoehe, $SRCCOPY)
Local $bmp = _GDIPlus_BitmapCreateFromGraphics($b, $h, $hGraphics)
Local $hBu = _GDIPlus_ImageGetGraphicsContext($bmp)
Local $pxGes = 0, $col, $Prozent, $px = 0
For $p = 0 To $Tiefe Step 1 ;p = BildNummern
For $x = 0 To $b / 2 ^ ($Tiefe - $p) Step 1
For $y = 0 To $h / 2 ^ ($Tiefe - $p) Step 1
$pxGes += 1
Next
Next
Next
Local $bmp2 = _GDIPlus_BitmapCloneArea($bmp, 0, 0, $b, $h)
Local $bbuffer = _GDIPlus_ImageGetGraphicsContext($bmp2)
Local $hBuffer = _GDIPlus_GraphicsCreateFromHDC($hDC_Backbuffer)
Local $hPen = _GDIPlus_PenCreate(0xFFFFFFFF)
Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
Local $Erhellen = 1, $Verdunkeln = 1
$Helligkeit = _Bet($Helligkeit)
While $Helligkeit > 2
$Helligkeit -= 1
WEnd
If $Helligkeit < 1 Then
$Verdunkeln = $Helligkeit
$Erhellen = 1
;~ ToolTip('Dunkel: ' & $Verdunkeln)
Else
$Erhellen = 1 - ($Helligkeit - 1)
$Verdunkeln = 1
;~ ToolTip('Hell: ' & $Erhellen)
EndIf
For $p = 0 To $Tiefe Step 1 ;p = BildNummern
For $x = 0 To $b / 2 ^ ($Tiefe - $p) Step 1
For $y = 0 To $h / 2 ^ ($Tiefe - $p) Step 1
$px += 1
Switch _Zufall($Nummer)
Case 0
$col = '0x' & Hex((255 / 2 ^ $p) * $Erhellen, 2) & '000000'
Case 1
$col = '0x' & Hex((255 / 2 ^ $p) * $Verdunkeln, 2) & 'FFFFFF'
EndSwitch
_pix($bmp, $x, $y, $col)
Next
$Prozent = $px / $pxGes
_GDIPlus_GraphicsDrawRect($hBuffer, 5, $Hoehe - 20, $Breite - 10, 15, $hPen)
_GDIPlus_GraphicsFillRect($hBuffer, 7, $Hoehe - 18, ($Breite - 13) * $Prozent, 12, $hBrush)
_Winapi_StretchBlt($hDC_GUI, 0, 0, $Breite * $Stretch, $Hoehe * $Stretch, $hDC_Backbuffer, 0, 0, $Breite, $Hoehe, $SRCCOPY)
Next
_GDIPlus_GraphicsDrawImageRectRect($bbuffer, $bmp, 0, 0, $b / 2 ^ ($Tiefe - $p), $h / 2 ^ ($Tiefe - $p), 0, 0, $b, $h)
Next
Global $_ptr, $_hbmp
Global $_hdc = _CreateNewBmp32($b, $h, $_ptr, $_hbmp)
Local $gra = _GDIPlus_GraphicsCreateFromHDC($_hdc)
_GDIPlus_GraphicsDrawImage($gra, $bmp2, 0, 0)
_GDIPlus_GraphicsDispose($gra)
_GDIPlus_GraphicsDispose($hBu)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_GraphicsDispose($bbuffer)
_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BitmapDispose($bmp)
_GDIPlus_BitmapDispose($bmp2)
Local $a[3] = [$_hdc, $_hbmp, $_ptr]
Return $a
EndFunc ;==>_PerlinNoise
Func _pix($hBitmap, $ix, $iy, $color)
DllCall($ghGDIPDll, "int", "GdipBitmapSetPixel", "hwnd", $hBitmap, "int", $ix, "int", $iy, "dword", $color)
EndFunc ;==>_pix
Func _NeuesBild()
[/autoit] [autoit][/autoit] [autoit];~ _GDIPlus_Startup()
_Winapi_StretchBlt($hDC_Backbuffer, 0, 0, $Breite * $Stretch, $Hoehe * $Stretch, $Frame, 0, 0, $Breite, $Hoehe, $SRCCOPY)
Local $hBuffer = _GDIPlus_GraphicsCreateFromHDC($hDC_Backbuffer)
Local $hPen = _GDIPlus_PenCreate(0xFFFFFFFF)
Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
Local $g = '88', $r = '34', $b = '99'
Local $Prozent = 0
Local $pxGes = $Hoehe * $Breite, $col
$Frame = _CreateNewBmp32($Breite, $Hoehe, $ptr, $hbmp)
$Struct = DllStructCreate('int[' & $Breite * $Hoehe & ']', $ptr)
;~ _Apfelm($Struct)
[/autoit] [autoit][/autoit] [autoit]For $i = 0 To $Hoehe Step 1
For $j = 0 To $Breite Step 1
$col = _Funktion($i, $j, $r, $g, $b)
If $col Then
DllStructSetData($Struct, 1, $col, $j * $Breite + $i + 1)
Else
DllStructSetData($Struct, 1, '0xFF' & $r & $g & $b, $j * $Breite + $i + 1)
EndIf
Next
$Prozent = ($i * $Hoehe + $j) / $pxGes
_GDIPlus_GraphicsDrawRect($hBuffer, 5, $Hoehe - 20, $Breite - 10, 15, $hPen)
_GDIPlus_GraphicsFillRect($hBuffer, 7, $Hoehe - 18, ($Breite - 13) * $Prozent, 12, $hBrush)
_Winapi_StretchBlt($hDC_GUI, 0, 0, $Breite * $Stretch, $Hoehe * $Stretch, $hDC_Backbuffer, 0, 0, $Breite, $Hoehe, $SRCCOPY)
Next
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($hBrush)
;~ _GDIPlus_Shutdown()
$Neu = True
Sleep(100)
EndFunc ;==>_NeuesBild
[/autoit] [autoit][/autoit] [autoit]Func _Save()
Local $Pfad = FileSaveDialog('BildSpeichern', @ScriptDir & '\Muster', '(*,.png)', Default, Hex(Random(256, 16 ^ 3, 1), 3) & '.png')
_GDIPlus_Startup()
Local $bm = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
_GDIPlus_ImageSaveToFile($bm, $Pfad)
_GDIPlus_BitmapDispose($bm)
_GDIPlus_Shutdown()
EndFunc ;==>_Save
Func _Exit()
ConsoleWrite('Blubb')
_WinAPI_ReleaseDC($hGUI, $hDC_GUI)
_GDIPlus_Shutdown()
_Delete_Bitmap32($hDC_Backbuffer, $hbmp_Backbuffer)
_Delete_Bitmap32($Frame, $hbmp)
DllClose($h_NTDLL_DLL)
DllClose($h_MSIMG32_DLL)
DllClose($gdi32)
Exit
EndFunc ;==>_Exit
Func _Delete_Bitmap32($hDC, $hbmp)
_WinAPI_DeleteObject($hbmp)
_WinAPI_ReleaseDC(0, $hDC)
EndFunc ;==>_Delete_Bitmap32
Func _CreateNewBmp32($iWidth, $iHeight, ByRef $ptr, ByRef $hbmp) ;erstellt leere 32-bit-Bitmap; Rückgabe DC und ptr und handle auf die Bitmapdaten
;by Andy
Local $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen
Local $tBMI = DllStructCreate($tagBITMAPINFO) ;Struktur der Bitmapinfo erstellen und Daten eintragen
DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4);Structgröße abzüglich der Daten für die Palette
DllStructSetData($tBMI, "Width", $iWidth)
DllStructSetData($tBMI, "Height", -$iHeight) ;minus =standard = bottomup
DllStructSetData($tBMI, "Planes", 1)
DllStructSetData($tBMI, "BitCount", 32) ;32 Bit = 4 Bytes => AABBGGRR
Local $adib = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', $DIB_RGB_COLORS, 'ptr*', 0, 'ptr', 0, 'uint', 0)
$hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden
$ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet
;_arraydisplay($adib)
_WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC
Return $hcdc ;DC der Bitmap zurückgeben
EndFunc ;==>_CreateNewBmp32
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
If ($hWnd = $hGUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc ;==>WM_NCHITTEST
Func _C($a, $b)
Switch $b
Case 0 ;Y
Return @DesktopHeight / 2 - $a / 2
Case 1 ;X
Return @DesktopWidth / 2 - $a / 2
EndSwitch
EndFunc ;==>_C
[Blockierte Grafik: http://img6.imagebanana.com/img/rjd361ve/4BD.png]