Oui, si l'on le veut en flocon (vers l'extérieur). Ce que je voulais souligner est qu'on doit calculer les coordonnées du sommet en fonction de la taille, plutôt que de mettre une valeur litérale (qui était fausse).
Avec l'expansion vers l'extérieur on ne voit pas que le dessin est bancal.
Code : Tout sélectionner
Global Const $PI = 3.141592653589793, $COS60 = Cos($PI / 3), $SIN60 = Sin($PI / 3)
Global $iTaille = 600, $iMax = 5
Local $iMarge = 50, $iH = $iTaille + 2 * $iMarge, $iV = $iTaille * 2 * Sqrt(3) / 3 + 2 * $iMarge, $sTitle = "Flocon de Koch"
Local $hGUI = GUICreate($sTitle, $iH, $iV)
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Local $aPts = [ _
[$iMarge, $iMarge + $iTaille * Sqrt(3) / 2], _
[$iH - $iMarge, $iMarge + $iTaille * Sqrt(3) / 2], _
[$iMarge + $iTaille / 2, $iMarge] _
]
For $i = 1 To $iMax
_KochFlake($hGraphic, $aPts[0][0], $aPts[0][1], $aPts[1][0], $aPts[1][1], $i)
_KochFlake($hGraphic, $aPts[2][0], $aPts[2][1], $aPts[0][0], $aPts[0][1], $i)
_KochFlake($hGraphic, $aPts[1][0], $aPts[1][1], $aPts[2][0], $aPts[2][1], $i)
WinSetTitle($hGUI, $sTitle, $sTitle & " -Génération " & $i & " -")
Sleep(600)
Next
_GDIPlus_Shutdown()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _KochFlake($hGraph, $ix, $iy, $jx, $jy, $k)
If $k <> 0 Then
Local $a[2], $b[2], $c[2], $d[2], $e[2]
$a[0] = $ix
$a[1] = $iy
$b[0] = $jx
$b[1] = $jy
$c[0] = $a[0] + ($b[0] - $a[0]) / 3
$c[1] = $a[1] + ($b[1] - $a[1]) / 3
$d[0] = $a[0] + 2 * ($b[0] - $a[0]) / 3
$d[1] = $a[1] + 2 * ($b[1] - $a[1]) / 3
$e[0] = ($c[0] + $d[0]) * $COS60 - ($d[1] - $c[1]) * $SIN60
$e[1] = ($c[1] + $d[1]) * $COS60 + ($d[0] - $c[0]) * $SIN60
_GDIPlus_GraphicsDrawLine($hGraph, $c[0], $c[1], $d[0], $d[1])
_GDIPlus_GraphicsDrawLine($hGraph, $a[0], $a[1], $c[0], $c[1])
_GDIPlus_GraphicsDrawLine($hGraph, $c[0], $c[1], $e[0], $e[1])
_GDIPlus_GraphicsDrawLine($hGraph, $e[0], $e[1], $d[0], $d[1])
_GDIPlus_GraphicsDrawLine($hGraph, $d[0], $d[1], $b[0], $b[1])
_KochFlake($hGraph, $a[0], $a[1], $c[0], $c[1], $k - 1)
_KochFlake($hGraph, $c[0], $c[1], $e[0], $e[1], $k - 1)
_KochFlake($hGraph, $e[0], $e[1], $d[0], $d[1], $k - 1)
_KochFlake($hGraph, $d[0], $d[1], $b[0], $b[1], $k - 1)
EndIf
EndFunc ;==>_KochFlake
Note : inutile de passer en paramètre une variable global et de la passer en paramètre si on ne se sert pas de celui-ci ($hGraphics --> $hGraph)