Jump to content

Some Graphical Examples using GDI+ Vol. I


UEZ
 Share

Recommended Posts

My 2 cents would be, for the friction have it be 1) the inverse so lower is less friction. and 2) make it a value between 0 and 100.

I don't mind the orbiting effect, makes it seem like particles, but it still has the pockets. I made is so I could make the friction over 1 (slicked the tracks a lil) and the dominant corner for the balls to get trapped is the top left, but occasionally they get trapped in the tip right and the bottom left.

Giggity

Link to comment
Share on other sites

My 2 cents would be, for the friction have it be 1) the inverse so lower is less friction. and 2) make it a value between 0 and 100.

I don't mind the orbiting effect, makes it seem like particles, but it still has the pockets. I made is so I could make the friction over 1 (slicked the tracks a lil) and the dominant corner for the balls to get trapped is the top left, but occasionally they get trapped in the tip right and the bottom left.

Thanks for feedback :D

I had that in mind, too but have forgotten to implement it (shame)! I will implement it on the next release...

I wanted to make a simulation like playing billiard but without spinning and that's why I will try to eliminate the 'orbiting' effect.

The reason for the balls being on the left upper corner is that the vectors become 0.

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 changed pixel distance function to

Func Pixel_Distance($x1, $y1, $x2, $y2)
    Local $a, $b, $c
    
        $a = $y2 - $y1
        $b = $x2 - $x1
        $c = Sqrt($a ^ 2 + $b ^ 2) - 1
        Return Round($c, 20)
EndFunc;==>Pixel_Distance

Orbiting gone.

Edit: I wanted to see my background through it. Also the changed pixel distance function messes with the friction.

CODE
#include <GuiButton.au3>

#include <GUIConstantsEx.au3>

#include <GDIplus.au3>

#include <Misc.au3>

#include <WindowsConstants.au3>

#Include <ScreenCapture.au3>

Opt('MustDeclareVars', 1)

Opt('MouseCoordMode', 2)

HotKeySet("{F5}", "Initialize")

HotKeySet("{F3}", "message")

Global $dll = DllOpen("user32.dll")

Global $width = 640

Global $height = 400

Global $enterprise

Global $winposold[10]

Global $winpos[10]

Global $field_size = 90

Global $hwnd = GUICreate("Simple Ball Collision Simulation Beta by UEZ 2009 - Press F5 to reset", $width, $height + $field_size, -1, -1)

_GDIPlus_Startup()

Global $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)

Global $bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)

Global $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

_GDIPlus_GraphicsClear($backbuffer)

_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 2)

Global $brush_color

Global $brush = _GDIPlus_BrushCreateSolid()

_GDIPlus_BrushSetSolidColor($brush, $brush_color)

Global $pen = _GDIPlus_PenCreate(0, 2)

Global $max_balls = 50

Global $amount_balls = 16

Global $min_balls = 2

Global $max_speed = 8

Global $pi = 3.1415926535897932384626

Global $pi_div_180 = $pi / 180

Global $diameter = 32

Global $radius = $diameter / 2

Global $friction = 1.000

Global $friction_min = 0.975

Dim $coordinates[$max_balls][6]

Global $angle, $distance, $dist, $DX, $DY, $mass_tot, $matrix11, $matrix12, $matrix21, $matrix22, $v_p1, $v_p2, $v_x1, $v_x2, $v_y1, $v_y2, $i

Global $q, $msg

Dim $brush[$max_balls]

Global $ball_size_min = 10

Global $ball_size_max = Int(1.5 * @DesktopHeight / 15)

Global $mouse_pos[2], $mouse_pos_temp[2]

GUICtrlCreateLabel("Ball size (min: " & $ball_size_min & " - max: " & $ball_size_max & ")", 4, $height + 12)

GUICtrlCreateLabel("Current ball size = " & $diameter, 4, $height + 68)

Global $slider_ball_size = GUICtrlCreateSlider(4, $height + 28, 150, 35)

GUICtrlSetLimit(-1, $ball_size_max, $ball_size_min)

GUICtrlSetTip(-1, "Move slider to change size of balls but pay attention to the amount of balls!")

GUICtrlCreateLabel("Friction (min: " & $friction_min & " - max: " & $friction & ")", 160, $height + 12)

GUICtrlCreateLabel("Current friction value = " & StringFormat("%.3f\n", $friction), 160, $height + 68)

Global $slider_friction = GUICtrlCreateSlider(160, $height + 28, 150, 35)

GUICtrlSetLimit(-1, ($friction - $friction_min) * 1000)

GUICtrlSetData(-1, $friction * 1000)

GUICtrlSetTip(-1, "Move slider to change friction value! Less means more friction")

GUICtrlCreateLabel("Amount of balls (min: " & $min_balls & " - max: " & $max_balls & ")", 316, $height + 12)

GUICtrlCreateLabel("Current balls = " & $amount_balls, 316, $height + 68)

Global $slider_amount_balls = GUICtrlCreateSlider(316, $height + 28, 168, 35)

GUICtrlSetLimit(-1, $max_balls, 2)

GUICtrlSetData(-1, $amount_balls)

GUICtrlSetTip(-1, "Move slider to change amount of balls!" & @CRLF & @CRLF & "But if ball size and amount of balls is too high then it will hard to place balls " & @CRLF & "on screen without collide with other balls!!!")

Global $Checkbox = GUICtrlCreateCheckbox(" Enable random mass", 492, $height + 08)

GUICtrlSetState($Checkbox, $GUI_UNCHECKED)

GUICtrlSetTip(-1, "Enable or disable random ball mass! When selected / unselected press F5 to apply!")

Global $random_mass = False

Global $nMsg

GUISetBkColor(0xF0F0F0)

GUISetState(@SW_SHOW)

GUICtrlSetData($slider_ball_size, $diameter)

GUIRegisterMsg($WM_HSCROLL , "WM_HSCROLL")

Initialize()

Do

$nMsg = GUIGetMsg()

Switch $nMsg

Case $Checkbox

If BitAND(GUICtrlRead($Checkbox), $GUI_CHECKED) Then

$random_mass = True

ElseIf BitAND(GUICtrlRead($Checkbox), $GUI_UNCHECKED) Then

$random_mass = False

EndIf

EndSwitch

_GDIPlus_GraphicsClear($backbuffer, 0xFF000000)

Collision_Check()

Draw_Dots()

Calculate_New_Position()

_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)

Sleep(25)

Until $nMsg = $GUI_EVENT_CLOSE

Func WM_HSCROLL($hwnd, $iMsg, $iwParam, $ilParam) ;check for slider activity

$diameter = GUICtrlRead($slider_ball_size)

$friction = $friction_min + GUICtrlRead($slider_friction) / 1000

$amount_balls = GUICtrlRead($slider_amount_balls)

GUICtrlCreateLabel($diameter, 90, $height + 68) ;update only the value

GUICtrlCreateLabel(StringFormat("%.3f\n", $friction), 160 + 109, $height + 68)

GUICtrlCreateLabel($amount_balls, 386, $height + 68)

EndFunc

Func Initialize()

For $k = 0 To $max_balls - 1

$brush_color = 0xFF000000 + Random(0x400000, 0xFFFFFF, 1)

$brush[$k] = _GDIPlus_BrushCreateSolid($brush_color)

Create_New_Coordinates($k)

Next

EndFunc ;==>Initialize

Func Create_New_Coordinates($k)

$coordinates[$k][0] = Random($radius + 1, $width - $radius - 1, 1);start x position

$coordinates[$k][1] = Random($radius + 1, $height - $radius - 1, 1) ;start y position

$q = 0

If $k > 0 Then ;check whether new coordinate is within other balls radius (collision)

While 1

$dist = Pixel_Distance($coordinates[$q][0], $coordinates[$q][1], $coordinates[$k][0], $coordinates[$k][1])

If $dist <= 3 * $radius Then ;create new coordinate until distance of balls are > 3 * radius

$coordinates[$k][0] = Random($radius + 1, $width - $radius - 1, 1)

$coordinates[$k][1] = Random($radius + 1, $height - $radius - 1, 1)

$q = -1

EndIf

$q += 1

If $q = $k Then ExitLoop

WEnd

EndIf

$coordinates[$k][2] = Random(1, $max_speed, 1) ;speed of pixel

$angle = Random(1, 360, 1)

$coordinates[$k][3] = $coordinates[$k][2] * Cos($angle * $pi_div_180) ;slope of x -> vector x

$coordinates[$k][4] = $coordinates[$k][2] * Sin($angle * $pi_div_180) ;slope of y -> vector y

If $random_mass Then

$coordinates[$k][5] = Random(0.5, 5.0)

Else

$coordinates[$k][5] = 1 ;mass of the ball

EndIf

EndFunc ;==>New_Coordinates

Func message()

MsgBox(0,"",$v_x1 & @lf & $v_y1 & @lf & $v_x2 & @lf & $v_y2 & @lf & $v_p1 & @lf & $v_p2)

EndFunc

Func Collision_Check()

Local $tmp, $dist_tmp

For $x = 0 To $amount_balls - 1

For $y = $x + 1 To $amount_balls - 1

$distance = Pixel_Distance($coordinates[$x][0], $coordinates[$x][1], $coordinates[$y][0], $coordinates[$y][1]) ;get distance

If $distance <= $diameter Then

$DX = $coordinates[$y][0] - $coordinates[$x][0] ;save delta x

$DY = $coordinates[$y][1] - $coordinates[$x][1] ;save delta y

;matrix with new coordinate axis (orthographic / parallel to collision object)

$matrix11 = $DX / $distance

$matrix12 = -$DY / $distance

$matrix21 = $DY / $distance

$matrix22 = $DX / $distance

;scalar product of vectors

$v_x1 = $coordinates[$x][3] * $matrix11 + $coordinates[$x][4] * -$matrix12

$v_y1 = $coordinates[$x][3] * -$matrix21 + $coordinates[$x][4] * $matrix22

$v_x2 = $coordinates[$y][3] * $matrix11 + $coordinates[$y][4] * -$matrix12

$v_y2 = $coordinates[$y][3] * -$matrix21 + $coordinates[$y][4] * $matrix22

$mass_tot = $coordinates[$x][5] + $coordinates[$y][5] ;total mass

;new vectors

$v_p1 = ($coordinates[$x][5] - $coordinates[$y][5]) / $mass_tot * $v_x1 + 2 * $coordinates[$y][5] / $mass_tot * $v_x2

$v_p2 = ($coordinates[$y][5] - $coordinates[$x][5]) / $mass_tot * $v_x2 + 2 * $coordinates[$x][5] / $mass_tot * $v_x1

;calculate new position using new vectors

$coordinates[$x][3] = $v_p1 * $matrix11 + $v_y1 * $matrix12

$coordinates[$x][4] = $v_p1 * $matrix21 + $v_y1 * $matrix22

$coordinates[$y][3] = $v_p2 * $matrix11 + $v_y2 * $matrix12

$coordinates[$y][4] = $v_p2 * $matrix21 + $v_y2 * $matrix22

$tmp = Pixel_Distance($coordinates[$x][0] + $coordinates[$x][3], $coordinates[$x][1] + $coordinates[$x][4], $coordinates[$y][0] + $coordinates[$y][3], $coordinates[$y][1] + $coordinates[$y][4])

EndIf

Next

Next

EndFunc

Func Calculate_New_Position()

Local $k

For $k = 0 To $amount_balls - 1

$coordinates[$k][0] += $coordinates[$k][3] ;increase x coordinate with appropriate slope (x vector)

$coordinates[$k][1] += $coordinates[$k][4] ;increase y coordinate with appropriate slope (y vector)

If $coordinates[$k][0] <= 0 Then ;border collision x left

$coordinates[$k][0] = 1

$coordinates[$k][3] *= -1

ElseIf $coordinates[$k][0] >= $width - $diameter Then ;border collision x right

$coordinates[$k][0] = $width - ($diameter + 1)

$coordinates[$k][3] *= -1

EndIf

If $coordinates[$k][1] <= 0 Then ;border collision y top

$coordinates[$k][1] = 1

$coordinates[$k][4] *= -1

ElseIf $coordinates[$k][1] >= $height - $diameter Then ;border collision y bottom

$coordinates[$k][1] = $height - ($diameter + 1)

$coordinates[$k][4] *= -1

EndIf

$coordinates[$k][3] *= $friction ;friction of the ball with the ground (x vector)

$coordinates[$k][4] *= $friction ;friction of the ball with the ground (y vector)

Next

EndFunc ;==>Calculate_New_Position

Func Pixel_Distance($x1, $y1, $x2, $y2)

Local $a, $b, $c

$a = $y2 - $y1

$b = $x2 - $x1

$c = Sqrt($a ^ 2 + $b ^ 2) - 1

Return Round($c, 20)

EndFunc ;==>Pixel_Distance

Func Draw_Dots()

Local $i, $temp_x, $temp_y

zulu()

For $i = 0 To $amount_balls - 1

_GDIPlus_GraphicsFillEllipse($backbuffer, $coordinates[$i][0], $coordinates[$i][1], $diameter, $diameter, $brush[$i])

Next

EndFunc ;==>Draw_Dots

Func Close()

_GDIPlus_PenDispose($pen)

For $x = 0 To UBound($brush) - 1

_GDIPlus_BrushDispose($brush[$x])

Next

_GDIPlus_BitmapDispose($bitmap)

_GDIPlus_GraphicsDispose($graphics)

_GDIPlus_GraphicsDispose($backbuffer)

_GDIPlus_Shutdown()

DllClose($dll)

Exit

EndFunc ;==>close

Func _GDIPlus_BrushSetSolidColor($hBrush, $iARGB = 0xFF000000)

Local $aResult

$aResult = DllCall($ghGDIPDll, "int", "GdipSetSolidFillColor", "hwnd", $hBrush, "int", $iARGB)

If @error Then Return SetError(@error, @extended, 0)

Return SetError($aResult[0], 0, $aResult[0] = 0)

EndFunc ;==>_GDIPlus_BrushSetSolidColor

Func Zulu ()

$winpos = WinGetPos("Simple Ball Collision Simulation Beta by UEZ 2009 - Press F5 to reset")

If $winposold[0] <> $winpos[0] Then

;~ MsgBox(0,$winposold[0],$winpos[0] & @LF & "msgbox1")

If $winposold[1] <> $winpos[1] Then

;~ MsgBox(0,$winposold[1],$winpos[1] & @LF & "msgbox2")

$winposold = WinGetPos("Simple Ball Collision Simulation Beta by UEZ 2009 - Press F5 to reset")

GUISetState(@SW_HIDE,$hwnd)

_GDIPlus_ImageDispose($enterprise)

Sleep(100)

$i += 1

_ScreenCapture_Capture(@TempDir & "\background" & $i & ".jpg",$winpos[0]+1,$winpos[1]+29,$winpos[2] + $winpos[0]+1,$winpos[3] + $winpos[1]+29,False)

$enterprise = _GDIPlus_ImageLoadFromFile(@tempDir & "\background" & $i & ".jpg")

GUISetState(@sw_show,$hwnd)

_GDIPlus_GraphicsDrawImageRect($backbuffer, $enterprise,0,0,$winpos[2],$winpos[3])

Else

$enterprise = _GDIPlus_ImageLoadFromFile(@tempDir & "\background" & $i & ".jpg")

_GDIPlus_GraphicsDrawImageRect($backbuffer, $enterprise,0,0,$winpos[2],$winpos[3])

EndIf

Else

$enterprise = _GDIPlus_ImageLoadFromFile(@tempDir & "\background" & $i & ".jpg")

_GDIPlus_GraphicsDrawImageRect($backbuffer, $enterprise,0,0,$winpos[2],$winpos[3])

EndIf

EndFunc

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

I changed pixel distance function to

Func Pixel_Distance($x1, $y1, $x2, $y2)
     Local $a, $b, $c
     
         $a = $y2 - $y1
         $b = $x2 - $x1
         $c = Sqrt($a ^ 2 + $b ^ 2) - 1
         Return Round($c, 20)
 EndFunc;==>Pixel_Distance

Orbiting gone.

But that is mathematically not correct and also the speed of the balls will be continuously faster!

The reason for the 'orbiting' is that the collision vectors are not enough to leave the collision zone (distance between balls is < 2*r)!

Also if the balls are too fast it might be that they are not collide because the direction vector is greater than the diameter of the balls.

I'm working on it...

:D 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

  • 1 month later...

Despite the annoying flicker, I think this may have some promising effects. I'm a little rusty on my GDI+ right now, but I was thinking a background that reflected time of day, maybe even have the time back there, eventually have it incompuse your whole world, weather, upcoming events, everything on your background. And here's my start. I was a little excited about the idea so I took UEZ's spinning squares and used it as my example. Yes lots of flicker, but if it were a updated every minute type deal, it wouldn't be so bad.

CODE
#include <Constants.au3>

#include <GuiListView.au3>

#include <GuiConstantsEx.au3>

#include <GDIPlus.au3>

$hdesk=ControlGetHandle("Program Manager", "", "SysListView321")

$deskpos=WinGetPos($hDesk)

Opt('MustDeclareVars', 1)

Global Const $Pi = 3.1415926535897932384626

Global Const $width = @DesktopWidth / 2

Global Const $height = @DesktopHeight / 2

Global $hGUI, $hGraphic, $Bitmap, $GDI_Buffer, $Pen, $Brush

Global $i, $j, $k, $xcoord, $ycoord, $red, $green, $blue

Global $x1, $x2, $x3, $x4, $y1, $y2, $y3, $y4

$hGUI = GUICreate("GDI+: Rotating Squares by UEZ 2009", $width, $height)

GUISetState(@SW_SHOW)

_GDIPlus_Startup ()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) ;create graphic

$Bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap

$GDI_Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap) ;create buffer

$Pen = _GDIPlus_PenCreate(0, 2)

$Brush = _GDIPlus_BrushCreateSolid(0xFF000000)

_GDIPlus_GraphicsSetSmoothingMode($GDI_Buffer, 4)

_GDIPlus_GraphicsClear($GDI_Buffer)

$i = 1

Do

;~ _GDIPlus_GraphicsClear($GDI_Buffer) ;clear buffer

_GDIPlus_GraphicsFillEllipse($GDI_Buffer, $width / 2 - $k, $height / 2 - $k, 2 * $k, 2 * $k, $Brush) ;clear only area where the squares are drawn

If $k <= 3 * $width / 7 Then $k += 1

For $j = 8 To $k Step 24 + Cos($i * $Pi / 60) * 12

$red = ((Sin(2^0 * ($j - $i) / 2^5) + 1) / 2) * 256

$green = ((Sin(2^0 * ($j - $i) / 2^7) + 1) / 2) * 256

$blue = ((Sin(2^0 * ($j - $i) / 2^9) + 1) / 2) * 256

_GDIPlus_PenSetColor($Pen, "0xEF" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2)) ;Set the pen color

$xcoord = $j ;+ Sin($i * $Pi / 60) * 8

$ycoord = $j ;+ Cos($i * $Pi / 60) * 8

Square($xcoord, $ycoord, $j * Sin($i / $k * $Pi * 4) * 2 / 3)

Next

_GDIPlus_GraphicsDrawImageRect($hGraphic, $Bitmap, 0, 0, $width, $height) ;copy to bitmap

$i += 1.5

Sleep(30)

_GDIPlus_ImageSaveToFile($bitmap,@MyDocumentsDir & "\gdibkg.jpg")

_GUICtrlListView_SetBkImage($hDesk,@MyDocumentsDir & "\gdibkg.jpg",1)

Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources

_GDIPlus_PenDispose($Pen)

_GDIPlus_BitmapDispose($Bitmap)

_GDIPlus_GraphicsDispose($GDI_Buffer)

_GDIPlus_GraphicsDispose ($hGraphic)

_GDIPlus_Shutdown ()

Func Square($xx1, $yy1, $i)

Local $degree

$degree = 45

$x1 = $xx1 * Cos(($i + $degree + 0) * $Pi / 180) + $width / 2

$y1 = $yy1 * Sin(($i + $degree + 0) * $Pi / 180) + $height / 2

$x2 = $xx1 * Cos(($i + $degree + 90) * $Pi / 180) + $width / 2

$y2 = $yy1 * Sin(($i + $degree + 90) * $Pi / 180) + $height / 2

$x3 = $xx1 * Cos(($i + $degree + 180) * $Pi / 180) + $width / 2

$y3 = $yy1 * Sin(($i + $degree + 180) * $Pi / 180) + $height / 2

$x4 = $xx1 * Cos(($i + $degree + 270) * $Pi / 180) + $width / 2

$y4 = $yy1 * Sin(($i + $degree + 270) * $Pi / 180) + $height / 2

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x1, $y1, $x2, $y2, $Pen)

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x2, $y2, $x3, $y3, $Pen)

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x3, $y3, $x4, $y4, $Pen)

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x4, $y4, $x1, $y1, $Pen)

EndFunc

Giggity

Link to comment
Share on other sites

Despite the annoying flicker, I think this may have some promising effects. I'm a little rusty on my GDI+ right now, but I was thinking a background that reflected time of day, maybe even have the time back there, eventually have it incompuse your whole world, weather, upcoming events, everything on your background. And here's my start. I was a little excited about the idea so I took UEZ's spinning squares and used it as my example. Yes lots of flicker, but if it were a updated every minute type deal, it wouldn't be so bad.

CODE
#include <Constants.au3>

#include <GuiListView.au3>

#include <GuiConstantsEx.au3>

#include <GDIPlus.au3>

$hdesk=ControlGetHandle("Program Manager", "", "SysListView321")

$deskpos=WinGetPos($hDesk)

Opt('MustDeclareVars', 1)

Global Const $Pi = 3.1415926535897932384626

Global Const $width = @DesktopWidth / 2

Global Const $height = @DesktopHeight / 2

Global $hGUI, $hGraphic, $Bitmap, $GDI_Buffer, $Pen, $Brush

Global $i, $j, $k, $xcoord, $ycoord, $red, $green, $blue

Global $x1, $x2, $x3, $x4, $y1, $y2, $y3, $y4

$hGUI = GUICreate("GDI+: Rotating Squares by UEZ 2009", $width, $height)

GUISetState(@SW_SHOW)

_GDIPlus_Startup ()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) ;create graphic

$Bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap

$GDI_Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap) ;create buffer

$Pen = _GDIPlus_PenCreate(0, 2)

$Brush = _GDIPlus_BrushCreateSolid(0xFF000000)

_GDIPlus_GraphicsSetSmoothingMode($GDI_Buffer, 4)

_GDIPlus_GraphicsClear($GDI_Buffer)

$i = 1

Do

;~ _GDIPlus_GraphicsClear($GDI_Buffer) ;clear buffer

_GDIPlus_GraphicsFillEllipse($GDI_Buffer, $width / 2 - $k, $height / 2 - $k, 2 * $k, 2 * $k, $Brush) ;clear only area where the squares are drawn

If $k <= 3 * $width / 7 Then $k += 1

For $j = 8 To $k Step 24 + Cos($i * $Pi / 60) * 12

$red = ((Sin(2^0 * ($j - $i) / 2^5) + 1) / 2) * 256

$green = ((Sin(2^0 * ($j - $i) / 2^7) + 1) / 2) * 256

$blue = ((Sin(2^0 * ($j - $i) / 2^9) + 1) / 2) * 256

_GDIPlus_PenSetColor($Pen, "0xEF" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2)) ;Set the pen color

$xcoord = $j ;+ Sin($i * $Pi / 60) * 8

$ycoord = $j ;+ Cos($i * $Pi / 60) * 8

Square($xcoord, $ycoord, $j * Sin($i / $k * $Pi * 4) * 2 / 3)

Next

_GDIPlus_GraphicsDrawImageRect($hGraphic, $Bitmap, 0, 0, $width, $height) ;copy to bitmap

$i += 1.5

Sleep(30)

_GDIPlus_ImageSaveToFile($bitmap,@MyDocumentsDir & "\gdibkg.jpg")

_GUICtrlListView_SetBkImage($hDesk,@MyDocumentsDir & "\gdibkg.jpg",1)

Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources

_GDIPlus_PenDispose($Pen)

_GDIPlus_BitmapDispose($Bitmap)

_GDIPlus_GraphicsDispose($GDI_Buffer)

_GDIPlus_GraphicsDispose ($hGraphic)

_GDIPlus_Shutdown ()

Func Square($xx1, $yy1, $i)

Local $degree

$degree = 45

$x1 = $xx1 * Cos(($i + $degree + 0) * $Pi / 180) + $width / 2

$y1 = $yy1 * Sin(($i + $degree + 0) * $Pi / 180) + $height / 2

$x2 = $xx1 * Cos(($i + $degree + 90) * $Pi / 180) + $width / 2

$y2 = $yy1 * Sin(($i + $degree + 90) * $Pi / 180) + $height / 2

$x3 = $xx1 * Cos(($i + $degree + 180) * $Pi / 180) + $width / 2

$y3 = $yy1 * Sin(($i + $degree + 180) * $Pi / 180) + $height / 2

$x4 = $xx1 * Cos(($i + $degree + 270) * $Pi / 180) + $width / 2

$y4 = $yy1 * Sin(($i + $degree + 270) * $Pi / 180) + $height / 2

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x1, $y1, $x2, $y2, $Pen)

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x2, $y2, $x3, $y3, $Pen)

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x3, $y3, $x4, $y4, $Pen)

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x4, $y4, $x1, $y1, $Pen)

EndFunc

Nice idea but it is flickering terribly!

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 an little modified explosion effect from AUTOITEROIDS (not a medical name for a type of sickness :) ), maybe you like it:

Look at my 1st post if you are interested -> #11 Particle Explosions!

When I find the time I will try to code a firework :party:

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

Nothing is more painful than when your AutoIteroids explodes. Yea it flickers a lot, because the desktop has to refresh. I may try some stuff to make it look better, dono, have a lot of work to do this week. May just go with my original idea of something that only needs to refresh ever minute or so.

Giggity

Link to comment
Share on other sites

Here's the most useless GDI+ Particle Collision script to exist.

There are many rules at the top of the script that can be set to alter behavior.

(be sure to look over and play with these settings)

The current options indicate several rules about what happens:

Many free-moving particles are shown, they all start as red.

If a particle collides it cycles it's color (see the $Pens array)

If two free-moving particles collide, they are glued into place.

If a particle that is stuck is hit by a free-moving particle, both are then free-moving.

- This allows items to sporadically cycle between active and dormant for a while.

Chances are, however, if "Sticky" collisions are on, that the majority of particles will EVENTUALLY come to rest nomatter the setting.

#include <GDIPlus.au3>
Opt("GUIOnEventMode", 1)
; Known issues:
;  If $CollisionsRandomizeAngles is True, the same items may collide on subsequent loops because the angle is not forced "away" from the collision.
;  Because all items are checked against all other items, the same two items may collide 1-2 times in the same loop - there is not a obvious way to gracefully save every collision.
;   - This last issue doesn't seem to seriously effect operation
;  | both of the above issues can somewhat be offset by having $CollisionsMoveCollidedItems enabled

$w=294
$h=258

$ParticleNum=50
$ParticleMax=50
$ParticleSpeed=10

;collision debugging/settings
$MarkCollisions=True; collisions are circled
$PauseCollisions=False; pauses all changes when a collision occurs (drawing occurs before pausing, so circles are shown)

;collision effects
$CollisionsCycleColors=True;  the colors of the collided items cycle (via $Pens array)
$CollisionsRandomizeAngles=True; the angles of the collided items are randomized.
$CollisionsMoveItems=False; the collided items are moved once more (occurs after $CollisionsRandomizeAngles if enabled)
;sticky collisions!
$CollisionsStickMovingItems=True; moving collisions are glued in place. This will disable $CollisionsRandomizeAngles
$CollisionsUnstickStuckItems=True; items glued in place start moving again once hit.
$CollisionsStuckItemsNotSticky=True; if true, items that hit stuck items don't get stuck themselves

;Drawing state settings
$Running=True
$Changing=True
$Moving=True
$Colliding=True

Opt('GUIOnEventMode',1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("o.0", $w, $h, 361, 159)
GUISetOnEvent(-3,'_Exit')
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

If $CollisionsStickMovingItems Then $CollisionsRandomizeAngles=False

_GDIPlus_Startup()
$gro=_GDIPlus_GraphicsCreateFromHWND($Form1)
$grb=_GDIPlus_BitmapCreateFromGraphics($w, $h, $gro)
$gri=_GDIPlus_ImageGetGraphicsContext($grb)


$PenMax=7
Dim $Pens[$PenMax]
$Pens[0]=0; because unused particles use Pen 0;
$Pens[1]=_GDIPlus_PenCreate(0xFFFF0000)
$Pens[2]=_GDIPlus_PenCreate(0xFF7F7F00)
$Pens[3]=_GDIPlus_PenCreate(0xFF00FF00)
$Pens[4]=_GDIPlus_PenCreate(0xFF007F7F)
$Pens[5]=_GDIPlus_PenCreate(0xFF0000FF)
$Pens[6]=_GDIPlus_PenCreate(0xFF7F007F)

Dim $Particles[$ParticleMax][4]
_Particles_Clear()


For $i=1 To $ParticleNum
    _Particles_Add(Random(0,$w,1),Random(0,$h,1),Random(0,6.28318),1)
Next


GUISetState(@SW_SHOW)
While $Running
    If $Changing Then
        _GDIPlus_GraphicsClear($gri,0xFF000000)
        _Particles_Changes()
    EndIf
    _GDIPlus_GraphicsDrawImageRect ($gro, $grb, 0, 0, $w, $h) ;copy to bitmap
    Sleep(150)
WEnd
Exit

Func _Exit()
    $Running=False
EndFunc

Func _Particles_Changes()
    For $i=0 To $ParticleMax-1
        If $Particles[$i][3]<>0 Then
            If $Moving Then _Particles_Move($i)
            _Particles_Draw($i)
            If $Colliding Then _Particles_Collide($i)
        EndIf
    Next
EndFunc



Func _Particles_Remove($i)
    For $j=0 To 3
        $Particles[$i][$j]=0
    Next
EndFunc
Func _Particles_Clear()
    For $i=0 To $ParticleMax-1
        _Particles_Remove($i)
    Next
EndFunc
Func _Particles_Add($x,$y,$a,$c)
    For $i=0 To $ParticleMax-1
        If $Particles[$i][3]=0 Then; no pen!? - it's blank!!!
            $Particles[$i][0]=$x
            $Particles[$i][1]=$y
            $Particles[$i][2]=$a
            $Particles[$i][3]=$c
            Return
        EndIf
    Next
EndFunc
Func _Particles_Draw($i)
    ;_GDIPlus_GraphicsDrawLine($gri,$Particles[$i][0],$Particles[$i][1],$Particles[$i][0]+1,$Particles[$i][1],$Pens[$Particles[$i][3]])
    _GDIPlus_GraphicsDrawRect($gri,$Particles[$i][0]-1,$Particles[$i][1]-1,2,2,$Pens[$Particles[$i][3]])
EndFunc

Func _Particles_Move($i)
    If $Particles[$i][2]=-1 Then Return; while -1 is a valid angle, I'm using it as a "stuck" value.
    $Particles[$i][0]+=Round(   Cos($Particles[$i][2])*$ParticleSpeed,4)
    $Particles[$i][1]+=Round(-1*Sin($Particles[$i][2])*$ParticleSpeed,4)
    iLimit2($Particles[$i][0],0,$w,   $w,0)
    iLimit2($Particles[$i][1],0,$h,   $h,0)
EndFunc



Func _Particles_Collide($i)
    For $j=0 To $ParticleMax-1
        If $i=$j Then ContinueLoop
        If $Particles[$j][3]<>0 Then
            If $Particles[$i][2]=-1 And $Particles[$j][2]=-1 Then Return; two stuck items cannot collide
            If Abs($Particles[$i][0]-$Particles[$j][0])<5 And Abs($Particles[$i][1]-$Particles[$j][1])<5 Then
                ;ConsoleWrite('Collision: '&$Particles[$i][0]&','&$Particles[$i][1]&' && '&$Particles[$j][0]&','&$Particles[$j][1]&@CRLF)

                If $CollisionsCycleColors Then
                    $Particles[$i][3]+=1
                    $Particles[$j][3]+=1
                    iLimit2($Particles[$i][3], 1,$PenMax-1, $PenMax-1,1)
                    iLimit2($Particles[$j][3], 1,$PenMax-1, $PenMax-1,1)
                EndIf

                If $CollisionsRandomizeAngles Then
                    $Particles[$i][2]=Random(0,6.28318)
                    $Particles[$j][2]=Random(0,6.28318)
                EndIf

                If $CollisionsMoveItems Then
                    _Particles_Move($i)
                    _Particles_Move($j)
                EndIf

                $iCanUnStick=True
                $jCanUnStick=True
                If $CollisionsStickMovingItems Then
                    If $Particles[$i][2]<>-1 Then
                        $Particles[$i][2]=-1
                        $iCanUnStick=False
                    EndIf
                    If $Particles[$j][2]<>-1 Then
                        $Particles[$j][2]=-1
                        $jCanUnStick=False
                    EndIf
                EndIf


                If $CollisionsUnstickStuckItems Then
                    If $iCanUnStick And $Particles[$i][2]=-1 Then
                        $Particles[$i][2]=Random(0,6.28318)
                        If $CollisionsStuckItemsNotSticky Then $Particles[$j][2]=Random(0,6.28318)
                    EndIf
                    If $jCanUnStick And $Particles[$j][2]=-1 Then
                        $Particles[$j][2]=Random(0,6.28318)
                        If $CollisionsStuckItemsNotSticky Then $Particles[$i][2]=Random(0,6.28318)
                    EndIf
                EndIf

                If $MarkCollisions Then
                    $avX=(($Particles[$i][0]+$Particles[$j][0])/2)-10
                    $avY=(($Particles[$i][1]+$Particles[$j][1])/2)-10
                    _GDIPlus_GraphicsDrawEllipse($gri,$avX,$avY,20,20,$Pens[1])
                EndIf

                If $PauseCollisions Then
                    $Moving=False
                    $Colliding=False
                    $Changing=False
                EndIf
            EndIf
        EndIf
    Next
EndFunc



Func iLimit2(ByRef $i, $n,$x, $n2, $x2)
    If Not IsInt($i) Then $i=Int($i)
    If $i<$n Then
        $i=$n2
        Return -1;=True, still.
    EndIf
    If $i>$x Then
        $i=$x2
        Return +1
    EndIf
    Return 0
EndFunc

Personally, it's not even worth posting on the first page - just enjoy it.

It's based on something that acts somewhat similar visually, but I shall not reveal my source. :D

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

  • 2 months later...

Despite the annoying flicker, I think this may have some promising effects. I'm a little rusty on my GDI+ right now, but I was thinking a background that reflected time of day, maybe even have the time back there, eventually have it incompuse your whole world, weather, upcoming events, everything on your background. And here's my start. I was a little excited about the idea so I took UEZ's spinning squares and used it as my example. Yes lots of flicker, but if it were a updated every minute type deal, it wouldn't be so bad.

<div class='codetop'>CODE</div><div class='codemain' style='height:200px;overflow:auto'>#include <Constants.au3>

#include <GuiListView.au3>

#include <GuiConstantsEx.au3>

#include <GDIPlus.au3>

$hdesk=ControlGetHandle("Program Manager", "", "SysListView321")

$deskpos=WinGetPos($hDesk)

Opt('MustDeclareVars', 1)

Global Const $Pi = 3.1415926535897932384626

Global Const $width = @DesktopWidth / 2

Global Const $height = @DesktopHeight / 2

Global $hGUI, $hGraphic, $Bitmap, $GDI_Buffer, $Pen, $Brush

Global $i, $j, $k, $xcoord, $ycoord, $red, $green, $blue

Global $x1, $x2, $x3, $x4, $y1, $y2, $y3, $y4

$hGUI = GUICreate("GDI+: Rotating Squares by UEZ 2009", $width, $height)

GUISetState(@SW_SHOW)

_GDIPlus_Startup ()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) ;create graphic

$Bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap

$GDI_Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap) ;create buffer

$Pen = _GDIPlus_PenCreate(0, 2)

$Brush = _GDIPlus_BrushCreateSolid(0xFF000000)

_GDIPlus_GraphicsSetSmoothingMode($GDI_Buffer, 4)

_GDIPlus_GraphicsClear($GDI_Buffer)

$i = 1

Do

;~ _GDIPlus_GraphicsClear($GDI_Buffer) ;clear buffer

_GDIPlus_GraphicsFillEllipse($GDI_Buffer, $width / 2 - $k, $height / 2 - $k, 2 * $k, 2 * $k, $Brush) ;clear only area where the squares are drawn

If $k <= 3 * $width / 7 Then $k += 1

For $j = 8 To $k Step 24 + Cos($i * $Pi / 60) * 12

$red = ((Sin(2^0 * ($j - $i) / 2^5) + 1) / 2) * 256

$green = ((Sin(2^0 * ($j - $i) / 2^7) + 1) / 2) * 256

$blue = ((Sin(2^0 * ($j - $i) / 2^9) + 1) / 2) * 256

_GDIPlus_PenSetColor($Pen, "0xEF" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2)) ;Set the pen color

$xcoord = $j ;+ Sin($i * $Pi / 60) * 8

$ycoord = $j ;+ Cos($i * $Pi / 60) * 8

Square($xcoord, $ycoord, $j * Sin($i / $k * $Pi * 4) * 2 / 3)

Next

_GDIPlus_GraphicsDrawImageRect($hGraphic, $Bitmap, 0, 0, $width, $height) ;copy to bitmap

$i += 1.5

Sleep(30)

_GDIPlus_ImageSaveToFile($bitmap,@MyDocumentsDir & "\gdibkg.jpg")

_GUICtrlListView_SetBkImage($hDesk,@MyDocumentsDir & "\gdibkg.jpg",1)

Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources

_GDIPlus_PenDispose($Pen)

_GDIPlus_BitmapDispose($Bitmap)

_GDIPlus_GraphicsDispose($GDI_Buffer)

_GDIPlus_GraphicsDispose ($hGraphic)

_GDIPlus_Shutdown ()

Func Square($xx1, $yy1, $i)

Local $degree

$degree = 45

$x1 = $xx1 * Cos(($i + $degree + 0) * $Pi / 180) + $width / 2

$y1 = $yy1 * Sin(($i + $degree + 0) * $Pi / 180) + $height / 2

$x2 = $xx1 * Cos(($i + $degree + 90) * $Pi / 180) + $width / 2

$y2 = $yy1 * Sin(($i + $degree + 90) * $Pi / 180) + $height / 2

$x3 = $xx1 * Cos(($i + $degree + 180) * $Pi / 180) + $width / 2

$y3 = $yy1 * Sin(($i + $degree + 180) * $Pi / 180) + $height / 2

$x4 = $xx1 * Cos(($i + $degree + 270) * $Pi / 180) + $width / 2

$y4 = $yy1 * Sin(($i + $degree + 270) * $Pi / 180) + $height / 2

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x1, $y1, $x2, $y2, $Pen)

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x2, $y2, $x3, $y3, $Pen)

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x3, $y3, $x4, $y4, $Pen)

_GDIPlus_GraphicsDrawLine($GDI_Buffer, $x4, $y4, $x1, $y1, $Pen)

EndFunc

</div>

i ran that on windows 7 and it messed up my background. how do i fix it?

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

  • 6 months later...

Normally I just add a GDI+ example to this thread silently but this time I thought it can be announced...

Just have a look the the GDI+ rotating cube examples made in pur GDI+ added to the 1st post of this thread! :mellow:

I hope you will like it.

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 cubes, but I have a few comments:

  • The cubes do not look as cubes, visually it looks as the upside perspective (deformed). Probably the formulas is wrong.
  • Script crashes on exit for me.
Edited by Yashied
Link to comment
Share on other sites

Nice cubes, but I have a few comments:

  • The cubes do not look as cubes, visually it looks as the upside perspective (deformed). Probably the formulas is wrong.
  • Script crashes on exit for me.

Yes, you are right! The vanishing point is not correct and I'm looking already for a proper working function!

I tested the cubes on Vista x32 and Windows7 x64 using latest AutoIt version without any problems!

Other people with problems on exit?

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

That's what I got (actually very similar).

#Include <GDIPlus.au3>
#Include <WinAPI.au3>

Global Const $STM_SETIMAGE = 0x0172
Global Const $STM_GETIMAGE = 0x0173

Global Const $Pi = 4 * ATan(1)

Global $Scale = 1

GUIRegisterMsg(0x020A, 'WM_MOUSEWHEEL')

GUICreate('MyGUI', 350, 350)
$Pic = GUICtrlCreatePic('', 0, 0, 350, 350)
$hPic = GUICtrlGetHandle(-1)
GUISetState()

_GDIPlus_Startup()

$IA = 0
$TA = 0

While 1
    _DrawCube(0, $IA, $TA, $Scale)
    $IA += 2
    If $IA > 360 Then
        $IA = 0
    EndIf
    $TA += 2
    If $TA > 360 Then
        $TA = 0
    EndIf
    $Timer = TimerInit()
    While TimerDiff($Timer) < 20
        If GUIGetMsg() = -3 Then
            ExitLoop 2
        EndIf
    WEnd
WEnd

_GDIPlus_Shutdown()

Func _2D($X, $Y, $Z, $D, $I, $T, ByRef $Xp, ByRef $Yp)

    Local $DC = Cos($D * $Pi / 180)
    Local $DS = Sin($D * $Pi / 180)
    Local $IC = Cos($I * $Pi / 180)
    Local $IS = Sin($I * $Pi / 180)
    Local $TC = Cos($T * $Pi / 180)
    Local $TS = Sin($T * $Pi / 180)

    $Xp = Round($X * ($DC * $TC - $DS * $TS * $IC) - $Y * ($DS * $TC + $DC * $TS * $IC) + $Z * ($TS * $IS))
    $Yp = Round($X * ($DS * $IS) + $Y * ($DC * $IS) + $Z * ($IC))

EndFunc   ;==>_2D

Func _DrawCube($DA, $IA, $TA, $Scale)

    Local $hBitmap, $hObj, $hGraphic, $hImage, $hBrush, $hPen
    Local $Size = WinGetClientSize($hPic)
    Local $Pos[8][2]

    _2D(-100 * $Scale, -100 * $Scale, -100 * $Scale, $DA, $IA, $TA, $Pos[ 0][0], $Pos[ 0][1])
    _2D(-100 * $Scale,  100 * $Scale, -100 * $Scale, $DA, $IA, $TA, $Pos[ 1][0], $Pos[ 1][1])
    _2D( 100 * $Scale,  100 * $Scale, -100 * $Scale, $DA, $IA, $TA, $Pos[ 2][0], $Pos[ 2][1])
    _2D( 100 * $Scale, -100 * $Scale, -100 * $Scale, $DA, $IA, $TA, $Pos[ 3][0], $Pos[ 3][1])
    _2D(-100 * $Scale, -100 * $Scale,  100 * $Scale, $DA, $IA, $TA, $Pos[ 4][0], $Pos[ 4][1])
    _2D(-100 * $Scale,  100 * $Scale,  100 * $Scale, $DA, $IA, $TA, $Pos[ 5][0], $Pos[ 5][1])
    _2D( 100 * $Scale,  100 * $Scale,  100 * $Scale, $DA, $IA, $TA, $Pos[ 6][0], $Pos[ 6][1])
    _2D( 100 * $Scale, -100 * $Scale,  100 * $Scale, $DA, $IA, $TA, $Pos[ 7][0], $Pos[ 7][1])

    For $i = 0 To 7
        For $j = 0 To 1
            $Pos[$i][$j] += Floor($Size[$j] / 2)
        Next
    Next

    $hBitmap = _WinAPI_CreateBitmap($Size[0], $Size[1], 1, 32)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    _WinAPI_DeleteObject($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $Size[0], $Size[1], $hBrush)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    $hPen = _GDIPlus_PenCreate(0xFFFF3030, 2)

    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[0][0], $Pos[0][1], $Pos[1][0], $Pos[1][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[1][0], $Pos[1][1], $Pos[2][0], $Pos[2][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[2][0], $Pos[2][1], $Pos[3][0], $Pos[3][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[3][0], $Pos[3][1], $Pos[0][0], $Pos[0][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[4][0], $Pos[4][1], $Pos[5][0], $Pos[5][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[5][0], $Pos[5][1], $Pos[6][0], $Pos[6][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[6][0], $Pos[6][1], $Pos[7][0], $Pos[7][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[7][0], $Pos[7][1], $Pos[4][0], $Pos[4][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[0][0], $Pos[0][1], $Pos[4][0], $Pos[4][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[1][0], $Pos[1][1], $Pos[5][0], $Pos[5][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[2][0], $Pos[2][1], $Pos[6][0], $Pos[6][1], $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $Pos[3][0], $Pos[3][1], $Pos[7][0], $Pos[7][1], $hPen)

    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)

    $hObj = _SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
    If $hObj Then
        _WinAPI_DeleteObject($hObj)
    EndIf
    $hObj = _SendMessage($hPic, $STM_GETIMAGE)
    If $hObj <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf
EndFunc   ;==>_DrawCube

Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)
    $Scale -= 0.1 * BitShift($wParam, 16) / 120
    If $Scale < 0.2 Then
        $Scale = 0.2
    EndIf
    If $Scale > 1.6 Then
        $Scale = 1.6
    EndIf
    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_MOUSEWHEEL

Yes, and I have the crash of the script only when I click the "Close" button. This is because of the following.

DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
Edited by Yashied
Link to comment
Share on other sites

No, it is closing properly on my WinXP SP3 x32 in VM and also with Vista x32 on real hw!

Btw, as far as I can see your cube looks same as the one I did with same vanishing point issue or is this an optical illusion?

Edit: do you have another mouse wheel code?

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

Btw, as far as I can see your cube looks same as the one I did with same vanishing point issue or is this an optical illusion?

Yes, it's an optical illusion, you need to add the perspective effect. But I currently can not tell you how to do it. I think about it.

EDIT:

...do you have another mouse wheel code?

WM_MOUSEWHEEL? Edited by Yashied
Link to comment
Share on other sites

  • 1 month later...

Thanks for the examples.

Posted Image

Just messing around.

"Lingering Line" v2.1 (Keys: ESC=Quit, Home=Toggle between Half and FullScreen.)

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_AU3Check=y
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4        -w 6 -q
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("GUIOnEventMode", 1)
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
Global Enum $_hWin_, $_hGraphic_, $_iWidth_, $_iHeight_, $_hBitmap_, $_Buffer_, $iFields_GdiGui
Global $HALFSIZE = True, $QUIT = False, $TOGGLESIZE = False, $FLIPCOLOR = False
Global $aGdiGui

Func _Lines_($iWidth, $iHeight, $hGraphic, $hBuffer)
    Local $aMax[4] = [$iWidth, $iHeight, $iWidth, $iHeight]
    Local $aLine[4] = [Random(0, $aMax[0], 1), Random(0, $aMax[1], 1), Random(0, $aMax[2], 1), Random(0, $aMax[3], 1)]
    Local $aMove[4] = [Random(1, 4, 1), Random(1, 4, 1), Random(1, 4, 1), Random(1, 4, 1)]
    Local $hPen = _GDIPlus_PenCreate(0x44000000, 1)
    Local $iJump = 2 * ($HALFSIZE * - 1 + 2)
    _AdlibSetup()
    GUIRegisterMsg($WM_PAINT, "WM_PAINT")
    GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
    Do
        For $j = 1 To $iJump
            _GDIPlus_GraphicsDrawLine($hBuffer, $aLine[0], $aLine[1], $aLine[2], $aLine[3], $hPen)
            _GDIPlus_GraphicsDrawLine($hGraphic, $aLine[0], $aLine[1], $aLine[2], $aLine[3], $hPen)
            For $i = 0 To 3
                $aLine[$i] += $aMove[$i]
                If $aLine[$i] < ($aMax[$i] * - 0.1) Then
                    $aMove[$i] = Random(1, 4, 1)
                ElseIf $aLine[$i] > ($aMax[$i] + $aMax[$i] * 0.1) Then
                    $aMove[$i] = Random(1, 4, 1) * - 1
                EndIf
            Next
        Next
        If $FLIPCOLOR Then
            If _GDIPlus_PenGetColor($hPen) > 0x44000000 Then
                _GDIPlus_PenSetColor($hPen, 0x44000000)
            Else
                _GDIPlus_PenSetColor($hPen, 0x44FFFFFF)
            EndIf
            $FLIPCOLOR = False
        EndIf

        Sleep(10)
    Until $QUIT
    GUISetState(@SW_HIDE, $aGdiGui[$_hWin_])
    Sleep(10)
    GUIRegisterMsg($WM_PAINT, "")
    GUIRegisterMsg($WM_ERASEBKGND, "")
    _GDIPlus_PenDispose($hPen)
    Return
EndFunc


Func MAIN()
    Do
        $aGdiGui = _GDI_Setup()
        _Lines_($aGdiGui[$_iWidth_], $aGdiGui[$_iHeight_], $aGdiGui[$_hGraphic_], $aGdiGui[$_Buffer_])
        _GDI_Shutdown($aGdiGui)
        If $TOGGLESIZE Then
            $HALFSIZE = ($HALFSIZE = False)
            $TOGGLESIZE = False
            $QUIT = False
            _AdlibSetup()
        EndIf
    Until $QUIT
    Return
EndFunc
Func _GDI_Setup()
    Local $aGdiGui[$iFields_GdiGui], $iLeft = -1, $iTop = -1
    If $HALFSIZE Then
        $aGdiGui[$_iWidth_] = @DesktopWidth / 2
        $aGdiGui[$_iHeight_] = @DesktopHeight / 2
    Else
        $aGdiGui[$_iWidth_] = @DesktopWidth
        $aGdiGui[$_iHeight_] = @DesktopHeight
        $iLeft = 0
        $iTop = 0
    EndIf
    $aGdiGui[$_hWin_] = GUICreate("Lingering Line", $aGdiGui[$_iWidth_], $aGdiGui[$_iHeight_], $iLeft, $iTop, $WS_POPUP)
    GUISetOnEvent($GUI_EVENT_CLOSE, "AK_Quit", $aGdiGui[$_hWin_])
    Local $AccelKeys[1][2] = [["{HOME}", GUICtrlCreateDummy()]]
    GUICtrlSetOnEvent($AccelKeys[0][1], 'AK_Quit')
    GUISetAccelerators($AccelKeys)
    _GDIPlus_Startup()
    $aGdiGui[$_hGraphic_] = _GDIPlus_GraphicsCreateFromHWND($aGdiGui[$_hWin_]) ;create graphic
    $aGdiGui[$_hBitmap_] = _GDIPlus_BitmapCreateFromGraphics($aGdiGui[$_iWidth_], $aGdiGui[$_iHeight_], $aGdiGui[$_hGraphic_]) ;create bitmap
    $aGdiGui[$_Buffer_] = _GDIPlus_ImageGetGraphicsContext($aGdiGui[$_hBitmap_]) ;create buffer
    Local Enum $_Smooth_none_, $_Smooth_8x4_, $_Smooth_8x8_
    _GDIPlus_GraphicsSetSmoothingMode($aGdiGui[$_Buffer_], $_Smooth_8x8_)
    _GDIPlus_GraphicsSetSmoothingMode($aGdiGui[$_hGraphic_], $_Smooth_8x8_)
    GUISetState(@SW_SHOW, $aGdiGui[$_hWin_])
    _GDIPlus_GraphicsClear($aGdiGui[$_Buffer_], 0xFF888888)
    _GDIPlus_GraphicsClear($aGdiGui[$_hGraphic_], 0xFF888888)
    Return $aGdiGui
EndFunc
Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($aGdiGui[$_hGraphic_], $aGdiGui[$_hBitmap_], 0, 0) ;copy to bitmap
    Return
EndFunc
Func WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam)
    Return 1
EndFunc
Func _GDI_Shutdown(ByRef $aGdiGui)
    _GDIPlus_BitmapDispose($aGdiGui[$_hBitmap_])
    _GDIPlus_GraphicsDispose($aGdiGui[$_Buffer_])
    _GDIPlus_GraphicsDispose($aGdiGui[$_hGraphic_])
    _GDIPlus_Shutdown()
    GUIDelete($aGdiGui[$_hWin_])
    $aGdiGui = 0
    Return
EndFunc
Func _AdlibSetup()
    AdlibUnRegister('_FlipColor')
    If $HALFSIZE Then
        AdlibRegister('_FlipColor', 4 * 1000)
    Else
        AdlibRegister('_FlipColor', 8 * 1000)
    EndIf
    Return
EndFunc
Func _FlipColor()
    $FLIPCOLOR = True
EndFunc
Func AK_Quit()
    If @GUI_CtrlId > 0 Then $TOGGLESIZE = True
    $QUIT = True
EndFunc

MAIN()

(fixed image, I think.)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

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