Jump to content

Genius Idea For a Script


 Share

Recommended Posts

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

longest way of doing it right... is changing the hex code's from 0x000000 to 0xffffff one pixel @ a time so 1st all the pixels will be 0x000000 then all will be 0x000000 accept the bottom right will be 0x000001 etc.

edit

ie. like a binary counter

Edited by ReaImDown
[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

I like the idea, so Ijustamde beginnning of script(working but takes time)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <String.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 242, 184, 193, 115)
$Graphic1 = GUICtrlCreateGraphic(0, 0, 1, 1)
GUICtrlSetColor(-1, 0x00FF00)
GUISetState(@SW_SHOW)
$y = 1
For $i = 1 To (100*100)
    If $i > 180 Then
        $y = $y +3
        $i = 1
    EndIf
$Graphic1 = GUICtrlCreateGraphic($i * 2, $y , 3, 3)
$c = hex( random(0,255,1)&random(0,255,1)&random(0,255,1),6)
;~ $c= Hex(255)
;~ MsgBox(1,1,"0x"&$c)
GUICtrlSetColor(-1, "0x"&$c)
Next    
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by E1M1

edited

Link to comment
Share on other sites

Sorry you all for bursting the clearly well-intentioned bubble, but this will never be a working plan. The idea of your friend was paradoxical because of a logical flaw (a flaw of limiting an infinite). Since the total number of images you will possibly be able to produce is <number of colors> ^ (<length> x <width>). Since that number is finite (albeit hardly-describably high), there will always be an image with more information than any of those that are possible in the grid. For instance: if you have had ALL possible images in a 32 bit colors 500x500 grid, you have still not gotten ANY of the infinite amount of images imaginable that need more than 500x500 resolution.

After a short calculation, it shows that if you take a monochrome color set (only two colors AT ALL) and you take only a 10x10 pixels grid... And you take a processing speed of 1 BILLION (1,000,000,000) images per second (remember, actually you would have to look at every image to interpret it! :D) ... It will still take you 40196936841331 years, which is roughly 2934 times the estimated age of the universe until now. (2 ^ 100 / 1,000,000,000 / 60 / 60 / 24 / 365 / 13,700,000,000 = about 2934. Counting leap days and such isn't really relevant any more for this calculation... :o)

[Theoretical Astronomics Mode] Better hope it turns out not to be a closed universe after all! :D [/Theoretical Astronomics Mode]

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Maybe it's just me but I'm always disappointed when I see a hard-coded implementation of Pi. I always use:

Global $Pi = ATan(1) * 4

WBD

Link to comment
Share on other sites

This is a faster way to generate a random pixel bitmap.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

HotKeySet(("^!p"), "SaveImage"); Ctrl+Alt+p  Save image o file

Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled
Global Const $ApW = Int(@DesktopWidth / 5) - Mod(Int(@DesktopWidth / 5), 8)
Global Const $ApH = Int(@DesktopHeight / 5) - Mod(Int(@DesktopHeight / 5), 8)
Global $hWnd, $hBitmap, $hImage, $hGraphic, $hBrush, $hBrush1, $hbmp, $aBmp
$hGui = GUICreate("Ctrl+Alt+p  To save image", $ApW + 40, $ApH + 40)
GUISetOnEvent(-3, "_Quit")
GUISetBkColor(0xff8080, $hGui)

$Pic = GUICtrlCreatePic("", 20, 20, $ApW, $ApH)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetState(-1, $GUI_DISABLE)

PicSetGraphics($Pic, $ApW, $ApH)

While 1
    Sleep(10)
WEnd

Func PicSetGraphics($cID, $iW, $iH)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    ;Local $hWnd, $hBitmap, $hImage, $hGraphic, $hBrush, $hBrush1, $hbmp, $aBmp
    $hWnd = GUICtrlGetHandle($cID)
    _GDIPlus_Startup()

    $hBitmap = _CreateRandomBitmap($hGui, $iW, $iH)

    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    GUISetState(@SW_SHOW, $hGui)

    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hbmp)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
EndFunc   ;==>PicSetGraphics

Func _Quit()
    If IsArray($aBmp) Then _WinAPI_DeleteObject($aBmp[0])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Quit

Func _CreateRandomBitmap($hWnd, $iWidth, $iHeight)
    Local $iI, $iSize, $tBits, $tBMI, $hDC, $hbmp, $iRow, $iW = 0, $iH = 0
    $iSize = $iWidth * $iHeight
    $tBits = DllStructCreate("int[" & $iSize & "]")
    For $iI = 1 To $iSize
        DllStructSetData($tBits, 1, "0x" & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2) & _
                Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2), $iI)
    Next
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)
    $hDC = _WinAPI_GetDC($hWnd)
    $hbmp = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SetDIBits(0, $hbmp, 0, $iHeight, DllStructGetPtr($tBits), DllStructGetPtr($tBMI))
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $hbmp
EndFunc   ;==>_CreateRandomBitmap

Func SaveImage()
    ; Save Graphics on picture control
    _GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "\TestWrite1.png")
    ShellExecute(@DesktopDir & "\TestWrite1.png")
EndFunc   ;==>SaveImage

Edit: Changed to $ApW = Int(@DesktopWidth / 5) - Mod(Int(@DesktopWidth / 5), 8) instead of plus.

$iSize needs to be divisible by 8.

Edited by Malkey
Link to comment
Share on other sites

Can I recommend a short story that readers of this topic will be hard pressed not to fall in love with. "The Library of Babel" by Argentine author Jorge Luis Borges.

From wiki.

Plot summary

Borges's narrator describes how his universe consists of an endless expanse of interlocking hexagonal rooms, each of which contains the bare necessities for human survivaland four walls of bookshelves. Though the order and content of the books is random and apparently completely meaningless, the inhabitants believe that the books contain every possible ordering of just a few basic characters (letters, spaces and punctuation marks). Though the majority of the books in this universe are pure gibberish, the library also must contain, somewhere, every coherent book ever written, or that might ever be written, and every possible permutation or slightly erroneous version of every one of those books. The narrator notes that the library must contain all useful information, including predictions of the future, biographies of any person, and translations of every book in all languages. Conversely, for many of the texts some language could be devised that would make it readable with any of a vast number of different contents.

Despite indeed, because of this glut of information, all books are totally useless to the reader, leaving the librarians in a state of suicidal despair. However, Borges speculates on the existence of the "Crimson Hexagon", containing a book that contains the log of all the other books; the librarian who reads it is akin to God.

Good luck watching the static, I shan't be bothering myself.

Link to comment
Share on other sites

thats awesome...

this is just a bit of fun, we've had some good discussion on the board if nothing else! (by the way how long did it take for you coding guys to knock up the code? also, what would the command to auto refresh every second or something be?)

Link to comment
Share on other sites

i was reading what WideboyDIxon said up above about Pi, and i was thinking, can you get the computer to display out Pi, and continuely caluclate it?

$pi = 4 * ATan(1)

;then

Echo ("$pi")

?

is echo even a command?

Edited by AJJ
Link to comment
Share on other sites

thats awesome...

this is just a bit of fun, we've had some good discussion on the board if nothing else! (by the way how long did it take for you coding guys to knock up the code? also, what would the command to auto refresh every second or something be?)

The refresh speed depends on your computer speed - the faster your pc is the faster is the update speed!

Here Malkey's code with update!

;coded by Malkey
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

HotKeySet(("^!p"), "SaveImage"); Ctrl+Alt+p  Save image o file

Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled
Global Const $ApW = Int(@DesktopWidth / 8) - Mod(Int(@DesktopWidth / 8), 8)
Global Const $ApH = Int(@DesktopHeight / 8) - Mod(Int(@DesktopHeight / 8), 8)
Global $hWnd, $hBitmap, $hImage, $hGraphic, $hBrush, $hBrush1, $hbmp, $aBmp
$hGui = GUICreate("Ctrl+Alt+p  To save image", $ApW + 40, $ApH + 40)
GUISetOnEvent(-3, "_Quit")
GUISetBkColor(0x000000, $hGui)

$Pic = GUICtrlCreatePic("", 20, 20, $ApW, $ApH)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetState(-1, $GUI_DISABLE)

Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0
$hWnd = GUICtrlGetHandle($Pic)
_GDIPlus_Startup()
PicSetGraphics($ApW, $ApH)
GUISetState(@SW_SHOW, $hGui)

    
While 1
    PicSetGraphics($ApW, $ApH)
    Sleep(10)
WEnd

Func PicSetGraphics($iW, $iH)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBitmap = _CreateRandomBitmap($hGui, $iW, $iH)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hbmp)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
EndFunc

Func _Quit()
    If IsArray($aBmp) Then _WinAPI_DeleteObject($aBmp[0])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Quit

Func _CreateRandomBitmap($hWnd, $iWidth, $iHeight)
    Local $iI, $iSize, $tBits, $tBMI, $hDC, $hbmp, $iRow, $iW = 0, $iH = 0
    $iSize = $iWidth * $iHeight
    $tBits = DllStructCreate("int[" & $iSize & "]")
    For $iI = 1 To $iSize
        DllStructSetData($tBits, 1, "0xFF" & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2), $iI)
    Next
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)
    $hDC = _WinAPI_GetDC($hWnd)
    $hbmp = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SetDIBits(0, $hbmp, 0, $iHeight, DllStructGetPtr($tBits), DllStructGetPtr($tBMI))
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $hbmp
EndFunc   ;==>_CreateRandomBitmap

Func SaveImage()
    ; Save Graphics on picture control
    _GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "\TestWrite1.png")
    ShellExecute(@DesktopDir & "\TestWrite1.png")
EndFunc   ;==>SaveImage

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

for just B&W image the following function

Func _CreateRandomBitmap($hWnd, $iWidth, $iHeight)
    Local $iI, $iSize, $tBits, $tBMI, $hDC, $hbmp, $iRow, $iW = 0, $iH = 0
    $iSize = $iWidth * $iHeight
    $tBits = DllStructCreate("int[" & $iSize & "]")
    For $iI = 1 To $iSize
        DllStructSetData($tBits, 1, "0x" & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2), $iI)
    Next
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)
    $hDC = _WinAPI_GetDC($hWnd)
    $hbmp = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SetDIBits(0, $hbmp, 0, $iHeight, DllStructGetPtr($tBits), DllStructGetPtr($tBMI))
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $hbmp
EndFunc   ;==>_CreateRandomBitmapoÝ÷ ÚÈhºW[yÈZ²¶§X¤zØb³²jëh×6Func _CreateRandomBitmap($hWnd, $iWidth, $iHeight)
    Local $iI, $iSize, $tBits, $tBMI, $hDC, $hbmp, $iRow, $iW = 0, $iH = 0, $ir
    $iSize = $iWidth * $iHeight
    $tBits = DllStructCreate("int[" & $iSize & "]")
    For $iI = 1 To $iSize
        $ir = Hex(Random(0, 1, 1) * 255, 2)
        DllStructSetData($tBits, 1, "0x" & $ir & $ir & $ir & $ir, $iI)
    Next
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)
    $hDC = _WinAPI_GetDC($hWnd)
    $hbmp = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SetDIBits(0, $hbmp, 0, $iHeight, DllStructGetPtr($tBits), DllStructGetPtr($tBMI))
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $hbmp
EndFunc   ;==>_CreateRandomBitmap
Edited by AntidotE
Link to comment
Share on other sites

Waaay too much code going on here. A far simpler way...

GUICreate("",300,300)
GUISetState()
While 1
    $Graphic = GUICtrlCreateGraphic(0,0,300,300)
    For $x = 1 to 300
        For $y = 1 to 300
            Switch Random(0,1,1)
                Case 0
                    GUICtrlSetGraphic($Graphic,8,0x000000)
                Case 1
                    GUICtrlSetGraphic($Graphic,8,0xFFFFFF)
            EndSwitch
            GUICtrlSetGraphic($Graphic,18,$x,$y)
        Next
    Next
    GUICtrlSetGraphic($Graphic,22)
    Sleep(1000)
    GUICtrlDelete($Graphic)
WEnd
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

This is a faster way to generate a random pixel bitmap.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

HotKeySet(("^!p"), "SaveImage"); Ctrl+Alt+p  Save image o file

Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled
Global Const $ApW = Int(@DesktopWidth / 5) - Mod(Int(@DesktopWidth / 5), 8)
Global Const $ApH = Int(@DesktopHeight / 5) - Mod(Int(@DesktopHeight / 5), 8)
Global $hWnd, $hBitmap, $hImage, $hGraphic, $hBrush, $hBrush1, $hbmp, $aBmp
$hGui = GUICreate("Ctrl+Alt+p  To save image", $ApW + 40, $ApH + 40)
GUISetOnEvent(-3, "_Quit")
GUISetBkColor(0xff8080, $hGui)

$Pic = GUICtrlCreatePic("", 20, 20, $ApW, $ApH)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetState(-1, $GUI_DISABLE)

PicSetGraphics($Pic, $ApW, $ApH)

While 1
    Sleep(10)
WEnd

Func PicSetGraphics($cID, $iW, $iH)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    ;Local $hWnd, $hBitmap, $hImage, $hGraphic, $hBrush, $hBrush1, $hbmp, $aBmp
    $hWnd = GUICtrlGetHandle($cID)
    _GDIPlus_Startup()

    $hBitmap = _CreateRandomBitmap($hGui, $iW, $iH)

    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    GUISetState(@SW_SHOW, $hGui)

    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hbmp)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
EndFunc   ;==>PicSetGraphics

Func _Quit()
    If IsArray($aBmp) Then _WinAPI_DeleteObject($aBmp[0])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Quit

Func _CreateRandomBitmap($hWnd, $iWidth, $iHeight)
    Local $iI, $iSize, $tBits, $tBMI, $hDC, $hbmp, $iRow, $iW = 0, $iH = 0
    $iSize = $iWidth * $iHeight
    $tBits = DllStructCreate("int[" & $iSize & "]")
    For $iI = 1 To $iSize
        DllStructSetData($tBits, 1, "0x" & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2) & _
                Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2), $iI)
    Next
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)
    $hDC = _WinAPI_GetDC($hWnd)
    $hbmp = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SetDIBits(0, $hbmp, 0, $iHeight, DllStructGetPtr($tBits), DllStructGetPtr($tBMI))
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $hbmp
EndFunc   ;==>_CreateRandomBitmap

Func SaveImage()
    ; Save Graphics on picture control
    _GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "\TestWrite1.png")
    ShellExecute(@DesktopDir & "\TestWrite1.png")
EndFunc   ;==>SaveImage

Edit: Changed to $ApW = Int(@DesktopWidth / 5) - Mod(Int(@DesktopWidth / 5), 8) instead of plus.

$iSize needs to be divisible by 8.

Your copy code is much faster - respect :D

But how can I adjust the size of the pixels? E.g. not 1x1 but 8x8!

Thanks,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Your copy code is much faster - respect ;)

But how can I adjust the size of the pixels? E.g. not 1x1 but 8x8!

Thanks,

UEZ

$iSize = $iWidth * $iHeight
    $tBits = DllStructCreate("int[" & $iSize & "]")
    For $iI = 1 To $iSize
        DllStructSetData($tBits, 1, "0x" & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2) & _
                Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2), $iI)
    Next
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)

In the bitmap info structure, $tBMI , the "BitCount" is 32. This defines the individual pixel data of length 32 bits, or, 4 bytes, or, an "int" data type length. (See data type "int" in DllStructCreate function help file)

In the script, the pixel data structure, $tBits, is int [Width x height] .So the Width x height number of individual pixel data of the bitmap are of length 32 bits or 4 bytes. This corresponds to the 32 bit, hex colour formats, 0xAABBGGRR, 0xAARRGGBB or 0xRRGGBBAA, having four colour channels.

Each colour channel is 1 byte or 8 bits in length. Normally, non - gdiplus wrappers use only the 24 bit 0xRRGGBB or 0xBBGGRR hex colour formats.

Alternatively, the pixel data structure, $tBits, can be of byte size, which contain all of the individual colour channels of all the pixels, byte[size * 4 ]. One byte or 8 bits per channel, four channels per pixel , gives 32 bit size pixels.

So, this also works.

$iSize = $iWidth * $iHeight
    $tBits = DllStructCreate("byte[" & $iSize * 4 & "]")
    For $iI = 1 To $iSize * 4
        DllStructSetData($tBits, 1, "0x" & Hex(Random(0, 255, 1), 2), $iI)
    Next
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)

I do like andybiochem's example. Simple is good.

Link to comment
Share on other sites

I have trouble understanding (in any of the examples) this part:

"0x" & Hex(Random...

That almost makes no sense :D

This code appears to be much faster (Malkey's modified):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

;HotKeySet(("^!p"), "SaveImage"); Ctrl+Alt+p  Save image o file

Opt("GUIOnEventMode", 1);0=disabled, 1=OnEvent mode enabled
Global Const $ApW = Int(@DesktopWidth / 8) - Mod(Int(@DesktopWidth / 8), 8)
Global Const $ApH = Int(@DesktopHeight / 8) - Mod(Int(@DesktopHeight / 8), 8)
Global $hWnd, $hBitmap, $hImage, $hGraphic, $hBrush, $hBrush1, $hbmp, $aBmp
$hGui = GUICreate("", $ApW + 40, $ApH + 40)
GUISetOnEvent(-3, "_Quit")
GUISetBkColor(0x000000, $hGui)

$Pic = GUICtrlCreatePic("", 20, 20, $ApW, $ApH)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetState(-1, $GUI_DISABLE)

Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0
$hWnd = GUICtrlGetHandle($Pic)


PicSetGraphics($ApW, $ApH)
GUISetState(@SW_SHOW, $hGui)


While 1
    PicSetGraphics($ApW, $ApH)
    Sleep(0)
WEnd

Func PicSetGraphics($iW, $iH)
;$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
;$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBitmap = _CreateRandomBitmap($hGui, $iW, $iH)
;$hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
;$aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hbmp)
    $iHBmp = GUICtrlSendMsg($Pic, $STM_SETIMAGE, 0, $hBitmap)
    _WinAPI_DeleteObject($iHBmp)
    _WinAPI_DeleteObject($hBitmap)
;_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
;_WinAPI_RedrawWindow($hGui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
EndFunc  ;==>PicSetGraphics

Func _Quit()
;...
    Exit
EndFunc  ;==>_Quit

Func _CreateRandomBitmap($hWnd, $iWidth, $iHeight)
    Local $iI, $iSize, $tBits, $tBMI, $hDC, $hbmp, $iRow, $iW = 0, $iH = 0
    $iSize = $iWidth * $iHeight
    $tBits = DllStructCreate("int[" & $iSize & "]")
    For $iI = 1 To $iSize
    ;DllStructSetData($tBits, 1, "0xFF" & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2), $iI)
        DllStructSetData($tBits, 1, Random(0, 0xFFFFFF, 1) + 0xFF000000, $iI)
    Next
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)
    $hDC = _WinAPI_GetDC($hWnd)
    $hbmp = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SetDIBits(0, $hbmp, 0, $iHeight, DllStructGetPtr($tBits), DllStructGetPtr($tBMI))
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $hbmp
EndFunc  ;==>_CreateRandomBitmap

Func SaveImage()
;GDI
    Return
EndFunc  ;==>SaveImage

Btw, no monkey lives forever.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I have trouble understanding (in any of the examples) this part:

"0x" & Hex(Random...

That almost makes no sense :D

This code appears to be much faster (Malkey's modified):

...

Btw, no monkey lives forever.

Well done trancexx! The code is now still faster.

Yes your are right - in this case to separate the alpha and color channels make no sense.

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

$iSize = $iWidth * $iHeight
     $tBits = DllStructCreate("int[" & $iSize & "]")
     For $iI = 1 To $iSize
         DllStructSetData($tBits, 1, "0x" & Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2) & _
                 Hex(Random(1, 255, 1), 2) & Hex(Random(1, 255, 1), 2), $iI)
     Next
     $tBMI = DllStructCreate($tagBITMAPINFO)
     DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
     DllStructSetData($tBMI, "Planes", 1)
     DllStructSetData($tBMI, "BitCount", 32)
     DllStructSetData($tBMI, "Width", $iWidth)
     DllStructSetData($tBMI, "Height", $iHeight)

In the bitmap info structure, $tBMI , the "BitCount" is 32. This defines the individual pixel data of length 32 bits, or, 4 bytes, or, an "int" data type length. (See data type "int" in DllStructCreate function help file)

In the script, the pixel data structure, $tBits, is int [Width x height] .So the Width x height number of individual pixel data of the bitmap are of length 32 bits or 4 bytes. This corresponds to the 32 bit, hex colour formats, 0xAABBGGRR, 0xAARRGGBB or 0xRRGGBBAA, having four colour channels.

Each colour channel is 1 byte or 8 bits in length. Normally, non - gdiplus wrappers use only the 24 bit 0xRRGGBB or 0xBBGGRR hex colour formats.

Alternatively, the pixel data structure, $tBits, can be of byte size, which contain all of the individual colour channels of all the pixels, byte[size * 4 ]. One byte or 8 bits per channel, four channels per pixel , gives 32 bit size pixels.

So, this also works.

$iSize = $iWidth * $iHeight
     $tBits = DllStructCreate("byte[" & $iSize * 4 & "]")
     For $iI = 1 To $iSize * 4
         DllStructSetData($tBits, 1, "0x" & Hex(Random(0, 255, 1), 2), $iI)
     Next
     $tBMI = DllStructCreate($tagBITMAPINFO)
     DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
     DllStructSetData($tBMI, "Planes", 1)
     DllStructSetData($tBMI, "BitCount", 32)
     DllStructSetData($tBMI, "Width", $iWidth)
     DllStructSetData($tBMI, "Height", $iHeight)

I do like andybiochem's example. Simple is good.

Thanks for your reply but why I asked this is that I used for the plasma effect nearly same idea and I thought I could use this technique to speed it up.

I think I cannot use it this way... :D

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

The thing with a random generator is the definition of random. that is that all the colous are equalu likely to be displayed in any pixel.

In scene random only makes sure you will NOT get any pattern! :D

The way to do it is like doing a bruteforce for cracking passwords: change one pixel at a time until all pixels go with all the combination possible. that is the fastest way to ensure all the combinations will be considered. Only reasonable way is Black and White otherwise it very improbable and requires improbability engine, may be even whole new computer in a form of a new planet :o

I think only almost reasonable acceptation is to see all B&W pictures of an ico for all future programs (assuming they will use 32x32px) :D

Edited by dexto
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...