Jump to content

GDI+


Recommended Posts

I've been playing with a GDI+ example made by UEZ and Monoceres. This script has no purpose, I'm just trying to learn from it. I've hit a snag. I don't know if it's with the math or if I'm understanding something wrong. The original script had a triangle, I tried to make it a pentagon. But for some reason it's still a triangle. Any idea what I did or am doing wrong?

#include <GUIConstantsEx.au3>
#include <GDIplus.au3>

Global Const $width = 600
Global Const $height = 400
Global Const $pi = 3.14159265358979323
Global $title = "GDI+"
Global $aPoints[100][2]


; Build your GUI here
Opt("GUIOnEventMode", 1)
$hwnd = GUICreate($title, $width, $height)
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)
$brush = _GDIPlus_BrushCreateSolid(0x1A000000);triangle fader
$hBrush = _GDIPlus_BrushCreateSolid (0x7FAFAFAF)
$font_size = 32
$hFormat = _GDIPlus_StringFormatCreate ()
$hFamily = _GDIPlus_FontFamilyCreate ("Arial")
$hFont = _GDIPlus_FontCreate ($hFamily, $font_size, 2)

$text = "GDI+ Demo" & @LF & @LF & _
            "Triangle coded by monoceres" & @LF & @LF & _
            "Vertical scroller by UEZ" & @LF & @LF & @LF & _
            "Greetings to all forum " & @LF  & _
            "Members at " & @LF & @LF & _
            "www.autoitscript.com"
           
$j = $height / 4

_AntiAlias($backbuffer, 4)
$inc = 0

Global $Polygon_Size = Random(80, 120, 1)
Global $Polygon_X = Random(0, $width - $Polygon_Size, 1)
Global $Polygon_Y = Random(0, $height - $Polygon_Size, 1)

Global $Polygon_Xdir = 1
Global $Polygon_ydir = 1

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

Global $Polygon_Speed = 1.2

_GDIPlus_GraphicsClear($backbuffer)
Do
    $inc += 0.02
;~   _GDIPlus_GraphicsFillRect($backbuffer, 20, 0, $width, $height, $brush)
   
    $Polygon_X += $Polygon_Xdir
    $Polygon_Y += $Polygon_ydir
   
    $Polygon_Size = 200;triangle size
       
    $red = ((Sin(1 * $inc / 1) + 1) / 2) * 256
    $green = ((Sin(2 * $inc / 1) + 1) / 2) * 256
    $blue = ((Sin(3 * $inc / 1) + 1) / 2) * 256
   
    $Pen = _GDIPlus_PenCreate("0x7F" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2), 6);pen format and size
    $x1 = Cos($inc * $Polygon_Speed) * $Polygon_Size + $Polygon_X
    $y1 = Sin($inc * $Polygon_Speed) * $Polygon_Size + $Polygon_Y
   
    $x2 = Cos($inc * $Polygon_Speed + 2 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y2 = Sin($inc * $Polygon_Speed + 2 * $pi / 3) * $Polygon_Size + $Polygon_Y
   
    $x3 = Cos($inc * $Polygon_Speed + 4 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y3 = Sin($inc * $Polygon_Speed + 4 * $pi / 3) * $Polygon_Size + $Polygon_Y
   
    $x4 = Cos($inc * $Polygon_Speed + 6 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y4 = Sin($inc * $Polygon_Speed + 6 * $pi / 3) * $Polygon_Size + $Polygon_Y
   
    $x5 = Cos($inc * $Polygon_Speed + 8 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y5 = Sin($inc * $Polygon_Speed + 8 * $pi / 3) * $Polygon_Size + $Polygon_Y

    $aPoints[0][0] = 5
    $aPoints[1][0] = $x1
    $aPoints[1][1] = $y1
    $aPoints[2][0] = $x2
    $aPoints[2][1] = $y2
    $aPoints[3][0] = $x3
    $aPoints[3][1] = $y3
    $aPoints[4][0] = $x4
    $aPoints[4][1] = $y4
    $aPoints[5][0] = $x5
    $aPoints[5][1] = $y5
       
    For $i = 1 To $aPoints[0][0]
        If $aPoints[$i][1] >= $height Then
            $Polygon_ydir = -1
        ElseIf $aPoints[$i][1] <= 0 Then
;~           ConsoleWrite("meh!" & @CRLF)
            $Polygon_ydir = 1
        EndIf
        If $aPoints[$i][0] >= $width Then
            $Polygon_Xdir = -1
        ElseIf $aPoints[$i][0] <= 0 Then
            $Polygon_Xdir = 1
        EndIf
    Next

    _GDIPlus_GraphicsDrawPolygon($backbuffer, $aPoints, $Pen)
       
    $tLayout = _GDIPlus_RectFCreate (1 / $width, $height + $j, 0, 0)
    _GDIPlus_GraphicsDrawStringEx ($backbuffer, $text, $hFont, $tLayout, $hFormat, $hBrush)
    $j -= 0.75
    If $height + $j < 0 - (StringLen($text) * 5) Then $j = $height / 4
   
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    _GDIPlus_PenDispose($Pen)
    Sleep(1)
Until False

Func close()
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose($brush)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc;==>close

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

Giggity

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