Jump to content

PolylineTo API


xroot
 Share

Recommended Posts

Looks really nice but it is flickering! You can avoid flickering by using buffering method!

Also use buildin GDI+ functions!

E.g.

$pen = _GDIPlus_PenCreate(0, 2)

_GDIPlus_PenSetColor($pen, 0xFFFFFFFF)

You don't need to create a pen everytime you call NewColor() function - it will cause a memory hog.

I made the same mistake ^_^

Good work!

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 the buffered version ;)

;mixed together by UEZ ;-)
#include <GUIConstants.au3>
#include <GDIplus.au3>

Global Const $width = @DesktopWidth
Global Const $height = @DesktopHeight
Global $title = "GDI+"

; Build your GUI here
Opt("GUIOnEventMode", 1)
$hwnd = GUICreate($title, $width, $height, 0, 0, 0x80000000)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetState()

; Load your GDI+ resources here:
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)
$pen = _GDIPlus_PenCreate(0, 2)
_GDIPlus_PenSetColor($pen, 0xFF000000 + Random(0x400000, 0xFFFFFF, 1))

$R = 0
$X = 0.1
$pi_div_180 = 4 * ATan(1) / 180
$Pt = DllStructCreate("int[2000]")
$pPt = DllStructGetPtr($Pt)
$IO = TimerInit()

Do
    _GDIPlus_GraphicsClear($backbuffer, 0xFF000000)
    
    If TimerDiff($IO) >= 3000 Then
        NewColor()
        $IO = TimerInit()
    EndIf
    PolyLine()
    
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    Sleep(50)
Until False


Func PolyLine()
    Local $A, $R, $N, $I, $J = 100
    $X += 0.01
    $I = 1
    For $N = 1 To $j
        $A = $N * $X
        $R += $A * 0.033
        DllStructSetData($Pt, 1, $width / 2 + Cos($A) * $R, $I)
        DllStructSetData($Pt, 1, $height / 2 - Sin($A) * $R, $I + 1)
        $I += 2
    Next
    For $N = 1 To $J - 3 Step 2 ;this simulates the PolylineTo api
        _GDIPlus_GraphicsDrawLine($backbuffer,    DllStructGetData($Pt, 1, $N), DllStructGetData($Pt, 1, $N + 1), _
                                                DllStructGetData($Pt, 1, $N + 2), DllStructGetData($Pt, 1, $N + 3), $pen)
    Next
EndFunc   ;==>PolyLine

Func NewColor()
    Local $Color = 0xFF000000 + Random(0x400000, 0xFFFFFF, 1)
    _GDIPlus_PenSetColor($pen, $Color)
EndFunc

Func close()
    $Pt = 0
    _GDIPlus_PenDispose($pen)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>close

I used the buffering method from monoceres and mixed it with the code from xroot ^_^

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

Nice. A bit hypnotic though. I started watching this and the next thing I know I'm waking up with just my underwear on, eating an onion that tastes like an apple ...

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