[Ex] De beaux dessins
Posté : dim. 30 août 2015 15:43
par sozary
Bonjour!
Voici un programme qui fait des beaux cercles de couleurs aléatoires!
Vous les voulez sans remplissage?
Voici un programme qui fait de beaux motifs avec des carrés!
Vous préférez les arbres? Voilà!
Une petite optimisation permet d'avoir un nombre de branches aléatoire compris entre 1 et 8. J'ai réalisé également modifié la hauteur aléatoirement afin d'avoir un résultat plus dissymétrique.
Je voulais vous montrer que votre aide m'a beaucoup aidé tout au long de mon apprentissage du langage AutoIt.
Bon certes je n'ai pas appris que ça
, mais j'ai toujours eu un faible pour les fractales, et ce langage m'a permis de les réaliser.
J'ai encore beaucoup à apprendre en programmation, et je vais devoir mettre AutoIt au placard pendant pas mal de temps je pense, étant donné que je m'axe principalement sur les langages bas niveaux.
Merci pour l'aide que vous avez pus me fournir, et à la prochaine les amis
!
Voici un programme qui fait des beaux cercles de couleurs aléatoires!
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
OnAutoItExitRegister("_Close")
Global $iW = 801, $iH = 601, $colour
Global $Form1 = GUICreate("Circle", $iW, $iH)
_GDIPlus_Startup()
$hGraphics=_GDIPlus_GraphicsCreateFromHWND($Form1)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
_GDIPlus_GraphicsClear($hBackbuffer,0xFFFFFFFF)
deuxcercles(400,300,600)
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
func deuxcercles($x,$y,$r)
$r2=$r/2
if $r>5 Then
$couleur=0xFF00FFFF
_GDIPlus_GraphicsFillEllipse2($hBackbuffer,$x,$y,$r,$couleur/hex(Random(0,255,1)))
deuxcercles(($x-($r2/2)),$y,$r2)
deuxcercles(($x+($r2/2)),$y,$r2)
EndIf
EndFunc
Func _GDIPlus_GraphicsFillEllipse2($hGrap, $x,$y,$r,$color=0xFF000000)
$colour=_GDIPlus_BrushCreateSolid($color)
_GDIPlus_GraphicsFillEllipse($hGrap,$x-($r/2),$y-($r/2),$r,$r,$colour)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
EndFunc
Func WM_ERASEBKGND()
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
Return 1
EndFunc
Func _Close()
GUIRegisterMsg($WM_ERASEBKGND, "")
_GDIPlus_BrushDispose($colour)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
GUIDelete($Form1)
Exit
EndFunc
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
OnAutoItExitRegister("_Close")
Global $pi=3.141592653
Global $deg=2*$pi/360
Global $Weight=601,$Height=$Weight,$colour
Global $Form1 = GUICreate("Circle", $Weight, $Height, 416, 220)
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$hGraphics=_GDIPlus_GraphicsCreateFromHWND($Form1)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($Weight, $Height, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
_GDIPlus_GraphicsClear($hBackbuffer,0xFFFFFFFF)
deuxcercles(300,300,300)
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
func deuxcercles($x,$y,$r)
$r2=$r/2
if $r>5 Then
_DessineRond($hBackbuffer,$x,$y,$r)
deuxcercles($x-$r2,$y,$r2)
deuxcercles($x+$r2,$y,$r2)
EndIf
EndFunc
Func _GDIPlus_GraphicsFillEllipse2($hGraphics, $x,$y,$r,$color=0xFF000000)
Local $colour=_GDIPlus_BrushCreateSolid($color)
_GDIPlus_GraphicsFillEllipse($hGraphics,$x-($r/2),$y-($r/2),$r,$r,$colour)
EndFunc
Func _DessineRond($graph,$x,$y,$r)
for $i=0 to 360 Step .25
_GDIPlus_GraphicsDrawRect($graph,$x+$r*Cos($i*$deg),$y-$r*sin($i*$deg),1,1)
Next
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $Weight, $Height)
EndFunc
Func WM_ERASEBKGND()
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $Weight, $Height)
Return 1
EndFunc
Func _Close()
GUIRegisterMsg($WM_ERASEBKGND, "")
_GDIPlus_BrushDispose($colour)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
GUIDelete($Form1)
Exit
EndFunc
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
OnAutoItExitRegister("_Close")
Global $iW = 601, $iH = 601, $colour
Global $tx=300,$ty=$tx,$tc=$tx
Global $Form1 = GUICreate("Square", $iW, $iH, 416, 220)
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$hGraphics=_GDIPlus_GraphicsCreateFromHWND($Form1)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
_GDIPlus_GraphicsClear($hBackbuffer,0xFFFFFFFF)
square($hGraphics,300,300,300)
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
func square($graph,$x,$y,$c)
$cc=$c/2
if $c>2 Then
$couleur=0xFF00FFFF
if $x=$tx And $y=$ty And $c=$tc Then
_GDIPlus_GraphicsFillRect2($graph,$x,$y,$c,0xFF000000)
Else
_GDIPlus_GraphicsFillRect2($graph,$x,$y,$c,0xFFFFFFFF)
EndIf
square($graph,$x-$c,$y-$c,$cc)
square($graph,$x+$c,$y-$c,$cc)
square($graph,$x+$c,$y+$c,$cc)
square($graph,$x-$c,$y+$c,$cc)
EndIf
EndFunc
Func _GDIPlus_GraphicsFillRect2($hGraphics, $x,$y,$c,$color1=0xFF000000)
Local $colour1=_GDIPlus_BrushCreateSolid($color1)
_GDIPlus_GraphicsFillRect($hGraphics,$x-$c,$y-$c,$c*2,$c*2,$colour1)
_GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBitmap, 0, 0, $iW, $iH)
EndFunc
Func WM_ERASEBKGND()
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
Return 1
EndFunc
Func _Close()
GUIRegisterMsg($WM_ERASEBKGND, "")
_GDIPlus_BrushDispose($colour)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
GUIDelete($Form1)
Exit
EndFunc
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Global $pi=3.141592653
Global $deg=2*$pi/360
Global $Form1 = GUICreate("Circle", 801, 601, 416, 220)
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$hGraphics=_GDIPlus_GraphicsCreateFromHWND($Form1)
_GDIPlus_GraphicsClear($hGraphics,0xFFFFFFFF)
arbre($hGraphics,400,600,600/3,0,0,90,0xFF663300)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
func arbre($graph,$x,$y,$l,$rx,$ry,$angle,$couleur)
if $l>1 Then
$rx=$x+$l*Cos($angle*$deg)
$couleur2=_GDIPlus_PenCreate($couleur)
$ry=$y-$l*Sin($angle*$deg)
_GDIPlus_GraphicsDrawLine($graph,$x,$y,$rx,$ry,$couleur2)
_GDIPlus_GraphicsDrawLine($graph,$x+1,$y,$rx+1,$ry,$couleur2)
arbre($graph,$rx,$ry,$l*.7,0,0,$angle+45,$couleur-3300)
arbre($graph,$rx,$ry,$l*.7,0,0,$angle-45,$couleur-3300)
EndIf
EndFunc
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Global $pi=3.141592653
Global $deg=2*$pi/360
OnAutoItExitRegister("_Close")
Global $iW = 901, $iH = 701, $colour
Global $Form1 = GUICreate("Circle", $iW, $iH, 416, 220)
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$hGraphics=_GDIPlus_GraphicsCreateFromHWND($Form1)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
_GDIPlus_GraphicsClear($hBackbuffer,0xFFFFFFFF)
_GDIPlus_GraphicsClear($hGraphics,0xFFFFFFFF)
arbre($hBackbuffer,900/2,600,185,0,0,90,0xFF663300)
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
func arbre($graph,$x,$y,$l,$rx,$ry,$angle,$couleur)
$l=$l+.1*Random(0,1.10*$l,1)
$rx=$x+$l*Cos($angle*$deg)
$ry=$y-$l*Sin($angle*$deg)
$couleur2=_GDIPlus_PenCreate($couleur)
_GDIPlus_GraphicsDrawLine($graph,$x,$y,$rx,$ry,$couleur2)
_GDIPlus_GraphicsDrawLine($graph,$x+1,$y,$rx+1,$ry,$couleur2)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
if $l>20 Then
$n=Random(1,8,1)
$ev=180/$n
for $i=1 to $n
arbre($hBackbuffer,$rx,$ry,$l*(2/3),$rx,$ry,$angle-90-($ev/2)+$i*$ev,$couleur-3300)
Next
EndIf
EndFunc
Func WM_ERASEBKGND()
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
Return 1
EndFunc
Func _Close()
GUIRegisterMsg($WM_ERASEBKGND, "")
_GDIPlus_BrushDispose($colour)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
GUIDelete($Form1)
Exit
EndFunc
Je voulais vous montrer que votre aide m'a beaucoup aidé tout au long de mon apprentissage du langage AutoIt.
Bon certes je n'ai pas appris que ça

J'ai encore beaucoup à apprendre en programmation, et je vais devoir mettre AutoIt au placard pendant pas mal de temps je pense, étant donné que je m'axe principalement sur les langages bas niveaux.
Merci pour l'aide que vous avez pus me fournir, et à la prochaine les amis
