8 Graphic Beispiele

  • Hier mal ein paar Beispiele für Spielereien mit dem Graphic Control ^^. Die Graphic-Befehle habe ich processing-ähnlich vereinfacht.

    Beispiele

    Ball mit Kollision, minx

    [autoit]

    #include <processing.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Width = 500, $Height = 300
    Local $Radius = 20, $Speed = 5
    Local $x = Random(0, $Width-$Radius*2, 1), $y = Random(0, $Height-$Radius*2, 1), $ax = $Speed, $ay = $Speed

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("processing: Ball with collision [minx]", $Width, $Height, -1, -1, -1, $GR_DBUFFER)
    GUISetOnEvent(-3, "quit")
    $hGraphics = size($Width,$Height)
    color()
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    $hBuffer = buffer($hGraphics)
    $hGraphics = size($Width, $Height)
    $x += $ax
    $y += $ay
    If $x > $Width - $Radius*2 Or $x <= 0 Then $ax *= -1
    If $y > $Height - $Radius*2 Or $y <= 0 Then $ay *= -1
    pen($hGraphics, 0xFFFFFF, 0xFFFFFF)
    ellipse($hGraphics, $x, $y, $Radius*2, $Radius*2)
    clearbuffer($hBuffer)
    WEnd

    [/autoit]

    Mehr Bälle mit Kollision, minx

    [autoit]

    #include <processing.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Balls = 20
    Local $Width = 500, $Height = 300
    Local $Radius = 20, $Speed = 3
    Local $ax = $Speed, $ay = $Speed
    Local $aBalls[$Balls][4] ; [nBall][x, y, ax, ay]

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To $Balls - 1
    $aBalls[$i][0] = Random(0, $Width-$Radius*2, 1)
    $aBalls[$i][1] = Random(0, $Height-$Radius*2, 1)
    $aBalls[$i][2] = $ax
    $aBalls[$i][3] = $ay
    Next

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("processing: n Balls with collision [minx]", $Width, $Height, -1, -1, -1, $GR_DBUFFER)
    GUISetOnEvent(-3, "quit")
    $hGraphics = size($Width,$Height)
    color()
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    $hBuffer = buffer($hGraphics)
    $hGraphics = size($Width, $Height)
    pen($hGraphics, 0x000000, 0xFFFFFF)
    For $i = 0 To $Balls -1
    $aBalls[$i][0] += $aBalls[$i][2]
    $aBalls[$i][1] += $aBalls[$i][3]
    If $aBalls[$i][0] > $Width - $Radius*2 Or $aBalls[$i][0] <= 0 Then $aBalls[$i][2] *= -1
    If $aBalls[$i][1] > $Height - $Radius*2 Or $aBalls[$i][1] <= 0 Then $aBalls[$i][3] *= -1
    ellipse($hGraphics, $aBalls[$i][0], $aBalls[$i][1], $Radius*2, $Radius*2)
    Next
    clearbuffer($hBuffer)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Offene und automatisch geschlossene Linien / Polygone, minx

    [autoit]

    #include <processing.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Width = 500, $Height = 300, $Radius = 100

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("processing: Open and closed lines [minx]", $Width, $Height, -1, -1, -1, $GR_DBUFFER)
    GUISetOnEvent(-3, "quit")
    $hGraphics = size($Width,$Height)
    color()
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    $hBuffer = buffer($hGraphics)
    $hGraphics = size($Width, $Height)
    pensize($hGraphics, 2)

    [/autoit] [autoit][/autoit] [autoit]

    pen($hGraphics, 0xFFFFFF, $GR_TRANS) ;You MUST specify $GR_TRANS as filling color, or the drawing WILL be closed
    move($hGraphics, 5, 5)
    linestep($hGraphics, 30, 30)
    linestep($hGraphics, 100, 30)
    linestep($hGraphics, 110, 40)
    linestep($hGraphics, 100, 50)
    linestep($hGraphics, 30, 50)
    linestep($hGraphics, 5, 75)
    linestep($hGraphics, 5, 5)

    [/autoit] [autoit][/autoit] [autoit]

    pen($hGraphics, 0x0000FF, 0xF0F0F0); Because we specified a filling color, the drawing closes itself (endpoint = startpoint)
    move($hGraphics, 5, 105)
    linestep($hGraphics, 30, 130)
    linestep($hGraphics, 100, 130)
    linestep($hGraphics, 110, 140)
    linestep($hGraphics, 100, 150)
    linestep($hGraphics, 30, 150)
    linestep($hGraphics, 5, 175)

    [/autoit] [autoit][/autoit] [autoit]

    clearbuffer($hBuffer)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Bezier Tropfen, minx

    [autoit]

    #include <processing.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Width = 500, $Height = 300
    Local $Left = 50, $Top = 50, $Field = 20

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("processing: Bezier [minx]", $Width, $Height, -1, -1, -1, $GR_DBUFFER)
    GUISetOnEvent(-3, "quit")
    $hGraphics = size($Width,$Height)
    color()
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    $hBuffer = buffer($hGraphics)
    $hGraphics = size($Width, $Height)
    pen($hGraphics, 0x000000, 0xFF00FF)
    bezier($hGraphics, $Width/2, 180, ($Width/2)-150, 0, ($Width/2)+150, 0)
    clearbuffer($hBuffer)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Rechteck Display, minx

    [autoit]

    #include <processing.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Width = 170, $Height = 200, $Radius = 100
    Dim $aBlocks[6][16] = [ [1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0], _
    [0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0], _
    [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0], _
    [0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0], _
    [0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0], _
    [0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0] _
    ]
    ;
    Local $rB = Random(0, 5, 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("processing: Display Tetris blocks [minx]", $Width, $Height, -1, -1, -1, $GR_DBUFFER)
    GUISetOnEvent(-3, "quit")
    GUICtrlCreateButton("Random", 5, 170, 160, 25)
    GUICtrlSetOnEvent(-1, "rand")
    $hGraphics = size($Width,$Height)
    color()
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    $hBuffer = buffer($hGraphics)
    $hGraphics = size($Width, $Height)
    $iC = -1
    For $y = 5 To (5+3*40) Step 40
    For $x = 5 To (5+3*40) Step 40
    $iC += 1
    If $aBlocks[$rB][$iC] = 0 Then
    pen($hGraphics, 0x808080, 0x8080F0)
    rect($hGraphics, $x, $y, 40, 40)
    ElseIf $aBlocks[$rB][$iC] = 1 Then
    pen($hGraphics, 0x808080, 0xFFFFFF)
    rect($hGraphics, $x, $y, 40, 40)
    EndIf
    Next
    Next
    clearbuffer($hBuffer)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func rand()
    $_i = $rB
    do
    $i = Random(0, 5, 1)
    Until $i <> $_i
    Global $rB = $i
    EndFunc

    [/autoit]

    Pacman Animation, minx

    [autoit]

    #include <processing.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Width = 500, $Height = 300, $Radius = 100
    Local $Mouth = 20, $rSweep = 360 - $Mouth*2, $rStart = (180-$Mouth)*-1
    Local $iAdd = 1, $x = $Width + $Radius

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("processing: Pacman animation [minx]", $Width, $Height, -1, -1, -1, $GR_DBUFFER)
    GUISetOnEvent(-3, "quit")
    $hGraphics = size($Width,$Height)
    color()
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    $hBuffer = buffer($hGraphics)
    $hGraphics = size($Width, $Height)
    $x -= 2
    $Mouth += $iAdd
    If $Mouth >= 40 Then $iAdd = -1
    If $Mouth <= 1 Then $iAdd = 1
    If $x + $Radius < 0 Then $x = $Width + $Radius
    $rSweep = 360 - $Mouth*2
    $rStart = (180-$Mouth)*-1
    pensize($hGraphics, 5)
    pen($hGraphics, 0x000000, 0xFFFF00)
    pie($hGraphics, $x, $Height/2, $Radius, $rStart, $rSweep)
    clearbuffer($hBuffer)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Pacman Potentiometer

    [autoit]

    #include <processing.au3>
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Width = 500, $Height = 300, $Radius = 100
    Local $Mouth = 10, $rSweep = 360 - $Mouth*2, $rStart = (180-$Mouth)*-1
    Local $iAdd = 1, $x = $Width + $Radius
    Local $Titel = "processing: Pacman Potentiometer [minx]"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Local $hGUI = GUICreate($Titel, $Width, $Height, -1, -1, -1, $GR_DBUFFER)
    GUISetOnEvent(-3, "quit")
    $hGraphics = size($Width,$Height)
    color()
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Local $aWin = WinGetPos($Titel), $Left = $aWin[0], $Top = $aWin[1]

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    If IsPointInCircle($Width/2, $Height/2, $Radius, (MouseGetPos(0)-$Left), (MouseGetPos(1)-$Top-30)) And _IsPressed("01") Then
    $Mouth = ((($Width/2+$Radius)-(MouseGetPos(0)-$Left))/($Width/2+$Radius)) * 320
    $rSweep = 360 - $Mouth*2
    $rStart = (180-$Mouth)*-1
    EndIf
    ToolTip(Int((($Mouth/360)*2)*100))
    $hBuffer = buffer($hGraphics)
    $hGraphics = size($Width, $Height)
    pensize($hGraphics, 5)
    pen($hGraphics, 0x000000, 0xFFFF00)
    pie($hGraphics, $Width/2, $Height/2, $Radius, $rStart, $rSweep)
    clearbuffer($hBuffer)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func IsPointInCircle(Const $Xm, Const $Ym, Const $R, Const $Xp, Const $Yp)
    Return ($Xp - $Xm) ^ 2 + ($Yp - $Ym) ^ 2 <= $R ^ 2
    EndFunc ;==>IsPointInCircle

    [/autoit]

    Cloth Simulation, UEZ

    [autoit]

    #include <processing.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("{SPACE}", "Gravity")

    [/autoit] [autoit][/autoit] [autoit]

    Local Const $iX = Int(@DesktopWidth * 0.66), $iY = Int($iX * 10 / 16)
    Local Const $W2 = $iX / 2, $H2 = $iY / 2
    $hGUI = GUICreate("processing: Cloth Simulation [UEZ] (Space to take away gravity)", $iX, $iY, -1, -1, -1, $GR_DBUFFER)
    GUISetOnEvent(-3, "quit")
    $hGraphics = size($iX, $iY)
    color()
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Local Const $f = 10
    Local Const $ff = $f ^ 2
    Local $k[$f][$f][5];f,f,px,py,m,k,j
    Local $l[$f ^ 2 + ($f -1) ^ 2][4]
    Local $q = 0
    Local $r = 0.00125
    Local $o = 1
    Local $y = 0.05
    Local $z = 0
    Local Const $u = 0.08
    Local Const $gg = $iX * 1.20
    Local Const $jj = $iY * 0.95
    Local $x, $h, $i

    [/autoit] [autoit][/autoit] [autoit]

    For $h = 0 To $f - 1
    $x = 0.05
    For $i = 0 To $f - 1
    $k[$h][$i][0] = $x ;px
    $k[$h][$i][1] = $y ;py
    $k[$h][$i][2] = 1 ;m
    $k[$h][$i][3] = $x ;k
    $k[$h][$i][4] = $y ;j
    If $h > 0 Then
    $l[$z][0] = $h - 1
    $l[$z][1] = $i
    $l[$z][2] = $h
    $l[$z][3] = $i
    $z += 1
    EndIf
    If $i > 0 Then
    $l[$z][0] = $h
    $l[$z][1] = $i - 1
    $l[$z][2] = $h
    $l[$z][3] = $i
    $z += 1
    EndIf
    $x += $u
    Next
    $y += $u
    Next
    $k[0][0][2] = 0
    $k[0][$f - 1][2] = 0

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    Simulate()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func Simulate()
    $hBuffer = buffer($hGraphics)
    $hGraphics = size($iX, $iY)
    pen($hGraphics, 0xFFFFFF)
    Local $nx, $ny, $a, $s, $t, $dx, $dy, $de, $di
    Local $x1, $y1, $x2, $y2, $spm, $tpm, $spx, $spy, $tpx, $tpy
    Local $pm, $px, $py, $pk, $pj, $_hGraphics
    For $h = 0 To $f - 1
    For $i = 0 To $f -1
    $pm = $k[$h][$i][2]
    If $pm <> 0 Then
    $px = $k[$h][$i][0]
    $py = $k[$h][$i][1]
    $pk = $k[$h][$i][3]
    $pj = $k[$h][$i][4]
    $nx = $px * 2 - $pk
    $ny = $py * 2 - $pj + $r
    $k[$h][$i][3] = $px
    $k[$h][$i][4] = $py
    $k[$h][$i][0] = $nx
    $k[$h][$i][1] = $ny
    EndIf
    Next
    Next
    For $h = 0 To 1
    For $i = 0 To UBound($l) - 1
    $tpm = $k[$l[$i][2]][$l[$i][3]][2]
    $tpx = $k[$l[$i][2]][$l[$i][3]][0]
    $tpy = $k[$l[$i][2]][$l[$i][3]][1]
    $spm = $k[$l[$i][0]][$l[$i][1]][2]
    $spx = $k[$l[$i][0]][$l[$i][1]][0]
    $spy = $k[$l[$i][0]][$l[$i][1]][1]
    $dx = $tpx - $spx
    $dy = $tpy - $spy
    $de = $dx * $dx + $dy * $dy
    $di = ($de - 0.0064) / ((0.0064 + $de) * ($spm + $tpm))
    If $spm <> 0 Then
    $k[$l[$i][0]][$l[$i][1]][0] += $dx * $di
    $k[$l[$i][0]][$l[$i][1]][1] += $dy * $di
    EndIf
    If $tpm <> 0 Then
    $k[$l[$i][2]][$l[$i][3]][0] -= $dx * $di
    $k[$l[$i][2]][$l[$i][3]][1] -= $dy * $di
    EndIf
    Next
    Next
    For $i = 0 To UBound($l) - 1
    $spx = $k[$l[$i][0]][$l[$i][1]][0]
    $spy = $k[$l[$i][0]][$l[$i][1]][1]
    $tpx = $k[$l[$i][2]][$l[$i][3]][0]
    $tpy = $k[$l[$i][2]][$l[$i][3]][1]
    $x1 = $spx * $gg
    $y1 = $spy * $jj
    $x2 = $tpx * $gg
    $y2 = $tpy * $jj
    move($hGraphics, $x1, $y1)
    linestep($hGraphics, $x2, $y2)
    Next
    clearbuffer($hBuffer)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Gravity()
    If $r == 0 Then
    $r = 0.00125
    $o = 0
    Else
    $r = 0
    $o = 1
    EndIf
    EndFunc

    [/autoit]

    Have Fun!

  • Ich habe damit zwar noch nie gearbeitet, aber reicht es nicht eigentlich es nur neu zu Zeichnen wenn sich was ändert.
    Es müsste sich doch automatisch neuzeichnen wenn es überzeichnet wird, da es ja ein GUIControl ist:

    Nur kurz ein Beispiel (Rechteck Display, minx),wie es weniger flackert (nur auf die schnelle):

    Spoiler anzeigen
    [autoit]


    #include <processing.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Width = 170, $Height = 200, $Radius = 100
    Dim $aBlocks[6][16] = [ [1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0], _
    [0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0], _
    [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0], _
    [0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0], _
    [0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0], _
    [0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0] _
    ]
    ;
    Local $rB = Random(0, 5, 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("processing: Display Tetris blocks [minx]", $Width, $Height, -1, -1, -1, $GR_DBUFFER)
    GUISetOnEvent(-3, "quit")
    GUICtrlCreateButton("Random", 5, 170, 160, 25)
    GUICtrlSetOnEvent(-1, "rand")
    $hGraphics = size($Width,$Height)
    color()
    rand()
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While Sleep(1000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func rand()
    $_i = $rB
    do
    $i = Random(0, 5, 1)
    Until $i <> $_i
    Global $rB = $i
    $hBuffer = buffer($hGraphics)
    $hGraphics = size($Width, $Height)
    $iC = -1
    For $y = 5 To (5+3*40) Step 40
    For $x = 5 To (5+3*40) Step 40
    $iC += 1
    If $aBlocks[$rB][$iC] = 0 Then
    pen($hGraphics, 0x808080, 0x8080F0)
    rect($hGraphics, $x, $y, 40, 40)
    ElseIf $aBlocks[$rB][$iC] = 1 Then
    pen($hGraphics, 0x808080, 0xFFFFFF)
    rect($hGraphics, $x, $y, 40, 40)
    EndIf
    Next
    Next
    clearbuffer($hBuffer)
    EndFunc

    [/autoit]

    So sollte es sehr viel weniger Auslastung haben.
    Und du könntest deine Beispiele oben in Spoiler setzen, dass wäre sehr viel übersichtlicher.
    Ansonsten, bin ich dir sehr dankbar, ich war immer zu faul mich damit zu beschäftigen, aber ich glaube das Control kann doch recht nützlich sein, die Beispiele sehen gut aus :thumbup:

  • Es sollte auch so nicht flackern, ich weiß nicht aber bei mir läuft das wie Butter :D.

    Ansonsten Danke ;). Der Spoiler wird bei mir nicht (nie) gesetzt egal in welchem Browser, und wie auch immer, ich finde das etwas nervig. Ich versuch das später vielleicht nochmal :S .

    // Ha! Es geht ^^

    MfG

  • Ich meinte eigentlich für jedes Beispiel jeweils einen Spoiler, dann hätte man alle im überblick und müsste nur den öffnen der einen Interessiert, anstatt erst meilenweit runter zu scrollen. :D

    So nach dem Prinzip:


    - Einleitung

    - Ball mit Kollision, minx (Titel)
    Spoiler (Script)

    - Mehr Bälle mit Kollision, minx (Titel)
    Spoiler (Script)

    ...

  • Bis auf die Cloth Simulation flackern bei mir die Beispiele. Ferner gibt es keine Kantenglättungsmöglichkeit.

    Kannst du nicht die Beispiele als Download anbieten?

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯