[Ex] Coding Challenge : Cube Wave

Partagez vos scripts, et vos applications AutoIt.
Règles du forum
.
Répondre
Avatar du membre
TommyDDR
Modérateur
Modérateur
Messages : 2086
Enregistré le : mar. 22 juil. 2008 21:55
Localisation : Nantes
Status : Hors ligne

[Ex] Coding Challenge : Cube Wave

#1

Message par TommyDDR »

Suite de cette petite série de TheCodingTrain, le CubeWave (vous pouvez tester le "$MODE_BOULE" et le "$MODE_VAGUE" ligne 38) :
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include "./include/2d.au3"

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

Global $gui

Enum $MODE_BOULE, $MODE_VAGUE

Global $YMAX = 11
Global $XMAX = 11

Global $offset = 30

Global $pi = 3.1415926535897932384626433

Global $losangeWidth = 30
Global $losangeHeight = $losangeWidth / 2

Global $taille[2] = [($XMAX + $YMAX + 1) * $losangeWidth/2 , ($XMAX + $YMAX + 1) * $losangeWidth/2 + 100]

Global $hBackbuffer = _createCanvas($taille[0], $taille[1])
GUISetOnEvent($GUI_EVENT_CLOSE, quit, $2d_Gui)

Global $brushTop = _GDIPlus_BrushCreateSolid(0xFF76AAAC)
Global $brushLeft = _GDIPlus_BrushCreateSolid(0xFF344B7A)
Global $brushRight = _GDIPlus_BrushCreateSolid(0xFFE3DBA4)
Global $whiteBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

Global $pos = 0

OnAutoItExitRegister(_freeRessources)
OnAutoItExitRegister(freeRessources)

While 1
   loop($MODE_BOULE)
WEnd

Func loop($mode)
   _GDIPlus_GraphicsFillRect($hBackbuffer, 0, 0, $taille[0], $taille[1], $whiteBrush)
   For $yy = 0 To $YMAX - 1
      For $xx = 0 To $XMAX - 1
         Local $x = $taille[0] / 2 + ($xx - ($XMAX+2) / 2) * $losangeWidth / 2 - ($yy - ($YMAX) / 2) * $losangeWidth / 2
         Local $y = $taille[1] / 2 + ($xx - ($XMAX) / 2) * $losangeHeight / 2 + ($yy - ($YMAX-1) / 2) * $losangeHeight / 2
         Local $distX
         Local $distY
         If($mode = $MODE_BOULE) Then
            $distX = ($xx - Ceiling(($XMAX - 1) / 2))
            $distY = ($yy - Ceiling(($YMAX - 1) / 2))
         ElseIf($mode = $MODE_VAGUE) Then
            $distX = (($XMAX - $xx) / 2)
            $distY = (($YMAX - $yy) / 2)
         EndIf
         Local $distCenter = Sqrt($distX * $distX + $distY * $distY)
         If ($distCenter == 0) Then $distCenter = 0.9
         Local $calc = $pos / 6 + ($distCenter) / ($XMAX - 1) * $pi * $pi
         Local $sinpos = Sin($calc)
         Local $ecart = $offset + ($sinpos + 1) * 50
         Local $size = 2 * $ecart
         If($mode == $MODE_BOULE) Then
            $size = 2 * $ecart
         ElseIf($mode == $MODE_VAGUE) Then
            $size = $offset + 50
         EndIf
         drawBar($x, $y - $ecart, $losangeWidth, $losangeHeight, $size)
      Next
   Next
   $pos -= 1
   _show()
   Sleep(1)
EndFunc

Func drawBar($x, $y, $width, $height, $size)
   drawLosange($x, $y, $width, $height)

   Local $points[5][2]
   $points[0][0] = 4

   $points[1][0] = $x
   $points[1][1] = $y + $height / 2

   $points[2][0] = $x + $width / 2
   $points[2][1] = $y + $height

   $points[3][0] = $x + $width / 2
   $points[3][1] = $y + $size + $height / 2

   $points[4][0] = $x
   $points[4][1] = $y + $size
   _GDIPlus_GraphicsFillPolygon($hBackbuffer, $points, $brushLeft)
;~    _GDIPlus_GraphicsDrawPolygon($hBackbuffer, $points)

   $points[1][0] = $x + $width
   $points[1][1] = $y + $height / 2

   $points[2][0] = $x + $width / 2
   $points[2][1] = $y + $height

   $points[3][0] = $x + $width / 2
   $points[3][1] = $y + $size + $height / 2

   $points[4][0] = $x + $width
   $points[4][1] = $y + $size
   _GDIPlus_GraphicsFillPolygon($hBackbuffer, $points, $brushRight)
;~    _GDIPlus_GraphicsDrawPolygon($hBackbuffer, $points)

EndFunc

Func drawRectangle($x, $y, $width, $height)
   _GDIPlus_GraphicsFillRect($hBackbuffer, $x, $y, $width, $height, $brushTop)
;~    _GDIPlus_GraphicsDrawRect($hBackbuffer, $x, $y, $width, $height)
EndFunc

Func drawLosange($x, $y, $width, $height)
   Local $points[5][2]
   $points[0][0] = 4

   $points[1][0] = $x
   $points[1][1] = $y + $height / 2

   $points[2][0] = $x + $width / 2
   $points[2][1] = $y

   $points[3][0] = $x + $width
   $points[3][1] = $y + $height / 2

   $points[4][0] = $x + $width / 2
   $points[4][1] = $y + $height

   _GDIPlus_GraphicsFillPolygon($hBackbuffer, $points, $brushTop)
;~    _GDIPlus_GraphicsDrawPolygon($hBackbuffer, $points)
EndFunc

Func quit()
   Exit
EndFunc

Func freeRessources()
   _GDIPlus_BrushDispose($brushTop)
   _GDIPlus_BrushDispose($brushLeft)
   _GDIPlus_BrushDispose($brushRight)
   _GDIPlus_BrushDispose($whiteBrush)
EndFunc
Le fichier 2d.au3 doit être dans un sous dossier "include"
Fichiers joints
2d.au3
(933 Octets) Téléchargé 539 fois
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
Avatar du membre
mikell
Spammer !
Spammer !
Messages : 6292
Enregistré le : dim. 29 mai 2011 17:32
Localisation : Deep Cévennes
Status : Hors ligne

Re: [Ex] Coding Challenge : Cube Wave

#2

Message par mikell »

Très joli Image
Mais si je puis me permettre,
TommyDDR a écrit : lun. 03 août 2020 21:42 Suite de cette petite série de TheCodingTrain
La série en question mériterait amplement un sujet dédié Image
" L'échec est le fondement de la réussite. " (Lao-Tseu )
" Plus ça rate, plus on a de chances que ça marche " (les Shadoks )
Répondre