# Courbe de Hilbert reel depth = 6 reel delai = 100 / depth reel longueur = 100 def Hilbert (pos, long_, orient_, flip_, cm, CM) { # CalculCarre (pos, long_, orient_, flip_) : point bg = pos point bd = plus (pos, rot (<0,0>, , abs(orient_))) point hg = rot (bg, bd, abs (flip_) * 90) point hd = rot (bd, bg, - abs (flip_) * 90) # Fond : #dans 0 faire FondHilbert (hom (cm, CM, 1/2), bg, bd, hg, hd) # 4 Hilberts depuis H1, H2, H3, H4 # 3 Pas depuis P1, P2, P3 reel l = abs (long_) reel lrec = (l - pas) / 2 reel r = lrec / l point H1 = bg point P1 = hom (bg, hg, r) point H2 = hom (hg, bg, r) point P2 = hom (hg, bd, r) point H3 = hom (hd, bg, r) point P3 = hom (hd, bd, r) point H4 = hom (bd, hd, r) # orientation : reel flip = abs(flip_) point Mflip_ = <-flip, 0> reel orient = abs(orient_) point or90_ = point or270_ = # les pas : dans 0.1 faire Pas (P1, or90_, Mflip_, hom (cm, CM, 1/4)) dans 0.2 faire Pas (P2, orient_, flip_, hom (cm, CM, 2/4)) dans 0.3 faire Pas (P3, or270_, Mflip_, hom (cm, CM, 3/4)) # longueur : point lrec_ = # les appels r'ecursifs : dans delai+0.1 faire Hilbert (H1, lrec_, or90_, Mflip_, hom (cm, CM, 0/4), hom (cm, CM, 1/4)) dans delai+0.2 faire Hilbert (H2, lrec_, orient_, flip_, hom (cm, CM, 1/4), hom (cm, CM, 2/4)) dans delai+0.3 faire Hilbert (H3, lrec_, orient_, flip_, hom (cm, CM, 2/4), hom (cm, CM, 3/4)) dans delai+0.4 faire Hilbert (H4, lrec_, or270_, Mflip_, hom (cm, CM, 3/4), hom (cm, CM, 4/4)) } def Pas (pos, orient_, flip_, c) { point long_ = # CalculCarre (pos, , orient_, flip_) : point bg = pos point bd = plus (pos, rot (<0,0>, , abs(orient_))) point hg = rot (bg, bd, abs (flip_) * 90) point hd = rot (bd, bg, - abs (flip_) * 90) point hd = hom (bd, hd, 3/8) point hg = hom (bg, hg, 3/8) Polygone (abs(c), bg, bd, hd, hg) } def FondHilbert (c, bg, bd, hg, hd) { point bg = hom (bd, bg, 3/4) point bd = hom (bg, bd, 3/4) point hg = hom (bd, hg, 3/4) point hd = hom (bg, hd, 3/4) Polygone (abs (c), bg, bd, hd, hg) } # inutilisable car m^eme avec d'elai 0, une fonction # peut venir s'intercaller entre CalculCarre et # la suite qui utiliserait le r'esultat... def CalculCarre (pos, long_, orient_, flip_) { point bg = pos point bd = plus (pos, rot (<0,0>, , abs(orient_))) point hg = rot (bg, bd, abs (flip_) * 90) point hd = rot (bd, bg, - abs (flip_) * 90) } # -------------------------- calcul du pas # pas = longueur / (2 ^ depth - 1) : # puissances de deux : reel deux_to_depth = 1 def deux_puiss () { reel deux_to_depth = deux_to_depth * 2 dans 0.1 faire deux_puiss () } # pour avoir la bonne puissance de 2 : def set_pas () { reel pas = longueur / (deux_to_depth - 1) # 2 ^ depth - 1 # pour voir sur la sortie texte : Polygone (0, ) ; } dans 0.0001 faire deux_puiss () reel depart = 0.05 + (depth - 1) * 0.1 dans depart - 0.01 faire set_pas () # ----------------------- fin calcul du pas dans depart faire Hilbert (<0, 0>, # pos tortue depart , # longueur <0, 0>, # orientation <1, 1>, # au dessus <0,0>, <100,100>) # plage de couleurs