(ocaml)
#!/usr/bin/env ocaml
#directory "+libMagick/"
#load "magick.cma"

open Magick ;;
open Imper ;;

(* {{{ text *)
let lines = [
  "Le contenu de ce vidéogramme est protégé en vertu du droit d\243auteur";
  "et des autres lois sur la propriété intellectuelle.";
  "";
  "CEPENDANT";
  "";
  "La licence de ce vidéogramme vous permet un visionnage privé, public, à";
  "domicile, commercial, gratuit, payant, dans les toilettes, la forêt, la";
  "cave, l\243espace inter-galactique etc., bref où vous voulez et comme bon";
  "vous semble. Toute distribution, copie, transmission, exécution";
  "publique, altération ou décodage sont AUTORISÉS, LÉGAUX et même";
  "VIVEMENT ENCOURAGÉS.";
  "";
  "Ce vidéogramme est sous licence Creative Commons Attribution 3.0";
  "BY (paternité), vous êtes libres :";
  " * de reproduire, distribuer et communiquer cette création au public";
  " * de modifier cette création";
  "tant que vous citez le nom de l\243auteur original";
  "";
  "Plus d\243infos : http://GULLIVER.eu.org/wiki/bbb";
]
(* }}} *)

let font = "./BlueHighwayBold.ttf"
(*
let width  = 640
and height = 360
let width  = 854
and height = 480
*)
(*
let width  = 1280
and height = 720
*)
let width  = 1920
and height = 1080

let round x = int_of_float (floor(x +. 0.5))

let color_of_string s =
  try color_of_string s
  with _ ->
    prerr_endline s;
    color_of_string "#F00"
;;

let () =
  let bg = get_canvas width height "rgb(2,2,70)" in

  (* scale factor if width and height change *)
  let scale = (float height) /. 480. in

  let t_end = 24 * 9 in  (* 9 seconds *)

  let main_loop t =
    let img = clone_image bg in

    (* black fade in *)
    if t <= 12 then begin
      let p = 1.0 -. ((float t) /. 12.) in
      let color = Printf.sprintf "#000000%02X" (truncate(p *. 255.)) in
      draw_rectangle img
          ~x0:0 ~y0:0 ~x1:width ~y1:height
          ~fill_color:(color_of_string color)
          ();
    end;

    (* draw the text of the annonce *)
    if t < (24 * 7) then (* the main text for 7 seconds *)
    begin
      let j = if t < 18 then truncate((float t) /. 2. *. 17.) else (0x99) in
      let color = Printf.sprintf "#FFFFFF%02X" j in
      let draw_line y line =
        draw_text img
            ~text:line
            ~x:(round(96. *. scale)) ~y:(round y)
            ~point_size:((18.0 *. scale))
            ~fill_color:(color_of_string color)
            ~font
            ();
        (y +. (21.4 *. scale))
      in
      ignore(List.fold_left draw_line 42.0 lines);
    end
    else begin
      let txt1 = "COPIEZ CE FILM !"
      and txt2 = "c\243est parfaitement légal" in

      let j = if t < 18 then truncate((float t) /. 2. *. 17.) else (0x99) in
      let color = Printf.sprintf "#FFFFFF%02X" j in
      let y = 180.
      and x = 210. in
      draw_text img
          ~text:txt1
          ~x:(round(scale *. x))
          ~y:(round(scale *. y))
          ~point_size:((32.0 *. scale))
          ~fill_color:(color_of_string color)
          ~font
          ();
      draw_text img
          ~text:txt2
          ~x:(round(scale *. (x +. 20.)))
          ~y:(round(scale *. (y +. 40.)))
          ~point_size:((28.0 *. scale))
          ~fill_color:(color_of_string color)
          ~font
          ();
    end;

    (* black fade out *)
    if t >= (t_end - 12) then begin
      let u = t_end - t in
      let p = 1.0 -. ((float u) /. 12.) in
      let color = Printf.sprintf "#000000%02X" (truncate(p *. 255.)) in
      draw_rectangle img
          ~x0:0 ~y0:0 ~x1:width ~y1:height
          ~fill_color:(color_of_string color)
          ();
    end;

    (*
    display img;
    *)
    set_compression_quality img 99;
    write_image img (Printf.sprintf "./B_%05d.jpg" t);
    Printf.printf " %d%!" t;
  in
  print_string "generating";
  for t = 0 to t_end do main_loop t done;
  print_newline();
;;
 
bbb_annonce_script.txt · Dernière modification: Le 07/10/2008 à 10:27 par migrate-to-doku     Haut de page
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Design by Chirripó