OCaml : Rotate Ocaml

TitreRotate Ocaml
Postée le30-01-2008
Affichée256
Lienhttp://www.codeswall.info/source-24.html
DescriptionRotation en Ocaml d'une image SDL
EtatInconnu. Inconnu.
Code d'insertion
OptionsRetirer les numéros de lignes.
TéléchargementTelecharger en format txtTelecharger en format pdf
  1. let rotate src dst alpha =
  2.  let (w,h,_) = Sdlvideo.surface_dims pic
  3.   let halfWidth = w / 2 in
  4.    let halfHeight = h / 2 in
  5.     let cosv = int_to_float(cos( -(alpha) / ((180 / 3.14159265)))) in
  6.      let sinv = int_to_float(sin( -(alpha) / ((180 / 3.14159265)))) in
  7.       let x = ref 1 in
  8.            let y = ref 1 in
  9.             while !x < w do
  10.                 (while !y < h do
  11.                  let xOr = ((x-halfWidth) * int_to_float(Maths.cos alpha) + ((y - halfHeight) * sinv + halfWidth)) in
  12.                   let yOr = int_to_float((x-halfWidth) * (Maths.cos alpha) + ((y - halfHeight) * sinv + halfWidth)) in
  13.                if (xOr >= 0 && yOr >= 0 && xOr < dst.Width && yOr < dst.Height)
  14.             Sdlvideo.put_pixel_color dst !x !y (Sqlvideo.get_pixel_color src xOr yOr)
  15.                    y := !y+1
  16.                   done;
  17.                   x := !x+1;)
  18.                 done;
  19.    dst