Jump to content

Some Graphical Examples using GDI+ Vol. I


UEZ
 Share

Recommended Posts

say that one saw this and thought it was pure asom, how would one make a screen saver?

*edit*

found a few threads about screensavers. here is what i have so far

this code has been updated in a later post

DEFINATLY not finished, but its a start.

any hints for a noob?

(thanks for the example, UEZ, i will be sure to add credits somewhere on there.........)

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Thank You and Nice effort UEZ,

But you need to destroy and recreate the pens and brushes each loop otherwise memory use will climb if your leaving your examples running for any great length of time.

eg: In the pearl necklace example move:

_GDIPlus_BrushDispose($Brush1)
_GDIPlus_BrushDispose($Brush2)oÝ÷ ÚÚ#ºËZ~׫¶¢¿Í{e¢eGºÚ"µÍÑÑT×ÑÜXÜÑ[[ÙJ ÌÍÔXÛPY ÌÍÞÛÛÜ    ÌÍÞXÛÛÜ   ÌÍÜÚ^HÈ    ÌÍÜÚ^HÈ    ÌÍÐÚBS^WÑÑT×ÐÚÜÜÙJ  ÌÍÐÚJHÉËKH]]BÑÑT×ÐÚÜÜÙJ   ÌÍÐÚHÉËKH]]BÑÑT×ÑÜXÜÑ]Ò[XYÙTXÝ
    ÌÍÑÜXË ÌÍÔXÛP]X    ÌÍÝÚY   ÌÍÚZYÚ
HØÛÜHÈ]XoÝ÷ Ù8b³²¶¦zj+ÊëÂ)e²+bvW¢Ë^iÚrX¦n)ඹ©eÉ8^±©¬~íë*¹ªÞ±ìZ^ÞjwZuÖ®¶­s`ôtDÇW5ô''W6F7÷6Rb33c¶''W6 ôtDÇW5õVäF7÷6Rb33cµVâ
after the For/Next loop to stop the escalating memory use.

Cheers

Link to comment
Share on other sites

say that one saw this and thought it was pure asom, how would one make a screen saver?

*edit*

found a few threads about screensavers. here is what i have so far

...

DEFINATLY not finished, but its a start.

any hints for a noob?

(thanks for the example, UEZ, i will be sure to add credits somewhere on there.........)

I had the same idea but it will be too slow on higher resolutions :)

By the way, look here to get more information about how to create ss! (dual monitor support, etc.) :o

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

Thank You and Nice effort UEZ,

But you need to destroy and recreate the pens and brushes each loop otherwise memory use will climb if your leaving your examples running for any great length of time.

eg: In the pearl necklace example move:

_GDIPlus_BrushDispose($Brush1)
_GDIPlus_BrushDispose($Brush2)oÝ÷ ÚÚ#ºËZ~׫¶¢¿Í{e¢eGºÚ"µÍÑÑT×ÑÜXÜÑ[[ÙJ ÌÍÔXÛPY ÌÍÞÛÛÜ    ÌÍÞXÛÛÜ   ÌÍÜÚ^HÈ    ÌÍÜÚ^HÈ    ÌÍÐÚB^ÑÑT×ÐÚÜÜÙJ    ÌÍÐÚJHÉËKH]]BÑÑT×ÐÚÜÜÙJ   ÌÍÐÚHÉËKH]]BÑÑT×ÑÜXÜÑ]Ò[XYÙTXÝ
    ÌÍÑÜXË ÌÍÔXÛP]X    ÌÍÝÚY   ÌÍÚZYÚ
HØÛÜHÈ]XoÝ÷ Ù8b³²¶¦zj+ÊëÂ)e²+bvW¢Ë^iÚrX¦n)ඹ©eÉ8^±©¬~íë*¹ªÞ±ìZ^ÞjwZuÖ®¶­sbôtDÇW5ô''W6F7÷6Rb33c¶''W6¢ôtDÇW5õVäF7÷6Rb33cµVâ
after the For/Next loop to stop the escalating memory use.

Cheers

Thanks for the hint. I updated both examples! :)

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

Thank You and Nice effort UEZ,

But you need to destroy and recreate the pens and brushes each loop otherwise memory use will climb if your leaving your examples running for any great length of time.

eg: In the pearl necklace example move:

_GDIPlus_BrushDispose($Brush1)
_GDIPlus_BrushDispose($Brush2)

after the For/Next loop to stop the escalating memory use.

Cheers

updated my script so if you left the screensaver on it would not lag.

@UEZ

say one wanted to make them spin too, how would one acomplish that task?

*EDIT*

updated the screen saver, deleated the old one from my last post. enjoy!

squaresaver.au3

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

updated my script so if you left the screensaver on it would not lag.

@UEZ

say one wanted to make them spin too, how would one acomplish that task?

*EDIT*

updated the screen saver, deleated the old one from my last post. enjoy!

Spin baby, spin.. buwahaha
;coded by UEZ 2008-01-06
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Global Const $Pi = 3.1415926535897932384626
Global Const $width = 400
Global Const $height = 400
Global $hGUI, $hWnd, $Graphic, $ParticleBitmap, $ParticleBuffer, $Brush1, $Brush2, $r = 0, $hMatrix
Global $starting_point, $i, $j, $k, $xcoord1, $ycoord1, $xcoord2, $ycoord2, $size, $red, $green, $blue

; Create GUI
$hGUI = GUICreate("GDI+: Flying Pearl Necklaces by UEZ 2009", $width, $height)
$hWnd = WinGetHandle($hGUI)
GUISetState()

_GDIPlus_Startup ()
$Graphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd) ;create graphic
$ParticleBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $Graphic) ;create bitmap
$ParticleBuffer = _GDIPlus_ImageGetGraphicsContext($ParticleBitmap) ;create buffer
AntiAlias($ParticleBuffer, 4)
_GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer

$hMatrix = _GDIPlus_MatrixCreate()
; Move the matrix half the width and helf the height towards the center
_GDIPlus_MatrixTranslate($hMatrix, 200, 200)

$i = -650
$starting_point = 0
; Loop until user exits
Do
    If $r >= 1 Then $r = 0
    _GDIPlus_MatrixRotate($hMatrix, $r)
    _GDIPlus_GraphicsSetTransform($ParticleBuffer, $hMatrix)
    
    $red = ((Sin(2^0 * $i / 2^5) + 1) / 2) * 256
    $green = ((Cos(2^0 * $i / 2^7) + 1) / 2) * 256
    $blue = ((-Sin(2^0 * $i / 2^9) + 1) / 2) * 256
    $Brush1 = _GDIPlus_BrushCreateSolid("0xEF" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2))
    $Brush2 = _GDIPlus_BrushCreateSolid("0xEF" & Hex($blue, 2) & Hex($red, 2) & Hex($green, 2))
    _GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer
    $k = 2^12
    $starting_point -= 0.05
    For $j = 1 To $k Step 32
        $size = $i - $j
        $xcoord1 = $width / 16 - (($i - $j) / 2) + Sin($starting_point) * -Sin(($i - $j) * $Pi / 90) * 64
        $ycoord1 = $height / 16 - (($i - $j) / 2) + -Cos($starting_point) * Cos(($i - $j) * $Pi / 90) * 32
        _GDIPlus_GraphicsFillEllipse($ParticleBuffer, $xcoord1, $ycoord1, $size / 6 , $size / 6, $Brush1)
        $xcoord2 = $width / 16 - (-($i - $j) / -1.75) - Sin($starting_point) * Sin(($i - $j) * $Pi / 120) * 32
        $ycoord2 = $height / 16 - (($i - $j) / -1.75) - Cos($starting_point) * Cos(($i - $j) * $Pi / 75) * 16
        _GDIPlus_GraphicsFillEllipse($ParticleBuffer, $xcoord2, $ycoord2, $size / 8 , $size / 8, $Brush2)

    Next
    _GDIPlus_BrushDispose($Brush1)
    _GDIPlus_BrushDispose($Brush2)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap
    $i += 3
    If $i > 4700 Then $i = -650
    $r += .005
    Sleep(20)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_GraphicsDispose ($Graphic)
_GDIPlus_BitmapDispose($ParticleBitmap)
_GDIPlus_GraphicsDispose($ParticleBuffer)
_GDIPlus_Shutdown ()


Func AntiAlias($Graphics, $iMode)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $Graphics, "int", $iMode)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_AntiAlias

Cheers

Edit: needs autoit v3.3

Edit: sped up the spin..

Edit: looks better at a bit slower spin, slowed the spin down..

Edited by smashly
Link to comment
Share on other sites

Spin baby, spin.. buwahaha

...

Cheers

Edit: needs autoit v3.3

Edit: sped up the spin..

Very nice smashly :)

If I find the time, I will do it on the squares, too -> _GDIPlus_GraphicsDrawRect() cannot be used anymore for rotation, need to use instead _GDIPlus_GraphicsDrawLine () :o

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

Does someone have like a guide to learning gdi+. I'm looking at these scripts and looking in the help file and I'm still drawing blanks (pun intended).

My resource is this forum, the help file and my imagination only :o

Currently, I'm working on a plasma effect but it is slow :)

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

If I find the time, I will do it on the squares, too -> _GDIPlus_GraphicsDrawRect() cannot be used anymore for rotation, need to use instead _GDIPlus_GraphicsDrawLine () :o

UEZ

Spin them squares man :)
;coded by UEZ 2008-01-08
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Global Const $Pi = 3.1415926535897932384626
Global Const $width = 400
Global Const $height = 400
Global $hGUI, $hWnd, $hGraphic, $ParticleBitmap, $ParticleBuffer, $hBrush0, $hBrush1, $Pen, $r = 0, $hMatrix
Global $starting_point, $i, $j, $k, $xcoord1, $ycoord1, $xcoord2, $ycoord2, $size, $red, $green, $blue, $start

; Create GUI
$hGUI = GUICreate("GDI+: Flying Squares by UEZ 2009", $width, $height)
$hWnd = WinGetHandle($hGUI)
GUISetState()

; Draw an ellipse
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd) ;create graphic
$ParticleBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap
$ParticleBuffer = _GDIPlus_ImageGetGraphicsContext($ParticleBitmap) ;create buffer
;~ $hBrush1 = _GDIPlus_BrushCreateSolid(0x7F777777) ; Unused brush?
AntiAlias($ParticleBuffer, 4)
_GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer

    $hMatrix = _GDIPlus_MatrixCreate()
;~ ; Move the matrix half the width and helf the height towards the center
    _GDIPlus_MatrixTranslate($hMatrix, 200, 200)

$start = -25
$i = $start
$starting_point = 0
; Loop until user exits
Do

    If $r >= 1 Then $r = 0
    _GDIPlus_MatrixRotate($hMatrix, $r)
    _GDIPlus_GraphicsSetTransform($ParticleBuffer, $hMatrix)
    
    $red = ((Sin(2^0 * $i / 2^5) + 1) / 2) * 256
    $green = ((Sin(2^0 * $i / 2^7) + 1) / 2) * 256
    $blue = ((Sin(2^0 * $i / 2^9) + 1) / 2) * 256
    $hBrush1 = _GDIPlus_BrushCreateSolid("0x0F" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2))
    $Pen = _GDIPlus_PenCreate("0xEF" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2), 1)
    _GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer
    $k = 2^9
    $starting_point -= 0.05
    For $j = 1 To $k Step 8
        $size = $i - $j
        $xcoord1 = $width / 16 - (($i - $j) / 2) + Sin($starting_point) * -Sin(($i - $j) * $Pi / 90) * 64
        $ycoord1 = $height / 16 - (($i - $j) / 2) + -Cos($starting_point) * Cos(($i - $j) * $Pi / 90) * 32
        $xcoord2 = $width / 16 - (-($i - $j) / 2) + Sin($starting_point) * -Sin(($i - $j) * $Pi / 90) * 64
        $ycoord2 = $height / 16 - (($i - $j) / 2) + -Cos($starting_point) * Cos(($i - $j) * $Pi / 90) * 32
        _GDIPlus_GraphicsDrawRect($ParticleBuffer, $xcoord1, $ycoord1, $size, $size, $Pen)
;~         ;_GDIPlus_GraphicsFillRect($ParticleBuffer, $xcoord1, $ycoord1, $size, $size, $hBrush1)
    Next
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_PenDispose($Pen)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap
    $i += 2
    If $i > $k + 2^9 Then $i = $start
    $r += .005
    Sleep(20)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_BitmapDispose($ParticleBitmap)
_GDIPlus_GraphicsDispose($ParticleBuffer)
_GDIPlus_Shutdown ()


Func AntiAlias($hGraphics, $iMode)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", $iMode)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_AntiAlias

Cheers

Edit: Requires AutoIt v3.3

Edited by smashly
Link to comment
Share on other sites

Spinning tunnel :)

;coded by UEZ 2008-01-08
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Global Const $Pi = 3.1415926535897932384626
Global Const $width = 400
Global Const $height = 400
Global $hGUI, $hWnd, $hGraphic, $ParticleBitmap, $ParticleBuffer, $hBrush0, $hBrush1, $Pen, $r = 0, $hMatrix
Global $starting_point, $i, $j, $k, $xcoord1, $ycoord1, $xcoord2, $ycoord2, $size, $red, $green, $blue, $start

; Create GUI
$hGUI = GUICreate("GDI+: Flying Squares by UEZ 2009", $width, $height)
$hWnd = WinGetHandle($hGUI)
GUISetState()

; Draw an ellipse
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd) ;create graphic
$ParticleBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap
$ParticleBuffer = _GDIPlus_ImageGetGraphicsContext($ParticleBitmap) ;create buffer
;~ $hBrush1 = _GDIPlus_BrushCreateSolid(0x7F777777) ; Unused brush?
AntiAlias($ParticleBuffer, 4)
_GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer

    $hMatrix = _GDIPlus_MatrixCreate()
;~ ; Move the matrix half the width and helf the height towards the center
    _GDIPlus_MatrixTranslate($hMatrix, 200, 200)

;~ $start = -25
$start = 500
$i = $start
$starting_point = 0
; Loop until user exits
Do

    If $r >= 1 Then $r = 0
    _GDIPlus_MatrixRotate($hMatrix, $r)
    _GDIPlus_GraphicsSetTransform($ParticleBuffer, $hMatrix)
   
    $red = ((Sin(2^0 * $i / 2^5) + 1) / 2) * 256
    $green = ((Sin(2^0 * $i / 2^7) + 1) / 2) * 256
    $blue = ((Sin(2^0 * $i / 2^9) + 1) / 2) * 256
    $hBrush1 = _GDIPlus_BrushCreateSolid("0x04" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2))
    $Pen = _GDIPlus_PenCreate("0xEF" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2), 1)
    _GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer
    $k = 2^9
    $starting_point -= 0.05
    
    For $j = 1 To $k Step 8
        $size = $i - $j
        $xcoord1 = $width / 16 - (($i - $j) / 2) + Sin($starting_point) * -Sin(($i - $j) * $Pi / 90) * 64
        $ycoord1 = $height / 16 - (($i - $j) / 2) + -Cos($starting_point) * Cos(($i - $j) * $Pi / 90) * 32
        $xcoord2 = $width / 16 - (-($i - $j) / 2) + Sin($starting_point) * -Sin(($i - $j) * $Pi / 90) * 64
        $ycoord2 = $height / 16 - (($i - $j) / 2) + -Cos($starting_point) * Cos(($i - $j) * $Pi / 90) * 32
        _GDIPlus_GraphicsDrawRect($ParticleBuffer, $xcoord1, $ycoord1, $size, $size, $Pen)
;~         _GDIPlus_GraphicsFillRect($ParticleBuffer, $xcoord1, $ycoord1, $size, $size, $hBrush1)
    Next
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_PenDispose($Pen)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap

    $i += 2
    If $i > 2^9 Then $i = $start
    $r += .005
    Sleep(20)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_BitmapDispose($ParticleBitmap)
_GDIPlus_GraphicsDispose($ParticleBuffer)
_GDIPlus_Shutdown ()


Func AntiAlias($hGraphics, $iMode)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", $iMode)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_AntiAlias

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

@ProgAndy and smashly: you used same technique :o Nice to now how to use the _GDIPlus_MatrixRotate() and _GDIPlus_GraphicsSetTransform() function.

I interpretated the spinning a litte bit different - each square should rotate by his own axis... Anyway learned again something new. THANKS.

I will try it with rotation of each square when I've time...

@youknowwho4eva: here you can learn best... :)

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

@ProgAndy and smashly: you used same technique :) Nice to now how to use the _GDIPlus_MatrixRotate() and _GDIPlus_GraphicsSetTransform() function.

I copied smashly's code and changed it a bit, so it must be the same :o

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Heh cool, _GDIPlus_MatrixTranslation and _GDIPlus_MatrixScale did get included in 3.3, it didn't appear in the change log so I thought Gary didn't have time to put it in :)

Anyways, good to now, now I don't have to copy and paste it around all the time :o

Great GDI+ stuff everyone, feel like doing some magic myself :D

Broken link? PM me and I'll send you the file!

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

×
×
  • Create New...