Jump to content

Some Graphical Examples using GDI+ Vol. I


UEZ
 Share

Recommended Posts

@monoceres: thanks for feedback -> changed it to sleep(20)

Apropos sleep - it's a good idea now -> Goto Sleep(6h) :)

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

Nice effect. :)

Playing with transparency gives an interesting variation too:

;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
Global $starting_point, $i, $j, $k, $xcoord1, $ycoord1, $xcoord2, $ycoord2, $size, $red, $green, $blue, $trans1, $trans2

; Create GUI
$hGUI = GUICreate("GDI+: Flying Pearl Necklace 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

$i = -600
$starting_point = 0
; Loop until user exits
Do
    $red = ((Sin(2^0 * $i / 2^5) + 1) / 2) * 256
    $green = ((Cos(2^0 * $i / 2^7) + 1) / 2) * 256
    $blue = ((-ATan(2^0 * $i / 2^9) + 1) / 2) * 256
    $trans1 = Hex(Random(50, 95), 2)
    $trans2 = Hex(Random(50, 95), 2)
    $Brush1 = _GDIPlus_BrushCreateSolid("0x" & $trans1 & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2))
    $Brush2 = _GDIPlus_BrushCreateSolid("0x" & $trans2 & 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 / 2 - (($i - $j) / 2) + Sin($starting_point) * -Sin(($i - $j) * $Pi / 90) * 64
        $ycoord1 = $height / 2 - (($i - $j) / 2) + -Cos($starting_point) * Cos(($i - $j) * $Pi / 90) * 32
        _GDIPlus_GraphicsFillEllipse($ParticleBuffer, $xcoord1, $ycoord1, $size / 6 , $size / 6, $Brush1)
        $xcoord2 = $width / 2 - (-($i - $j) / -1.75) - Sin($starting_point) * Sin(($i - $j) * $Pi / 120) * 32
        $ycoord2 = $height / 2 - (($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_GraphicsDrawImageRect($Graphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap
    $i += 3
    Sleep(20)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_GraphicsDispose ($Graphic)
_GDIPlus_BitmapDispose($ParticleBitmap)
_GDIPlus_GraphicsDispose($ParticleBuffer)
_GDIPlus_BrushDispose($Brush1)
_GDIPlus_BrushDispose($Brush2)
_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
Link to comment
Share on other sites

Wow I really need to start learnin GDI+. I'm wondering, is there a way for this to run in the background and export the image as a jpeg?

Yes and very easy too.

Since UEZ is double buffering the with a standard bitmap you can replace the following line:

_GDIPlus_GraphicsDrawImageRect($Graphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap

with:

_GDIPlus_ImageSaveToFile($ParticleBitmap,@ScriptDir&"\"&$LoopCount&".jpg"

where $LoopCount is an integer that you increment every loop.

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

Link to comment
Share on other sites

I don't know why Barbarella is in my head when looking this. And Jane Fonda.

Very nice!

Strange fantasy :) LOL :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

Here a modification (Flying Squares):

Look to my 1st post!

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

I still need to play with the gdi+. But I changed up your square one a little. It's kinda hypnotizing.

;coded by UEZ 2008-01-08
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Global Const $Pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706


7982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381


9644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412


7372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160


9433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949


1298336733624406566430
Global Const $width = 600
Global Const $height = 600
Global $hGUI, $hWnd, $hGraphic, $ParticleBitmap, $ParticleBuffer, $hBrush0, $hBrush1, $hBrush2, $Pen, $real
Global $starting_point, $i, $j, $k, $xcoord1, $ycoord1, $xcoord2, $ycoord2, $size, $red, $green, $blue, $start, $ran

; 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)
AntiAlias($ParticleBuffer, 4)
_GDIPlus_GraphicsClear($ParticleBuffer);clear buffer
$real = 6
$start = -12
$i = $start
$starting_point = 0
; Loop until user exits
Do
    $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^12
    $starting_point -= 0.05
    For $j = 1 To $k Step $real
;~      $ran = Random (1,2,1)
        $real += 1
        If $real = 20 Then $real = 6
        $size = $i - $j
        $xcoord1 = $width / 2 - (($i - $j) / 2) + cos($starting_point) * -Sin(($i - $j) * $Pi / 90) * 64
        $ycoord1 = $height / 2 - (($i - $j) / 2) + -Sin($starting_point) * cos(($i - $j) * $Pi / 90) * 32
        $xcoord2 = $width / 2 - (-($i - $j) / 2) + cos($starting_point) * -Sin(($i - $j) * $Pi / 90) * 64
        $ycoord2 = $height / 2 - (($i - $j) / 2) + -Sin($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_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height);copy to bitmap
    $i += 2
    If $i > $k + 2^12 Then $i = $start
    Sleep(20)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_BitmapDispose($ParticleBitmap)
_GDIPlus_GraphicsDispose($ParticleBuffer)
_GDIPlus_BrushDispose($hBrush1)
_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

Edit: I added some digits to pi as well :-P doesn't make a difference.

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

Naw, this is a start to a possible 3D game. I need to do more with that. I've been slacking lately. http://www.autoitscript.com/forum/index.ph...;hl=au3irrlicht

Edit, the reason I was asking about exporting the image was possibly adding that to my 3D work, having a spinning cube with the pearl necklace on it, that would be nifty.

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

Naw, this is a start to a possible 3D game. I need to do more with that. I've been slacking lately. http://www.autoitscript.com/forum/index.ph...;hl=au3irrlicht

In my opinion the problem is not GDI+ but the mathematics to realize 3D :)

I'm just a beginner, too.

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

looks like a good base for building a "3D" game (the squares script) :o

great work btw! :):D

Thanks for your comment :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

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...