Commits

Quentin Dauchy committed 5e6692e

No couleur

  • Participants
  • Parent commits 224ef20

Comments (0)

Files changed (1)

File color_extension.ml

-open Graphics;;
-#load "graphics.cma";;
-open Inside_stuff;;
-open Graphic_stuff;;
-
-type super_symbol = (symbol*color);;
-type super_bracketed = SupS of super_symbol
-		       | SupSeq of super_bracketed list
-		       | SupBranch of super_bracketed list
-;;
-
-let sup_flatten sup = match sup with
-  | SupSeq s -> s
-  | x -> [x]
-;;
-
-let maxed n = 
-  if (n > 250)
-  then 250
-  else if (n < 0)
-  then 0
-  else n
-;;
-
-let sup_concat a1 a2 = match a1 with
-  | SupS (s,c) -> begin
-    match a2 with
-    | SupS (s2,c2) -> SupSeq [SupS (s,c);SupS (s2,c2)]
-    | SupSeq a -> SupSeq ((SupS (s,c))::(sup_flatten(a2)))
-    | SupBranch a -> SupSeq [SupS (s,c); SupBranch a]
-  end
-  | SupSeq a -> begin
-    match a2 with
-    | SupS s -> SupSeq (sup_flatten(a1)@[a2])
-    | SupSeq b -> SupSeq (sup_flatten(a1)@(sup_flatten(a2)))
-    | SupBranch b -> SupSeq (sup_flatten(a1)@[SupBranch b])
-  end
-  | SupBranch a -> begin
-    match a2 with
-    | SupS s -> SupSeq [SupBranch a; SupS s]
-    | SupSeq b -> SupSeq (a1::(sup_flatten(a2)))
-    | SupBranch b -> SupSeq [SupBranch a; SupBranch b]
-  end
-;;
-
-let rec convert brack n = match brack with
-  | S s -> SupS (s,(rgb (maxed (255-(n*10))) (maxed (n*10)) (maxed (n*10))))
-  | Seq [] -> SupSeq []
-  | Seq (s::l) -> SupSeq ((convert s n)::(sup_flatten (convert (Seq l) n)))
-  | Branch [] -> SupBranch []
-  | Branch (s::l) -> SupBranch ((convert s n)::(sup_flatten (convert (Seq l) n)))
-;;
-
-let rec sup_itere x regle = match x with
-  | SupS (s,c) -> begin
-      try (convert (List.assoc s regle) ((c mod 256)/10 + 1))
-      with Not_found -> x
-    end
-  | SupSeq (a::r) -> sup_concat (sup_itere a regle) (sup_itere (SupSeq r) regle)
-  | SupBranch (a::r) -> SupBranch (sup_flatten (sup_concat (sup_itere a regle) (sup_itere (SupSeq r) regle)))
-  | _ -> SupSeq []
-;;
-
-let rec sup_intel_calculate n axiom regle inter t = match axiom with
-  | SupS (s,c) -> begin
-    if (n = 0)
-    then begin
-      print_int c; print_newline (); set_color c; interpret_graphic (List.assoc s inter) t end
-    else sup_intel_calculate (n-1) (sup_itere axiom regle) regle inter t
-  end
-  | SupSeq (s::l) -> sup_intel_calculate n s regle inter t; sup_intel_calculate n (SupSeq l) regle inter t
-  | SupBranch (s::l) -> begin
-    let y = { x = t.x ; y = t.y ; angle = t.angle }
-    in begin
-      sup_intel_calculate n s regle inter y;
-      sup_intel_calculate n (SupSeq l) regle inter y
-    end
-  end
-  | _ -> ()
-;;
-
-let w_koch = convert (Seq [S A;S B;S A;S B;S A;S B;S A]) 0
-and s_koch =
-  [A,
-   Seq ([S A;S C;S A;S A;S B;S A;S A;S B;S A;S B;S A;S C;S A;S C;S A] @
-	   [S A;S B;S A;S B;S A;S C;S A;S C;S A;S A;S C;S A;S A;S B;S A])]
-and i_koch =
-  [(A,[Line(10)]); (B,[Turn(90)]); (C,[Turn(-90)]); (D,[Move(10)])];;
-;;
-open_graph " 1000x1000";;
-let t = { x = 0; y= 950 ; angle = 0} in 
-  moveto t.x t.y;
-  sup_intel_calculate 9 w_koch s_koch i_koch t;;
-sup_itere axiom s_p;;